Page 1 of 1

LD builtin linker script

Posted: Sat May 02, 2009 2:35 am
by dosfan
Hi

I now have gcc and friends running natively on my OS (Thanks pcmattman!!). It does produce valid looking executables but my lazy loading routines have always barfed on non-page aligned sections. As a result I've always had to specify a linker script when compiling anything.

That aside, how do I control the default behavior of LD? I've followed the 'OS Specfic Toolchain' tutorial to add my OS as a target then Canadian cross built native binutils/gcc with it. I'm guessing this must be done at compile time as it uses a 'builtin' linker script... but where is that configured?

Thanks

Re: LD builtin linker script

Posted: Sat May 02, 2009 3:51 am
by pcmattman
Hi,

On the (OS_Specific_Toolchain) article, you will create a "myos_<arch>.sh" file. This contains a heap of information that basically defines the built-in linker scripts (and other similar behavior).

There is a line in this script which the article specifies as:

Code: Select all

TEXT_START_ADDR=0x40000000
This address will be the base of the binary - all other sections will follow this. For most people, all they need to do is specify the base address and they're happy. Your OS may differ - perhaps wanting to have the data starting at a totally different location. In that case, you have other variables - DATA_START_ADDR for instance. A quick Google for TEXT_START_ADDR got me a heap of example GCC emulation scripts, so it shouldn't be too hard to find the information you need :)

Any further questions, feel free to ask!

EDIT: Also, should it also be trying to squeeze in other sections outside of the main ones, you should specify MAXPAGESIZE, COMMONPAGESIZE, and NOP (as the article says). If that still doesn't create binaries with the alignment you need, please post an objdump that lets us see the unaligned sections :)

Re: LD builtin linker script

Posted: Sat May 02, 2009 6:20 am
by Tomaka17
I don't know if it is related but on my Linux I have a path /usr/lib/ldscripts/ which contains many scripts for ld
I have no proof of this but it could be possible that ld uses them by default

Same for a cross-compiler: /usr/local/(cross compiler target)/lib/ldscripts/
They seem to be generated when 'make install'ing binutils