kzinti wrote:xeyes wrote:How do you link crtbegin.o / crtend.o?
If you link using GCC, it should be automatic (unless you use freestanding / nostdlib).
xeyes wrote:How I do track down linker scripts of complex projects like this? Do they even use static ones or maybe they generate those on the fly?
If you are not using an explicit one, I assume it reverts to a default one and that might be the problem. You are not supposed to have both a __CTOR_LIST__ and a .init_array section. These are two different mechanisms to call constructors. The former is the older method and the later is the new one. .init_array is the better option because the constructors can be executed in the correct order where the __CTOR_LIST__ method will execute constructors in the order you linked them. To me it looks like your GCC is configured to use .init_array and that you are using a linker script + crtbegin.o that are configured to use __CTOR_LIST__, which shouldn't happen with a clean GCC build.
Maybe by not specifying either enable or disable initfini, the configure script was confused and resulted in parts not agreeing with each other?
I searched the gcc folder and the single ld file in there is in a test folder. But it is unlikely that project with its scale doesn't use linker scripts, so maybe they generate linker scripts during the build or maybe the scripts are not named *.ld?
kzinti wrote:Looks like a corrupted file. This is weird. Try dumping it with "objdump -D"?
The file is not corrupted during copying as the md5 cheksums match, but that obviously can't tell whether it is broken or of a wrong format.
objdump -D output of crtbegin.o below, there some scary things like relocation in there but those shouldn't make ld not recognize the format right?
Also attached the output for crtend.o at the end. They look to be the same or similiar format at least to my eyes
Code: Select all
crtbegin.o: file format elf32-i386
Disassembly of section .group:
00000000 <.group>:
0: 01 00 add %eax,(%eax)
2: 00 00 add %al,(%eax)
4: 10 00 adc %al,(%eax)
...
Disassembly of section .group:
00000000 <.group>:
0: 01 00 add %eax,(%eax)
2: 00 00 add %al,(%eax)
4: 11 00 adc %eax,(%eax)
...
Disassembly of section .group:
00000000 <.group>:
0: 01 00 add %eax,(%eax)
2: 00 00 add %al,(%eax)
4: 12 00 adc (%eax),%al
...
Disassembly of section .text:
00000000 <deregister_tm_clones>:
0: e8 fc ff ff ff call 1 <deregister_tm_clones+0x1>
5: 81 c2 02 00 00 00 add $0x2,%edx
b: 8d 8a 00 00 00 00 lea 0x0(%edx),%ecx
11: 8d 82 00 00 00 00 lea 0x0(%edx),%eax
17: 39 c8 cmp %ecx,%eax
19: 74 25 je 40 <deregister_tm_clones+0x40>
1b: 8b 82 00 00 00 00 mov 0x0(%edx),%eax
21: 85 c0 test %eax,%eax
23: 74 1b je 40 <deregister_tm_clones+0x40>
25: 55 push %ebp
26: 89 e5 mov %esp,%ebp
28: 83 ec 14 sub $0x14,%esp
2b: 51 push %ecx
2c: ff d0 call *%eax
2e: 83 c4 10 add $0x10,%esp
31: c9 leave
32: c3 ret
33: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
3a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
40: c3 ret
41: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
48: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
4f: 90 nop
00000050 <register_tm_clones>:
50: e8 fc ff ff ff call 51 <register_tm_clones+0x1>
55: 81 c2 02 00 00 00 add $0x2,%edx
5b: 55 push %ebp
5c: 89 e5 mov %esp,%ebp
5e: 53 push %ebx
5f: 8d 8a 00 00 00 00 lea 0x0(%edx),%ecx
65: 8d 82 00 00 00 00 lea 0x0(%edx),%eax
6b: 83 ec 04 sub $0x4,%esp
6e: 29 c8 sub %ecx,%eax
70: 89 c3 mov %eax,%ebx
72: c1 e8 1f shr $0x1f,%eax
75: c1 fb 02 sar $0x2,%ebx
78: 01 d8 add %ebx,%eax
7a: d1 f8 sar %eax
7c: 74 14 je 92 <register_tm_clones+0x42>
7e: 8b 92 00 00 00 00 mov 0x0(%edx),%edx
84: 85 d2 test %edx,%edx
86: 74 0a je 92 <register_tm_clones+0x42>
88: 83 ec 08 sub $0x8,%esp
8b: 50 push %eax
8c: 51 push %ecx
8d: ff d2 call *%edx
8f: 83 c4 10 add $0x10,%esp
92: 8b 5d fc mov -0x4(%ebp),%ebx
95: c9 leave
96: c3 ret
97: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
9e: 66 90 xchg %ax,%ax
000000a0 <__do_global_dtors_aux>:
a0: 55 push %ebp
a1: 89 e5 mov %esp,%ebp
a3: 57 push %edi
a4: e8 fc ff ff ff call a5 <__do_global_dtors_aux+0x5>
a9: 81 c7 02 00 00 00 add $0x2,%edi
af: 56 push %esi
b0: 53 push %ebx
b1: 83 ec 0c sub $0xc,%esp
b4: 80 bf 00 00 00 00 00 cmpb $0x0,0x0(%edi)
bb: 75 63 jne 120 <__do_global_dtors_aux+0x80>
bd: 8d b7 00 00 00 00 lea 0x0(%edi),%esi
c3: 8d 9f 00 00 00 00 lea 0x0(%edi),%ebx
c9: 8b 87 04 00 00 00 mov 0x4(%edi),%eax
cf: 29 f3 sub %esi,%ebx
d1: c1 fb 02 sar $0x2,%ebx
d4: 83 eb 01 sub $0x1,%ebx
d7: 39 d8 cmp %ebx,%eax
d9: 73 1b jae f6 <__do_global_dtors_aux+0x56>
db: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
df: 90 nop
e0: 83 c0 01 add $0x1,%eax
e3: 89 87 04 00 00 00 mov %eax,0x4(%edi)
e9: ff 14 86 call *(%esi,%eax,4)
ec: 8b 87 04 00 00 00 mov 0x4(%edi),%eax
f2: 39 d8 cmp %ebx,%eax
f4: 72 ea jb e0 <__do_global_dtors_aux+0x40>
f6: e8 05 ff ff ff call 0 <deregister_tm_clones>
fb: 8b 87 00 00 00 00 mov 0x0(%edi),%eax
101: 85 c0 test %eax,%eax
103: 74 14 je 119 <__do_global_dtors_aux+0x79>
105: 83 ec 0c sub $0xc,%esp
108: 8d 87 00 00 00 00 lea 0x0(%edi),%eax
10e: 89 fb mov %edi,%ebx
110: 50 push %eax
111: e8 fc ff ff ff call 112 <__do_global_dtors_aux+0x72>
116: 83 c4 10 add $0x10,%esp
119: c6 87 00 00 00 00 01 movb $0x1,0x0(%edi)
120: 8d 65 f4 lea -0xc(%ebp),%esp
123: 5b pop %ebx
124: 5e pop %esi
125: 5f pop %edi
126: 5d pop %ebp
127: c3 ret
128: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
12f: 90 nop
00000130 <frame_dummy>:
130: 55 push %ebp
131: 89 e5 mov %esp,%ebp
133: 53 push %ebx
134: e8 fc ff ff ff call 135 <frame_dummy+0x5>
139: 81 c3 02 00 00 00 add $0x2,%ebx
13f: 83 ec 04 sub $0x4,%esp
142: 8b 83 00 00 00 00 mov 0x0(%ebx),%eax
148: 85 c0 test %eax,%eax
14a: 74 19 je 165 <frame_dummy+0x35>
14c: 83 ec 08 sub $0x8,%esp
14f: 8d 83 08 00 00 00 lea 0x8(%ebx),%eax
155: 50 push %eax
156: 8d 83 00 00 00 00 lea 0x0(%ebx),%eax
15c: 50 push %eax
15d: e8 fc ff ff ff call 15e <frame_dummy+0x2e>
162: 83 c4 10 add $0x10,%esp
165: 8b 5d fc mov -0x4(%ebp),%ebx
168: c9 leave
169: e9 e2 fe ff ff jmp 50 <register_tm_clones>
Disassembly of section .data:
00000000 <__dso_handle>:
0: 00 00 add %al,(%eax)
...
Disassembly of section .bss:
00000000 <completed.2>:
0: 00 00 add %al,(%eax)
...
00000004 <dtor_idx.1>:
4: 00 00 add %al,(%eax)
...
00000008 <object.0>:
...
Disassembly of section .ctors:
00000000 <__CTOR_LIST__>:
0: ff (bad)
1: ff (bad)
2: ff (bad)
3: ff .byte 0xff
Disassembly of section .dtors:
00000000 <__DTOR_LIST__>:
0: ff (bad)
1: ff (bad)
2: ff (bad)
3: ff .byte 0xff
Disassembly of section .fini:
00000000 <.fini>:
0: e8 9c 00 00 00 call a1 <__do_global_dtors_aux+0x1>
Disassembly of section .init:
00000000 <.init>:
0: e8 2c 01 00 00 call 131 <frame_dummy+0x1>
Disassembly of section .text.__x86.get_pc_thunk.dx:
00000000 <__x86.get_pc_thunk.dx>:
0: 8b 14 24 mov (%esp),%edx
3: c3 ret
Disassembly of section .text.__x86.get_pc_thunk.bx:
00000000 <__x86.get_pc_thunk.bx>:
0: 8b 1c 24 mov (%esp),%ebx
3: c3 ret
Disassembly of section .text.__x86.get_pc_thunk.di:
00000000 <__x86.get_pc_thunk.di>:
0: 8b 3c 24 mov (%esp),%edi
3: c3 ret
Disassembly of section .comment:
00000000 <.comment>:
0: 00 47 43 add %al,0x43(%edi)
3: 43 inc %ebx
4: 3a 20 cmp (%eax),%ah
6: 28 47 4e sub %al,0x4e(%edi)
9: 55 push %ebp
a: 29 20 sub %esp,(%eax)
c: 31 30 xor %esi,(%eax)
e: 2e 32 2e xor %cs:(%esi),%ch
11: 30 00 xor %al,(%eax)
Here is the objdump for crtend.o:
Code: Select all
crtend.o: file format elf32-i386
Disassembly of section .group:
00000000 <.group>:
0: 01 00 add %eax,(%eax)
2: 00 00 add %al,(%eax)
4: 0c 00 or $0x0,%al
...
Disassembly of section .text:
00000000 <__do_global_ctors_aux>:
0: e8 fc ff ff ff call 1 <__do_global_ctors_aux+0x1>
5: 81 c2 02 00 00 00 add $0x2,%edx
b: 8b 82 fc ff ff ff mov -0x4(%edx),%eax
11: 83 f8 ff cmp $0xffffffff,%eax
14: 74 3a je 50 <__do_global_ctors_aux+0x50>
16: 55 push %ebp
17: 89 e5 mov %esp,%ebp
19: 53 push %ebx
1a: 8d 9a fc ff ff ff lea -0x4(%edx),%ebx
20: 83 ec 04 sub $0x4,%esp
23: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
2a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
30: ff d0 call *%eax
32: 8b 43 fc mov -0x4(%ebx),%eax
35: 83 eb 04 sub $0x4,%ebx
38: 83 f8 ff cmp $0xffffffff,%eax
3b: 75 f3 jne 30 <__do_global_ctors_aux+0x30>
3d: 8b 5d fc mov -0x4(%ebp),%ebx
40: c9 leave
41: c3 ret
42: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
49: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
50: c3 ret
Disassembly of section .ctors:
00000000 <__CTOR_END__>:
0: 00 00 add %al,(%eax)
...
Disassembly of section .dtors:
00000000 <__DTOR_END__>:
0: 00 00 add %al,(%eax)
...
Disassembly of section .eh_frame:
00000000 <__FRAME_END__>:
0: 00 00 add %al,(%eax)
...
Disassembly of section .init:
00000000 <.init>:
0: e8 fc ff ff ff call 1 <.init+0x1>
Disassembly of section .text.__x86.get_pc_thunk.dx:
00000000 <__x86.get_pc_thunk.dx>:
0: 8b 14 24 mov (%esp),%edx
3: c3 ret
Disassembly of section .comment:
00000000 <.comment>:
0: 00 47 43 add %al,0x43(%edi)
3: 43 inc %ebx
4: 3a 20 cmp (%eax),%ah
6: 28 47 4e sub %al,0x4e(%edi)
9: 55 push %ebp
a: 29 20 sub %esp,(%eax)
c: 31 30 xor %esi,(%eax)
e: 2e 32 2e xor %cs:(%esi),%ch
11: 30 00 xor %al,(%eax)