Page 1 of 1

LD, section start option doesn't work?

Posted: Fri Sep 03, 2010 5:05 am
by 0000
Hi,

I just want to set the .text segment address through ld's option (--section-start .text=org).
Nevertheless, after linking, the .text segment start at an other address.

My code is similar to:

Code: Select all

[...]
.text
.global _start
_start:
    xor eax,eax
    inc eax
    int 0x80
Assembling, linking:

Code: Select all

as -o test.o test.s
ld --section-start .text=0x08048000 --oformat binary -o test test.o
_start isn't located at 0x08048000 but at 0x080480da.
So, what is wrong ?

Re: LD, section start option doesn't work?

Posted: Fri Sep 03, 2010 5:37 am
by gerryg400
Disassemble/inspect the output and look what is in the first 0xda bytes. Is it startup code ? Junk ?

Isn't the syntax

Code: Select all

ld --section-start=.text=0x08048000 --oformat binary -o test test.o
i.e. 2 equal signs ?

Re: LD, section start option doesn't work?

Posted: Fri Sep 03, 2010 6:31 am
by 0000
gerryg400 wrote:Disassemble/inspect the output and look what is in the first 0xda bytes. Is it startup code ? Junk ?
It startup with code:

Code: Select all

$ hexdump -Cn 9 -s 218 load-sym  
000000da  31 c0 40 cd 80 74 65 0d  07                       |1À@Í.te..|
We can find the xor instruction at the first byte.
It's really difficult to disassemble/debug, because I'm writing his own elf header and use some tricks
to reduce his size.

Re: LD, section start option doesn't work?

Posted: Fri Sep 03, 2010 7:10 am
by gerryg400
I mean 'what is at the beginning of the file'?