------- Comment #2 from ramiro dot polla at gmail dot com 2009-07-30 03:43 ------- I might be guessing wildly since I don't know that much about PE, but this is what more I've found:
It crashes loading the dll in __pei386_runtime_relocator at address 65ec12a8: 65ec1290 <__pei386_runtime_relocator>: 65ec1290: 55 push %ebp 65ec1291: b9 28 40 ec 65 mov $0x65ec4028,%ecx 65ec1296: 89 e5 mov %esp,%ebp 65ec1298: eb 14 jmp 65ec12ae <__pei386_runtime_relocator+0x1e> 65ec129a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 65ec12a0: 8b 51 04 mov 0x4(%ecx),%edx 65ec12a3: 8b 01 mov (%ecx),%eax 65ec12a5: 83 c1 08 add $0x8,%ecx 65ec12a8: 01 82 00 00 ec 65 add %eax,0x65ec0000(%edx) 65ec12ae: 81 f9 30 40 ec 65 cmp $0x65ec4030,%ecx 65ec12b4: 72 ea jb 65ec12a0 <__pei386_runtime_relocator+0x10> 65ec12b6: 5d pop %ebp 65ec12b7: c3 ret In the same testcase compiled without -O2, I get the sole entry of runtime_pseudo_reloc in __RUNTIME_PSEUDO_RELOC_LIST__ (the equivalent to 0x65ec4028) is: addend = 0x00000004 target = 0x000011d5 and the .text section is: 0 .text 00000344 67701000 67701000 00000400 2**4 CONTENTS, ALLOC, LOAD, CODE, DATA With -O2 it is: addend = 0x00000004 target = 0x00002005 0 .text 00000334 65ec1000 65ec1000 00000600 2**4 CONTENTS, ALLOC, LOAD, CODE, DATA 1 .text.unlikely 0000000c 65ec2000 65ec2000 00000a00 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE Is it possible that it triggers the exception trying to write in text.unlikely which is READONLY? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40905