Question on using a linker script
Iru Cai
vimacs@disroot.org
Tue Oct 26 09:43:29 GMT 2021
Hi,
I'm new to use a linker script to define the sections for ELF output,
but I'm having problems and cannot find any related document.
I create a simple object file from assembly like this:
.section .text.start
.global _start
_start:
nop
And build it using ``as -c test.S -o test.o`` to get an x86_64 ELF object.
Then I write a linker script, which has some area for a special RAM and
a special address space for code:
SECTIONS
{
.text 0x00000000 :
{
*(.text.start)
ASSERT((. <= 0x00040000), "No room for initial code.");
}
.data :
{
*(.data)
ASSERT((. <= 0x003c0000), "No room for .data");
}
.ram 0x003c0000 :
{
*(.ram)
ASSERT((. <= 0x00400000), "No room for RAM.");
}
.text 0x08000000 : { *(.text) }
}
Since my object file test.o only has .text.start section, I think I'll
only get a code segment, and only a .text section. However, ld reports
an assertion fail:
$ ld.bfd -T test.ld test.o -o test
ld.bfd: No room for RAM.
I also tried ld.gold and ld.lld, they can link the object but have
different result.
So what's wrong with my linker script, or is this a bug for ld?
Thanks
Iru
More information about the Binutils
mailing list