Код: Выделить всё
__attribute__ ((constructor)) inline static void constructor(void)
Вроде бы собирается. И компилятор молчит как партизан... хотелось бы услышать мнение знающих.
Модератор: Модераторы разделов
Код: Выделить всё
__attribute__ ((constructor)) inline static void constructor(void)
Код: Выделить всё
$ gcc -std=gnu99 -O0 -g3 -o tmptest main.c component.c
$ $ objdump -h ./tmptest
$ objdump -h ./tmptest
./tmptest: file format elf64-x86-64
Sections:
Idx Name Size VMA LMA File off Algn
0 .interp 0000001c 0000000000400238 0000000000400238 00000238 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .note.ABI-tag 00000020 0000000000400254 0000000000400254 00000254 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .note.gnu.build-id 00000024 0000000000400274 0000000000400274 00000274 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .hash 0000003c 0000000000400298 0000000000400298 00000298 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .gnu.hash 0000001c 00000000004002d8 00000000004002d8 000002d8 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .dynsym 000000f0 00000000004002f8 00000000004002f8 000002f8 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .dynstr 00000069 00000000004003e8 00000000004003e8 000003e8 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .gnu.version 00000014 0000000000400452 0000000000400452 00000452 2**1
CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .gnu.version_r 00000020 0000000000400468 0000000000400468 00000468 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
9 .rela.dyn 00000018 0000000000400488 0000000000400488 00000488 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
10 .rela.plt 000000c0 00000000004004a0 00000000004004a0 000004a0 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
11 .init 00000018 0000000000400560 0000000000400560 00000560 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
12 .plt 00000090 0000000000400578 0000000000400578 00000578 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
13 .text 00000a28 0000000000400610 0000000000400610 00000610 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
14 .fini 0000000e 0000000000401038 0000000000401038 00001038 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
15 .rodata 00000090 0000000000401048 0000000000401048 00001048 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
16 .eh_frame_hdr 0000009c 00000000004010d8 00000000004010d8 000010d8 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
17 .eh_frame 0000025c 0000000000401178 0000000000401178 00001178 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
18 .ctors 00000030 0000000000601df0 0000000000601df0 00001df0 2**3
CONTENTS, ALLOC, LOAD, DATA
19 .dtors 00000018 0000000000601e20 0000000000601e20 00001e20 2**3
CONTENTS, ALLOC, LOAD, DATA
20 .jcr 00000008 0000000000601e38 0000000000601e38 00001e38 2**3
CONTENTS, ALLOC, LOAD, DATA
21 .dynamic 000001a0 0000000000601e40 0000000000601e40 00001e40 2**3
CONTENTS, ALLOC, LOAD, DATA
22 .got 00000008 0000000000601fe0 0000000000601fe0 00001fe0 2**3
CONTENTS, ALLOC, LOAD, DATA
23 .got.plt 00000058 0000000000601fe8 0000000000601fe8 00001fe8 2**3
CONTENTS, ALLOC, LOAD, DATA
24 .data 00000010 0000000000602040 0000000000602040 00002040 2**3
CONTENTS, ALLOC, LOAD, DATA
25 .bss 00000018 0000000000602050 0000000000602050 00002050 2**3
ALLOC
26 .comment 00000023 0000000000000000 0000000000000000 00002050 2**0
CONTENTS, READONLY
27 .debug_aranges 00000060 0000000000000000 0000000000000000 00002073 2**0
CONTENTS, READONLY, DEBUGGING
28 .debug_pubnames 00000103 0000000000000000 0000000000000000 000020d3 2**0
CONTENTS, READONLY, DEBUGGING
29 .debug_info 00000602 0000000000000000 0000000000000000 000021d6 2**0
CONTENTS, READONLY, DEBUGGING
30 .debug_abbrev 000001b9 0000000000000000 0000000000000000 000027d8 2**0
CONTENTS, READONLY, DEBUGGING
31 .debug_line 000004b8 0000000000000000 0000000000000000 00002991 2**0
CONTENTS, READONLY, DEBUGGING
32 .debug_str 0000025a 0000000000000000 0000000000000000 00002e49 2**0
CONTENTS, READONLY, DEBUGGING
33 .debug_loc 000004c0 0000000000000000 0000000000000000 000030a3 2**0
CONTENTS, READONLY, DEBUGGING
34 .debug_macinfo 0000762c 0000000000000000 0000000000000000 00003563 2**0
CONTENTS, READONLY, DEBUGGING
Код: Выделить всё
0000000000400b90 t constructor
0000000000400700 t constructor_test1
0000000000400710 t constructor_test2
0000000000400720 t constructor_test3
Код: Выделить всё
#define constructor_chunk __attribute__ ((constructor, always_inline)) inline static void
Код: Выделить всё
#define constructor_chunk __attribute__ ((constructor)) void
nick87720z писал(а): ↑26.02.2011 20:46С какими опциями лучше? Пока так (авось то).
Код
$ gcc -std=gnu99 -O0 -g3 -o tmptest main.c component.c
$ $ objdump -h ./tmptest
$ objdump -h ./tmptest
$
objdump -d a.out | sed -rn "/<main>/,/^$/p"
08048384 <main>:
8048384: 8d 4c 24 04 lea 0x4(%esp),%ecx
8048388: 83 e4 f0 and $0xfffffff0,%esp
804838b: ff 71 fc pushl -0x4(%ecx)
804838e: 55 push %ebp
804838f: 89 e5 mov %esp,%ebp
8048391: 51 push %ecx
8048392: 83 ec 04 sub $0x4,%esp
8048395: 83 ec 0c sub $0xc,%esp
8048398: 68 80 84 04 08 push $0x8048480
804839d: e8 12 ff ff ff call 80482b4 <puts@plt>
80483a2: 83 c4 10 add $0x10,%esp
80483a5: b8 00 00 00 00 mov $0x0,%eax
80483aa: 8b 4d fc mov -0x4(%ebp),%ecx
80483ad: c9 leave
80483ae: 8d 61 fc lea -0x4(%ecx),%esp
80483b1: c3 ret
80483b2: 90 nop
80483b3: 90 nop
80483b4: 90 nop
80483b5: 90 nop
80483b6: 90 nop
80483b7: 90 nop
80483b8: 90 nop
80483b9: 90 nop
80483ba: 90 nop
80483bb: 90 nop
80483bc: 90 nop
80483bd: 90 nop
80483be: 90 nop
80483bf: 90 nop
Код: Выделить всё
$ objdump -d ./tmptest | sed -rn "/<main>/,/^$/p"
0000000000400700 <main>:
400700: 55 push %rbp
400701: 31 c0 xor %eax,%eax
400703: b9 07 00 00 00 mov $0x7,%ecx
400708: 53 push %rbx
400709: 48 81 ec f8 00 00 00 sub $0xf8,%rsp
400710: 48 89 e7 mov %rsp,%rdi
400713: f3 48 ab rep stos %rax,%es:(%rdi)
400716: bf bc 10 40 00 mov $0x4010bc,%edi
40071b: e8 60 04 00 00 callq 400b80 <component_New>
400720: 48 89 c7 mov %rax,%rdi
400723: e8 28 05 00 00 callq 400c50 <component_Delete>
400728: bf ca 10 40 00 mov $0x4010ca,%edi
40072d: e8 4e 04 00 00 callq 400b80 <component_New>
400732: bf df 10 40 00 mov $0x4010df,%edi
400737: 48 89 04 24 mov %rax,(%rsp)
40073b: e8 40 04 00 00 callq 400b80 <component_New>
400740: bf f4 10 40 00 mov $0x4010f4,%edi
400745: 48 89 44 24 08 mov %rax,0x8(%rsp)
40074a: e8 31 04 00 00 callq 400b80 <component_New>
40074f: bf 09 11 40 00 mov $0x401109,%edi
400754: 48 89 44 24 10 mov %rax,0x10(%rsp)
400759: e8 22 04 00 00 callq 400b80 <component_New>
40075e: bf 1e 11 40 00 mov $0x40111e,%edi
400763: 48 89 44 24 18 mov %rax,0x18(%rsp)
400768: e8 13 04 00 00 callq 400b80 <component_New>
40076d: bf 33 11 40 00 mov $0x401133,%edi
400772: 48 89 44 24 20 mov %rax,0x20(%rsp)
400777: e8 04 04 00 00 callq 400b80 <component_New>
40077c: bf bc 10 40 00 mov $0x4010bc,%edi
400781: 48 89 44 24 28 mov %rax,0x28(%rsp)
400786: 48 c7 44 24 30 00 00 movq $0x0,0x30(%rsp)
40078d: 00 00
40078f: e8 ec 03 00 00 callq 400b80 <component_New>
400794: 48 89 c3 mov %rax,%rbx
400797: 48 8b 04 24 mov (%rsp),%rax
40079b: 48 8d b4 24 e0 00 00 lea 0xe0(%rsp),%rsi
4007a2: 00
4007a3: 48 89 df mov %rbx,%rdi
4007a6: 48 c7 84 24 e8 00 00 movq $0x0,0xe8(%rsp)
4007ad: 00 00 00 00 00
4007b2: 48 89 84 24 e0 00 00 mov %rax,0xe0(%rsp)
4007b9: 00
4007ba: e8 f1 02 00 00 callq 400ab0 <component_AddChildren>
4007bf: 48 8b 44 24 08 mov 0x8(%rsp),%rax
4007c4: 48 8d b4 24 d0 00 00 lea 0xd0(%rsp),%rsi
4007cb: 00
4007cc: 48 89 df mov %rbx,%rdi
4007cf: 48 c7 84 24 d8 00 00 movq $0x0,0xd8(%rsp)
4007d6: 00 00 00 00 00
4007db: 48 89 84 24 d0 00 00 mov %rax,0xd0(%rsp)
4007e2: 00
4007e3: e8 c8 02 00 00 callq 400ab0 <component_AddChildren>
4007e8: 48 8b 44 24 10 mov 0x10(%rsp),%rax
4007ed: 48 8d 74 24 40 lea 0x40(%rsp),%rsi
4007f2: 48 89 df mov %rbx,%rdi
4007f5: 48 c7 44 24 60 00 00 movq $0x0,0x60(%rsp)
4007fc: 00 00
4007fe: 48 89 44 24 40 mov %rax,0x40(%rsp)
400803: 48 8b 44 24 18 mov 0x18(%rsp),%rax
400808: 48 89 44 24 48 mov %rax,0x48(%rsp)
40080d: 48 8b 44 24 20 mov 0x20(%rsp),%rax
400812: 48 89 44 24 50 mov %rax,0x50(%rsp)
400817: 48 8b 44 24 28 mov 0x28(%rsp),%rax
40081c: 48 89 44 24 58 mov %rax,0x58(%rsp)
400821: e8 8a 02 00 00 callq 400ab0 <component_AddChildren>
400826: 48 89 df mov %rbx,%rdi
400829: e8 22 04 00 00 callq 400c50 <component_Delete>
40082e: bf bc 10 40 00 mov $0x4010bc,%edi
400833: e8 48 03 00 00 callq 400b80 <component_New>
400838: 48 89 e6 mov %rsp,%rsi
40083b: 48 89 c7 mov %rax,%rdi
40083e: 48 89 c3 mov %rax,%rbx
400841: e8 6a 02 00 00 callq 400ab0 <component_AddChildren>
400846: 48 8b 44 24 28 mov 0x28(%rsp),%rax
40084b: 48 8d bc 24 c0 00 00 lea 0xc0(%rsp),%rdi
400852: 00
400853: 48 c7 84 24 c8 00 00 movq $0x0,0xc8(%rsp)
40085a: 00 00 00 00 00
40085f: 48 89 84 24 c0 00 00 mov %rax,0xc0(%rsp)
400866: 00
400867: e8 24 01 00 00 callq 400990 <component_RemoveChildren>
40086c: 48 8b 44 24 10 mov 0x10(%rsp),%rax
400871: 48 8d bc 24 b0 00 00 lea 0xb0(%rsp),%rdi
400878: 00
400879: 48 c7 84 24 b8 00 00 movq $0x0,0xb8(%rsp)
400880: 00 00 00 00 00
400885: 48 89 84 24 b0 00 00 mov %rax,0xb0(%rsp)
40088c: 00
40088d: e8 fe 00 00 00 callq 400990 <component_RemoveChildren>
400892: 48 8b 44 24 08 mov 0x8(%rsp),%rax
400897: 48 8d bc 24 90 00 00 lea 0x90(%rsp),%rdi
40089e: 00
40089f: 48 c7 84 24 a0 00 00 movq $0x0,0xa0(%rsp)
4008a6: 00 00 00 00 00
4008ab: 48 89 84 24 90 00 00 mov %rax,0x90(%rsp)
4008b2: 00
4008b3: 48 8b 44 24 18 mov 0x18(%rsp),%rax
4008b8: 48 89 84 24 98 00 00 mov %rax,0x98(%rsp)
4008bf: 00
4008c0: e8 cb 00 00 00 callq 400990 <component_RemoveChildren>
4008c5: 48 8b 04 24 mov (%rsp),%rax
4008c9: 48 8d 7c 24 70 lea 0x70(%rsp),%rdi
4008ce: 48 c7 84 24 80 00 00 movq $0x0,0x80(%rsp)
4008d5: 00 00 00 00 00
4008da: 48 89 44 24 70 mov %rax,0x70(%rsp)
4008df: 48 8b 44 24 20 mov 0x20(%rsp),%rax
4008e4: 48 89 44 24 78 mov %rax,0x78(%rsp)
4008e9: e8 a2 00 00 00 callq 400990 <component_RemoveChildren>
4008ee: 48 89 e6 mov %rsp,%rsi
4008f1: 48 89 df mov %rbx,%rdi
4008f4: e8 b7 01 00 00 callq 400ab0 <component_AddChildren>
4008f9: 48 8b 7c 24 10 mov 0x10(%rsp),%rdi
4008fe: e8 4d 03 00 00 callq 400c50 <component_Delete>
400903: 48 8b 7c 24 08 mov 0x8(%rsp),%rdi
400908: e8 43 03 00 00 callq 400c50 <component_Delete>
40090d: 48 8b 3c 24 mov (%rsp),%rdi
400911: e8 3a 03 00 00 callq 400c50 <component_Delete>
400916: 48 89 df mov %rbx,%rdi
400919: e8 22 06 00 00 callq 400f40 <component_DeleteRecursive>
40091e: 48 81 c4 f8 00 00 00 add $0xf8,%rsp
400925: 31 c0 xor %eax,%eax
400927: 5b pop %rbx
400928: 5d pop %rbp
400929: c3 retq
40092a: 90 nop
40092b: 90 nop
40092c: 90 nop
40092d: 90 nop
40092e: 90 nop
40092f: 90 nop