[mono/mono] [4 commits] d6d4d305: [jit] Avoid clearing MONO_INST_FAULT flags when using explicit null checks, LLVM can move the non-faulting loads before the null checks.

"Zoltan Varga ([email protected])" <[email protected]> Mon, 18 Nov 2013 04:25:29 +0000
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <000001426974c453-52459b6f-e4fa-4038-a69b-4603ee46223a-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/270fc62074a1...62dda654985c

   Commit: d6d4d305df5bdf33d8640ff55a351f17de1d3e7c
   Author: Zoltan Varga <[email protected]> (vargaz)
     Date: 2013-11-18 04:19:34 GMT
      URL: https://github.com/mono/mono/commit/d6d4d305df5bdf33d8640ff55a351f17de1d3e7c

[jit] Avoid clearing MONO_INST_FAULT flags when using explicit null checks, LLVM can move the non-faulting loads before the null checks.

Changed paths:
  M mono/mini/ir-emit.h

Modified: mono/mini/ir-emit.h
===================================================================
@@ -862,8 +862,6 @@
 		int __ins_flags = ins_flags; \
 		if (__ins_flags & MONO_INST_FAULT) {								\
 			MONO_EMIT_NULL_CHECK ((cfg), (base));						\
-			if (cfg->explicit_null_checks)								\
-				__ins_flags &= ~MONO_INST_FAULT;							\
 		}																\
 		NEW_LOAD_MEMBASE ((cfg), (dest), (op), (dr), (base), (offset));	\
 		(dest)->flags = (__ins_flags);									\
@@ -874,8 +872,6 @@
 		int __ins_flags = ins_flags; \
 	    if (__ins_flags & MONO_INST_FAULT) {									\
 			MONO_EMIT_NULL_CHECK ((cfg), (base));						\
-			if (cfg->explicit_null_checks)								\
-				__ins_flags &= ~MONO_INST_FAULT;							\
 		}																\
 		NEW_LOAD_MEMBASE ((cfg), (inst), (op), (dr), (base), (offset)); \
 		inst->flags = (__ins_flags); \

   Commit: c11973240b5f969a29571a2fbff3f87c5facc820
   Author: Zoltan Varga <[email protected]> (vargaz)
     Date: 2013-11-18 04:19:39 GMT
      URL: https://github.com/mono/mono/commit/c11973240b5f969a29571a2fbff3f87c5facc820

[jit] Handle the caller saved D8...D15 register during unwinding on ARM.

Changed paths:
  M mono/mini/exceptions-arm.c
  M mono/mini/unwind.c

Modified: mono/mini/exceptions-arm.c
===================================================================
@@ -394,7 +394,7 @@
 
 	if (ji != NULL) {
 		int i;
-		gssize regs [MONO_MAX_IREGS + 1];
+		gssize regs [MONO_MAX_IREGS + 1 + 8];
 		guint8 *cfa;
 		guint32 unwind_info_len;
 		guint8 *unwind_info;
@@ -408,16 +408,25 @@
 
 		for (i = 0; i < 16; ++i)
 			regs [i] = new_ctx->regs [i];
+#ifdef TARGET_IOS
+		/* On IOS, d8..d15 are callee saved. They are mapped to 8..15 in unwind.c */
+		for (i = 0; i < 8; ++i)
+			regs [MONO_MAX_IREGS + i] = new_ctx->fregs [8 + i];
+#endif
 
 		mono_unwind_frame (unwind_info, unwind_info_len, ji->code_start, 
 						   (guint8*)ji->code_start + ji->code_size,
-						   ip, regs, MONO_MAX_IREGS,
+						   ip, regs, MONO_MAX_IREGS + 8,
 						   save_locations, MONO_MAX_IREGS, &cfa);
 
 		for (i = 0; i < 16; ++i)
 			new_ctx->regs [i] = regs [i];
 		new_ctx->pc = regs [ARMREG_LR];
 		new_ctx->regs [ARMREG_SP] = (gsize)cfa;
+#ifdef TARGET_IOS
+		for (i = 0; i < 8; ++i)
+			new_ctx->fregs [8 + i] = regs [MONO_MAX_IREGS + i];
+#endif
 
 		if (*lmf && (MONO_CONTEXT_GET_SP (ctx) >= (gpointer)(*lmf)->sp)) {
 			/* remove any unused lmf */

Modified: mono/mini/unwind.c
===================================================================
@@ -49,8 +49,9 @@
 #define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (AMD64_RIP))
 #elif defined(TARGET_ARM)
 // http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040a/IHI0040A_aadwarf.pdf
-static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
-#define NUM_REGS 16
+/* Assign d8..d15 to hregs 16..24 */
+static int map_hw_reg_to_dwarf_reg [] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 264, 265, 266, 267, 268, 269, 270, 271 };
+#define NUM_REGS 272
 #define DWARF_DATA_ALIGN (-4)
 #define DWARF_PC_REG (mono_hw_reg_to_dwarf_reg (ARMREG_LR))
 #elif defined (TARGET_X86)
@@ -330,14 +331,14 @@
 #endif
 
 static G_GNUC_UNUSED void
-print_dwarf_state (int cfa_reg, int cfa_offset, int ip, int nregs, Loc *locations)
+print_dwarf_state (int cfa_reg, int cfa_offset, int ip, int nregs, Loc *locations, guint8 *reg_saved)
 {
 	int i;
 
 	printf ("\t%x: cfa=r%d+%d ", ip, cfa_reg, cfa_offset);
 
 	for (i = 0; i < nregs; ++i)
-		if (locations [i].loc_type == LOC_OFFSET)
+		if (reg_saved [i] && locations [i].loc_type == LOC_OFFSET)
 			printf ("r%d@%d(cfa) ", i, locations [i].offset);
 	printf ("\n");
 }
@@ -358,12 +359,12 @@
 				   guint8 **out_cfa)
 {
 	Loc locations [NUM_REGS];
-	int i, pos, reg, cfa_reg, cfa_offset;
+	guint8 reg_saved [NUM_REGS];
+	int i, pos, reg, cfa_reg, cfa_offset, offset;
 	guint8 *p;
 	guint8 *cfa_val;
 
-	for (i = 0; i < NUM_REGS; ++i)
-		locations [i].loc_type = LOC_SAME;
+	memset (reg_saved, 0, sizeof (reg_saved));
 
 	p = unwind_info;
 	pos = 0;
@@ -381,6 +382,7 @@
 		case DW_CFA_offset:
 			reg = *p & 0x3f;
 			p ++;
+			reg_saved [reg] = TRUE;
 			locations [reg].loc_type = LOC_OFFSET;
 			locations [reg].offset = decode_uleb128 (p, &p) * DWARF_DATA_ALIGN;
 			break;
@@ -400,8 +402,19 @@
 				break;
 			case DW_CFA_offset_extended_sf:
 				reg = decode_uleb128 (p, &p);
+				offset = decode_sleb128 (p, &p);
+				g_assert (reg < NUM_REGS);
+				reg_saved [reg] = TRUE;
+				locations [reg].loc_type = LOC_OFFSET;
+				locations [reg].offset = offset * DWARF_DATA_ALIGN;
+				break;
+			case DW_CFA_offset_extended:
+				reg = decode_uleb128 (p, &p);
+				offset = decode_uleb128 (p, &p);
+				g_assert (reg < NUM_REGS);
+				reg_saved [reg] = TRUE;
 				locations [reg].loc_type = LOC_OFFSET;
-				locations [reg].offset = decode_sleb128 (p, &p) * DWARF_DATA_ALIGN;
+				locations [reg].offset = offset * DWARF_DATA_ALIGN;
 				break;
 			case DW_CFA_advance_loc4:
 				pos += read32 (p);
@@ -422,7 +435,7 @@
 
 	cfa_val = (guint8*)regs [mono_dwarf_reg_to_hw_reg (cfa_reg)] + cfa_offset;
 	for (i = 0; i < NUM_REGS; ++i) {
-		if (locations [i].loc_type == LOC_OFFSET) {
+		if (reg_saved [i] && locations [i].loc_type == LOC_OFFSET) {
 			int hreg = mono_dwarf_reg_to_hw_reg (i);
 			g_assert (hreg < nregs);
 			regs [hreg] = *(mgreg_t*)(cfa_val + locations [i].offset);

   Commit: a2be8ab68228892e4cb25e6279b0d1608e701a39
   Author: Zoltan Varga <[email protected]> (vargaz)
     Date: 2013-11-18 04:19:46 GMT
      URL: https://github.com/mono/mono/commit/a2be8ab68228892e4cb25e6279b0d1608e701a39

Don't register the LLVM SSE intrinsics on arm.

Changed paths:
  M mono/mini/mini-llvm.c

Modified: mono/mini/mini-llvm.c
===================================================================
@@ -4886,6 +4886,7 @@
 	}
 
 	/* SSE intrinsics */
+#if defined(TARGET_X86) || defined(TARGET_AMD64)
 	{
 		LLVMTypeRef ret_type, arg_types [16];
 
@@ -5030,6 +5031,7 @@
 	}
 
 	AddFunc (module, "llvm.x86.sse2.pause", LLVMVoidType (), NULL, 0);
+#endif
 
 	/* Load/Store intrinsics */
 	{

   Commit: 62dda654985c6b4286660878479bf989fcef0467
   Author: Zoltan Varga <[email protected]> (vargaz)
     Date: 2013-11-18 04:20:55 GMT
      URL: https://github.com/mono/mono/commit/62dda654985c6b4286660878479bf989fcef0467

Upgrade the LLVM backend to LLVM e656caccc7dfb5c51c208906f0e176f0973f030f.

Changed paths:
  M mono/mini/aot-compiler.c
  M mono/mini/exceptions-amd64.c
  M mono/mini/exceptions-arm.c
  M mono/mini/mini-llvm-cpp.cpp
  M mono/mini/mini-llvm.c
  M mono/mini/mini-unwind.h
  M mono/mini/unwind.c

Modified: mono/mini/aot-compiler.c
===================================================================
@@ -6932,7 +6932,7 @@ struct _ReadOnlyValue {
 	 */
 	opts = g_strdup ("-instcombine -simplifycfg");
 	//opts = g_strdup ("-simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -domtree -domfrontier -scalarrepl -simplify-libcalls -instcombine -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loop-simplify -domfrontier -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -iv-users -indvars -loop-deletion -loop-simplify -lcssa -loop-unroll -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -domtree -memdep -dse -adce -simplifycfg -preverify -domtree -verify");
-	opts = g_strdup ("-targetlibinfo -no-aa -basicaa -notti -instcombine -simplifycfg -sroa -domtree -early-cse -simplify-libcalls -lazy-value-info -correlated-propagation -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -indvars -loop-idiom -loop-deletion -loop-unroll -memdep -gvn -memdep -memcpyopt -sccp -instcombine -lazy-value-info -correlated-propagation -domtree -memdep -dse -adce -simplifycfg -instcombine -strip-dead-prototypes -preverify -domtree -verify");
+	opts = g_strdup ("-targetlibinfo -no-aa -basicaa -notti -instcombine -simplifycfg -sroa -domtree -early-cse -lazy-value-info -correlated-propagation -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -indvars -loop-idiom -loop-deletion -loop-unroll -memdep -gvn -memdep -memcpyopt -sccp -instcombine -lazy-value-info -correlated-propagation -domtree -memdep -dse -adce -simplifycfg -instcombine -strip-dead-prototypes -preverify -domtree -verify");
 #if 1
 	command = g_strdup_printf ("%sopt -f %s -o \"%s.opt.bc\" \"%s.bc\"", acfg->aot_opts.llvm_path, opts, acfg->tmpbasename, acfg->tmpbasename);
 	printf ("Executing opt: %s\n", command);

Modified: mono/mini/exceptions-amd64.c
===================================================================
@@ -617,6 +617,11 @@ void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler)
 
 		frame->unwind_info = unwind_info;
 		frame->unwind_info_len = unwind_info_len;
+
+		/*
+		printf ("%s %p %p\n", ji->d.method->name, ji->code_start, ip);
+		mono_print_unwind_info (unwind_info, unwind_info_len);
+		*/
  
 		regs [AMD64_RAX] = new_ctx->rax;
 		regs [AMD64_RBX] = new_ctx->rbx;

Modified: mono/mini/exceptions-arm.c
===================================================================
@@ -406,6 +406,11 @@
 		else
 			unwind_info = mono_get_cached_unwind_info (ji->used_regs, &unwind_info_len);
 
+		/*
+		printf ("%s %p %p\n", ji->d.method->name, ji->code_start, ip);
+		mono_print_unwind_info (unwind_info, unwind_info_len);
+		*/
+
 		for (i = 0; i < 16; ++i)
 			regs [i] = new_ctx->regs [i];
 #ifdef TARGET_IOS

Modified: mono/mini/mini-llvm-cpp.cpp
===================================================================
@@ -123,14 +123,15 @@ class MonoJITMemoryManager : public JITMemoryManager
 	virtual void deallocateExceptionTable(void*) {
 	}
 
-	virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
-										 unsigned SectionID) {
+	virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID,
+										 StringRef SectionName) {
 		// FIXME:
 		assert(0);
 		return NULL;
 	}
 
-	virtual uint8_t* allocateDataSection(uintptr_t, unsigned int, unsigned int, bool) {
+	virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID,
+										 StringRef SectionName, bool IsReadOnly) {
 		// FIXME:
 		assert(0);
 		return NULL;
@@ -142,6 +143,12 @@ class MonoJITMemoryManager : public JITMemoryManager
 		return false;
 	}
 
+	virtual bool finalizeMemory(std::string *ErrMsg = 0) {
+		// FIXME:
+		assert(0);
+		return false;
+	}
+
 	virtual void* getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure) {
 		void *res;
 		char *err;
@@ -408,7 +415,7 @@ class MonoJITEventListener : public JITEventListener {
       (void) llvm::createBasicAliasAnalysisPass();
       (void) llvm::createLibCallAliasAnalysisPass(0);
       (void) llvm::createScalarEvolutionAliasAnalysisPass();
-      (void) llvm::createBlockPlacementPass();
+      //(void) llvm::createBlockPlacementPass();
       (void) llvm::createBreakCriticalEdgesPass();
       (void) llvm::createCFGSimplificationPass();
 	  /*
@@ -478,7 +485,7 @@ class MonoJITEventListener : public JITEventListener {
       (void) llvm::createReassociatePass();
       (void) llvm::createSCCPPass();
       (void) llvm::createScalarReplAggregatesPass();
-      (void) llvm::createSimplifyLibCallsPass();
+      //(void) llvm::createSimplifyLibCallsPass();
 	  /*
       (void) llvm::createSingleLoopExtractorPass();
       (void) llvm::createStripSymbolsPass();
@@ -538,9 +545,6 @@ class MonoJITEventListener : public JITEventListener {
   mono_mm->alloc_cb = alloc_cb;
   mono_mm->dlsym_cb = dlsym_cb;
 
-  // PrettyStackTrace installs signal handlers which trip up libgc
-  DisablePrettyStackTrace = true;
-
   /*
    * The Default code model doesn't seem to work on amd64,
    * test_0_fields_with_big_offsets (among others) crashes, because LLVM tries to call
@@ -590,7 +594,7 @@ class MonoJITEventListener : public JITEventListener {
 	  }
   } else {
 	  /* Use the same passes used by 'opt' by default, without the ipo passes */
-	  const char *opts = "-simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -domtree -domfrontier -scalarrepl -simplify-libcalls -instcombine -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loop-simplify -domfrontier -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -iv-users -indvars -loop-deletion -loop-simplify -lcssa -loop-unroll -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -domtree -memdep -dse -adce -gvn -simplifycfg -preverify -domtree -verify";
+	  const char *opts = "-simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -domtree -domfrontier -scalarrepl -instcombine -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loop-simplify -domfrontier -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -iv-users -indvars -loop-deletion -loop-simplify -lcssa -loop-unroll -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -domtree -memdep -dse -adce -gvn -simplifycfg -preverify -domtree -verify";
 	  char **args;
 	  int i;
 

Modified: mono/mini/mini-llvm.c
===================================================================
@@ -4709,6 +4709,8 @@
 	 * with it.
 	 */
 	cfg->encoded_unwind_ops = mono_unwind_decode_fde ((guint8*)data, &cfg->encoded_unwind_ops_len, NULL, &ei, &ei_len, &type_info, &this_reg, &this_offset);
+	if (cfg->verbose_level > 1)
+		mono_print_unwind_info (cfg->encoded_unwind_ops, cfg->encoded_unwind_ops_len);
 
 	/* Count nested clauses */
 	nested_len = 0;

Modified: mono/mini/mini-unwind.h
===================================================================
@@ -158,4 +158,6 @@ enum {
 
 GSList* mono_unwind_get_cie_program (void) MONO_INTERNAL;
 
+void mono_print_unwind_info (guint8 *unwind_info, int unwind_info_len) MONO_INTERNAL;
+
 #endif

Modified: mono/mini/unwind.c
===================================================================
@@ -31,6 +31,8 @@
 	guint8 info [MONO_ZERO_LEN_ARRAY];
 } MonoUnwindInfo;
 
+#define ALIGN_TO(val,align) ((((guint64)val) + ((align) - 1)) & ~((align) - 1))
+
 static CRITICAL_SECTION unwind_mutex;
 
 static MonoUnwindInfo **cached_info;
@@ -249,6 +251,68 @@
 	return res;
 }
 
+void
+mono_print_unwind_info (guint8 *unwind_info, int unwind_info_len)
+{
+	guint8 *p;
+	int pos, reg, offset, cfa_reg, cfa_offset;
+
+	p = unwind_info;
+	pos = 0;
+	while (p < unwind_info + unwind_info_len) {
+		int op = *p & 0xc0;
+
+		switch (op) {
+		case DW_CFA_advance_loc:
+			pos += *p & 0x3f;
+			p ++;
+			break;
+		case DW_CFA_offset:
+			reg = *p & 0x3f;
+			p ++;
+			offset = decode_uleb128 (p, &p) * DWARF_DATA_ALIGN;
+			if (reg == DWARF_PC_REG)
+				printf ("CFA: [%x] offset: %s at cfa-0x%x\n", pos, "pc", -offset);
+			else
+				printf ("CFA: [%x] offset: %s at cfa-0x%x\n", pos, mono_arch_regname (mono_dwarf_reg_to_hw_reg (reg)), -offset);
+			break;
+		case 0: {
+			int ext_op = *p;
+			p ++;
+			switch (ext_op) {
+			case DW_CFA_def_cfa:
+				cfa_reg = decode_uleb128 (p, &p);
+				cfa_offset = decode_uleb128 (p, &p);
+				printf ("CFA: [%x] def_cfa: %s+0x%x\n", pos, mono_arch_regname (mono_dwarf_reg_to_hw_reg (cfa_reg)), cfa_offset);
+				break;
+			case DW_CFA_def_cfa_offset:
+				cfa_offset = decode_uleb128 (p, &p);
+				printf ("CFA: [%x] def_cfa_offset: 0x%x\n", pos, cfa_offset);
+				break;
+			case DW_CFA_def_cfa_register:
+				cfa_reg = decode_uleb128 (p, &p);
+				printf ("CFA: [%x] def_cfa_reg: %s\n", pos, mono_arch_regname (mono_dwarf_reg_to_hw_reg (cfa_reg)));
+				break;
+			case DW_CFA_offset_extended_sf:
+				reg = decode_uleb128 (p, &p);
+				offset = decode_sleb128 (p, &p) * DWARF_DATA_ALIGN;
+				printf ("CFA: [%x] offset_extended_sf: %s at cfa-0x%x\n", pos, mono_arch_regname (mono_dwarf_reg_to_hw_reg (reg)), -offset);
+				break;
+			case DW_CFA_advance_loc4:
+				pos += read32 (p);
+				p += 4;
+				break;
+			default:
+				g_assert_not_reached ();
+			}
+			break;
+		}
+		default:
+			g_assert_not_reached ();
+		}
+	}
+}
+
 /*
  * mono_unwind_ops_encode:
  *
@@ -660,33 +724,27 @@
 /*
  * decode_lsda:
  *
- *   Decode the Language Specific Data Area generated by LLVM.
+ *   Decode the Mono specific Language Specific Data Area generated by LLVM.
  */
 static void
 decode_lsda (guint8 *lsda, guint8 *code, MonoJitExceptionInfo **ex_info, guint32 *ex_info_len, gpointer **type_info, int *this_reg, int *this_offset)
 {
-	gint32 ttype_offset, call_site_length;
-	gint32 ttype_encoding, call_site_encoding;
-	guint8 *ttype, *action_table, *call_site, *p;
-	int i, ncall_sites;
+	guint8 *p;
+	int i, ncall_sites, this_encoding;
+	guint32 mono_magic, version;
 
-	/*
-	 * LLVM generates a c++ style LSDA, which can be decoded by looking at
-	 * eh_personality.cc in gcc.
-	 */
 	p = lsda;
 
-	if (*p == DW_EH_PE_udata4) {
-		/* This is the modified LSDA generated by the LLVM mono branch */
-		guint32 mono_magic, version;
+	/* This is the modified LSDA generated by the LLVM mono branch */
+	mono_magic = decode_uleb128 (p, &p);
+	g_assert (mono_magic == 0x4d4fef4f);
+	version = decode_uleb128 (p, &p);
+	g_assert (version == 1);
+	this_encoding = *p;
+	p ++;
+	if (this_encoding == DW_EH_PE_udata4) {
 		gint32 op, reg, offset;
 
-		p ++;
-		mono_magic = decode_uleb128 (p, &p);
-		g_assert (mono_magic == 0x4d4fef4f);
-		version = decode_uleb128 (p, &p);
-		g_assert (version == 1);
-
 		/* 'this' location */
 		op = *p;
 		g_assert (op == DW_OP_bregx);
@@ -697,61 +755,24 @@
 		*this_reg = mono_dwarf_reg_to_hw_reg (reg);
 		*this_offset = offset;
 	} else {
-		/* Read @LPStart */
-		g_assert (*p == DW_EH_PE_omit);
-		p ++;
+		g_assert (this_encoding == DW_EH_PE_omit);
 
 		*this_reg = -1;
 		*this_offset = -1;
 	}
-
-	/* Read @TType */
-	ttype_encoding = *p;
-	p ++;
-	ttype_offset = decode_uleb128 (p, &p);
-	ttype = p + ttype_offset;
-
-	/* Read call-site table */
-	call_site_encoding = *p;
-	g_assert (call_site_encoding == DW_EH_PE_udata4);
-	p ++;
-	call_site_length = decode_uleb128 (p, &p);
-	call_site = p;
-	p += call_site_length;
-	action_table = p;
-
-	/* Calculate the size of our table */
-	ncall_sites = 0;
-	p = call_site;
-	while (p < action_table) {
-		int block_start_offset, block_size, landing_pad, action_offset;
-
-		block_start_offset = read32 (p);
-		p += sizeof (gint32);
-		block_size = read32 (p);
-		p += sizeof (gint32);
-		landing_pad = read32 (p);
-		p += sizeof (gint32);
-		action_offset = decode_uleb128 (p, &p);
-
-		/* landing_pad == 0 means the region has no landing pad */
-		if (landing_pad)
-			ncall_sites ++;
-	}
+	ncall_sites = decode_uleb128 (p, &p);
+	p = (guint8*)ALIGN_TO ((guint64)p, 4);
 
 	if (ex_info) {
 		*ex_info = g_malloc0 (ncall_sites * sizeof (MonoJitExceptionInfo));
 		*ex_info_len = ncall_sites;
 	}
-
 	if (type_info)
 		*type_info = g_malloc0 (ncall_sites * sizeof (gpointer));
 
-	p = call_site;
-	i = 0;
-	while (p < action_table) {
-		int block_start_offset, block_size, landing_pad, action_offset, type_offset;
-		guint8 *action, *tinfo;
+	for (i = 0; i < ncall_sites; ++i) {
+		int block_start_offset, block_size, landing_pad;
+		guint8 *tinfo;
 
 		block_start_offset = read32 (p);
 		p += sizeof (gint32);
@@ -759,49 +780,19 @@
 		p += sizeof (gint32);
 		landing_pad = read32 (p);
 		p += sizeof (gint32);
-		action_offset = decode_uleb128 (p, &p);
-
-		if (!action_offset)
-			continue;
-
-		action = action_table + action_offset - 1;
-
-		type_offset = decode_sleb128 (action, &action);
-
-		if (landing_pad) {
-			//printf ("BLOCK: %p-%p %p, %d\n", code + block_start_offset, code + block_start_offset + block_size, code + landing_pad, action_offset);
-
-			g_assert (ttype_offset);
-
-			if (ttype_encoding == DW_EH_PE_absptr) {
-				guint8 *ttype_entry = (ttype - (type_offset * sizeof (gpointer)));
-				tinfo = *(gpointer*)ttype_entry;
-			} else if (ttype_encoding == (DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4)) {
-				guint8 *ttype_entry = (ttype - (type_offset * 4));
-				gint32 offset = *(gint32*)ttype_entry;
-				guint8 *stub = ttype_entry + offset;
-				tinfo = *(gpointer*)stub;
-			} else if (ttype_encoding == (DW_EH_PE_pcrel | DW_EH_PE_sdata4)) {
-				guint8 *ttype_entry = (ttype - (type_offset * 4));
-				gint32 offset = *(gint32*)ttype_entry;
-				tinfo = ttype_entry + offset;
-			} else if (ttype_encoding == DW_EH_PE_udata4) {
-				/* Embedded directly */
-				guint8 *ttype_entry = (ttype - (type_offset * 4));
-				tinfo = ttype_entry;
-			} else {
-				g_assert_not_reached ();
-			}
+		tinfo = p;
+		p += sizeof (gint32);
 
-			if (ex_info) {
-				if (*type_info)
-					(*type_info) [i] = tinfo;
-				(*ex_info)[i].try_start = code + block_start_offset;
-				(*ex_info)[i].try_end = code + block_start_offset + block_size;
-				(*ex_info)[i].handler_start = code + landing_pad;
+		g_assert (landing_pad);
+		g_assert (((guint64)tinfo % 4) == 0);
+		//printf ("X: %p %d\n", landing_pad, *(int*)tinfo);
 
-			}
-			i ++;
+		if (ex_info) {
+			if (*type_info)
+				(*type_info) [i] = tinfo;
+			(*ex_info)[i].try_start = code + block_start_offset;
+			(*ex_info)[i].try_end = code + block_start_offset + block_size;
+			(*ex_info)[i].handler_start = code + landing_pad;
 		}
 	}
 }


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches