#include <stdio.h>
int localmemory0 __attribute__((section("LOCALmem"))) = 0;
int localmemory1 __attribute__((section("LOCALmem"))) = 0;
int globalmemory __attribute__((section("GLOBALmem"))) = 0;
int main (int argc, char *argv[])
{
localmemory0 = 0x456;
localmemory1 = 0x123;
globalmemory = localmemory0 + localmemory1;
}
beyes@linux-beyes:~/C/GNU_C_EXT> gcc -c -o elf_section.o elf_section.c
beyes@linux-beyes:~/C/GNU_C_EXT> gcc -c -o elf_section2.o -fdata-sections elf_section.c
beyes@linux-beyes:~/C/GNU_C_EXT> objdump -S elf_section.o
elf_section.o: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 51 push %ecx
e: 83 ec 04 sub $0x4,%esp
11: c7 05 00 00 00 00 56 movl $0x456,0x0
18: 04 00 00
1b: c7 05 00 00 00 00 23 movl $0x123,0x0
22: 01 00 00
25: a1 00 00 00 00 mov 0x0,%eax
2a: 8b 15 00 00 00 00 mov 0x0,%edx
30: 01 d0 add %edx,%eax
32: a3 00 00 00 00 mov %eax,0x0
37: 83 c4 04 add $0x4,%esp
3a: 59 pop %ecx
3b: 5d pop %ebp
3c: 8d 61 fc lea -0x4(%ecx),%esp
3f: c3 ret
SECTIONS
{
.text : {
*(.text)
}
LOCALmem 0x1f0000 : {
*(LOCALmem)
}
GLOBALmem 0xff0000 : {
*(GLOBALmem)
}
}
beyes@linux-beyes:~/C/GNU_C_EXT> objdump -S elf_section.elf
elf_section.elf: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 51 push %ecx
e: c7 05 00 00 1f 00 56 movl $0x456,0x1f0000
15: 04 00 00
18: c7 05 04 00 1f 00 23 movl $0x123,0x1f0004
1f: 01 00 00
22: 8b 15 00 00 1f 00 mov 0x1f0000,%edx
28: a1 04 00 1f 00 mov 0x1f0004,%eax
2d: 8d 04 02 lea (%edx,%eax,1),%eax
30: a3 00 00 ff 00 mov %eax,0xff0000
35: b8 00 00 00 00 mov $0x0,%eax
3a: 59 pop %ecx
3b: 5d pop %ebp
3c: 8d 61 fc lea -0x4(%ecx),%esp
3f: c3 ret
beyes@linux-beyes:~/C/GNU_C_EXT> objdump -s elf_section.elf
elf_section.elf: file format elf32-i386
Contents of section .text:
0000 8d4c2404 83e4f0ff 71fc5589 e551c705 .L$.....q.U..Q..
0010 00001f00 56040000 c7050400 1f002301 ....V.........#.
0020 00008b15 00001f00 a104001f 008d0402 ................
0030 a30000ff 00b80000 0000595d 8d61fcc3 ..........Y].a..
Contents of section LOCALmem:
1f0000 00000000 00000000 ........
Contents of section GLOBALmem:
ff0000 00000000 ....
Contents of section .comment:
0000 00474343 3a202853 55534520 4c696e75 .GCC: (SUSE Linu
0010 78292034 2e332e32 205b6763 632d345f x) 4.3.2 [gcc-4_
0020 332d6272 616e6368 20726576 6973696f 3-branch revisio
0030 6e203134 31323931 5d00 n 141291].
Contents of section .comment.SUSE.OPTs:
0000 6f737077 6700 ospwg.
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |