Bug 10028 - unnamed section in program headers
Summary: unnamed section in program headers
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.20
: P2 normal
Target Milestone: ---
Assignee: Ian Lance Taylor
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-03 03:46 UTC by matt rice
Modified: 2009-06-23 06:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description matt rice 2009-04-03 03:46:59 UTC
#!/bin/sh
cat <<EOF >foo.c
int _start() {
 return 0; 
}
EOF

cat <<EOF >ldscript 
ENTRY(_start)

SECTIONS
{
  . = 0xC0000000 + 0x100000;
  _text = .;
}
EOF

gcc -Wl,-r -nostdlib foo.c -o foo.o

gcc -Wl,-Tldscript -nostdlib -o foo foo.o -g

readelf -l foo



this produces the output here of

Elf file type is EXEC (Executable file)
Entry point 0xc0100000
There are 3 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0xc00ff000 0xc00ff000 0x00094 0x00094 R   0x1000
  LOAD           0x001000 0xc0100000 0xc0100000 0x0000a 0x0000a R E 0x1000
  LOAD           0x00100c 0xc010000c 0xc010000c 0x00000 0x00000 RW  0x1000

 Section to Segment mapping:
  Segment Sections...
   00     
   01     .text 
   02   

when linking with gnu-ld these unnamed sections don't exist in the program headers,

when booting with grub, these sections appear to cause this error
[Multiboot-elf, <0xff000:0xb4:0x0>

Error 28: Selected item cannot fit into memory
this error is booting the actual coyotos kernel, where the unnamed section looks
like:
  LOAD           0x000000 0x00000000 0x000ff000 0x000b4 0x000b4 R   0x1000

the unnamed section doesn't appear when linking with gnu ld.
i am not really familiar with this stuff, so i'm not sure if the linker script
is relying on the behaviour of gnu ld, which is different in gold, or if this is
actually a bug.

let me know if you want the actual linker script as opposed to the reduction above.
Comment 1 Ian Lance Taylor 2009-06-23 06:12:17 UTC
The last empty segment is a result of the empty .data section.  The GNU linker
discards empty sections; gold does not.  I think gold's behaviour is reasonable,
and that does not seem to be your problem in any case.

The first segment holds the program headers.  gold does this to make it more
likely that programs built with a linker script can be executed on GNU/Linux.  I
think that there are some cases that the GNU linker will generated files which
can not be executed when using a linker script.

Of course you don't care about executing your program on GNU/Linux.  You should
probably use the -n option when you link to turn off dynamic paging.  That will
work with both the GNU linker and gold.  However, you may need to use the
current development version of gold to get the results you need.

Let me know if that seems like an acceptable solution for this problem.