ld ignores the specified entry point and address location?
Posted: Fri Sep 04, 2015 4:25 am
I must be missing something, because I'm going crazy with ld at the moment.
Per the ld documentation, one can specify the entry point of the produced binary with the -e option as well as the location of various sections with --section-start.
Well... it appears it doesn't work as described in the doc, or I'm clearly missing something.
The app.s assembly file below defines a bss segment for data, followed by the text segment where I have 3 functions. The entry point (entrypoint) is defined at the end on purpose:
Here is the makefile that produces the app.elf binary:
I pass the following 3 options to ld:
-e entrypoint : to tell ld the "entrypoint" label is the actual entry point of the program
--section-start=.text=0 to tell ld the code section should be located at address 0x0
--section-start=.bss=1000 to tell ld the bss section (data) should be located at address 0x1000
However, that's not what I'm seeing when dumping the elf content with "objdump -D app.elf":
I tried specifying different section names to ld, such .bss/.text and bss/text, but it still doesn't locate the data and code at the right addresses.
Can someone tell me what's going on or what I don't understand here?
Thanks!
Per the ld documentation, one can specify the entry point of the produced binary with the -e option as well as the location of various sections with --section-start.
Well... it appears it doesn't work as described in the doc, or I'm clearly missing something.
The app.s assembly file below defines a bss segment for data, followed by the text segment where I have 3 functions. The entry point (entrypoint) is defined at the end on purpose:
Code: Select all
global func1
global func2
global entrypoint
section .bss:
msg db "Greetings from the void", 0
section .text:
func1:
mov eax,0x1
ret
func2:
mov eax,0x2
ret
entrypoint:
mov eax,0xDEADBEEF
ret
Code: Select all
app.elf: app.o
ld -e entrypoint --section-start=.text=0 --section-start=.bss=1000 -melf_i386 app.o -o app.elf
app.o: app.s
nasm -f elf32 app.s -o app.o
clean:
rm -f *.o *.elf
-e entrypoint : to tell ld the "entrypoint" label is the actual entry point of the program
--section-start=.text=0 to tell ld the code section should be located at address 0x0
--section-start=.bss=1000 to tell ld the bss section (data) should be located at address 0x1000
However, that's not what I'm seeing when dumping the elf content with "objdump -D app.elf":
Code: Select all
app.elf: file format elf32-i386
Disassembly of section .bss::
00000000 <msg>:
0: 47 inc %edi
1: 72 65 jb 68 <entrypoint+0x44>
3: 65 gs
4: 74 69 je 6f <entrypoint+0x4b>
6: 6e outsb %ds:(%esi),(%dx)
7: 67 73 20 addr16 jae 2a <entrypoint+0x6>
a: 66 data16
b: 72 6f jb 7c <entrypoint+0x58>
d: 6d insl (%dx),%es:(%edi)
e: 20 74 68 65 and %dh,0x65(%eax,%ebp,2)
12: 20 76 6f and %dh,0x6f(%esi)
15: 69 .byte 0x69
16: 64 fs
...
Disassembly of section .text::
00000018 <func1>:
18: b8 01 00 00 00 mov $0x1,%eax
1d: c3 ret
0000001e <func2>:
1e: b8 02 00 00 00 mov $0x2,%eax
23: c3 ret
00000024 <entrypoint>:
24: b8 ef be ad de mov $0xdeadbeef,%eax
29: c3 ret
Can someone tell me what's going on or what I don't understand here?
Thanks!