Bug 3314 - ELF linker aligns empty section
Summary: ELF linker aligns empty section
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
: 3402 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-10-06 13:31 UTC by H.J. Lu
Modified: 2012-05-24 16:06 UTC (History)
3 users (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 H.J. Lu 2006-10-06 13:31:01 UTC
When we are outputing an empty loadable section, we consider it not loadable.
But we still align it at page boundary:

[hjl@gnu-13 empty-10]$ !cat
cat foo.c
extern char *__init_array_start;

int xxx = 10;

_start ()
{
  return __init_array_start != 0;
}
[hjl@gnu-13 empty-10]$ make LD=ld
gcc    -c -o foo.o foo.c
ld -o foo foo.o
readelf -Sl foo
There are 9 section headers, starting at offset 0x2001b0:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .text             PROGBITS         00000000004000e8  000000e8
       0000000000000016  0000000000000000  AX       0     0     4
  [ 2] .eh_frame         PROGBITS         0000000000400100  00000100
       0000000000000038  0000000000000000   A       0     0     8
  [ 3] .init_array       INIT_ARRAY       0000000000600138  00200138
       0000000000000000  0000000000000000  WA       0     0     1
  [ 4] .data             PROGBITS         0000000000600138  00000138
       0000000000000004  0000000000000000  WA       0     0     4
  [ 5] .comment          PROGBITS         0000000000000000  00200138
       000000000000002d  0000000000000000           0     0     1
  [ 6] .shstrtab         STRTAB           0000000000000000  00200165
       0000000000000046  0000000000000000           0     0     1
  [ 7] .symtab           SYMTAB           0000000000000000  002003f0
       0000000000000138  0000000000000018           8     8     8
  [ 8] .strtab           STRTAB           0000000000000000  00200528
       000000000000003d  0000000000000000           0     0     1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

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

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
                 0x0000000000000138 0x0000000000000138  R E    200000
  LOAD           0x0000000000000138 0x0000000000600138 0x0000000000600138
                 0x0000000000000004 0x0000000000000004  RW     200000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     8

 Section to Segment mapping:
  Segment Sections...
   00     .text .eh_frame
   01     .data
   02
[hjl@gnu-13 empty-10]$
Comment 1 H.J. Lu 2006-10-06 13:41:17 UTC
The patch is at

http://sourceware.org/ml/binutils/2006-10/msg00043.html
Comment 2 H.J. Lu 2006-10-06 16:20:30 UTC
The updated patch is at

http://sourceware.org/ml/binutils/2006-10/msg00045.html
Comment 3 H.J. Lu 2006-10-17 13:06:58 UTC
Fixed.
Comment 4 H.J. Lu 2006-10-20 13:56:33 UTC
*** Bug 3402 has been marked as a duplicate of this bug. ***