RFC: Remove empty output sections

H. J. Lu hjl@lucon.org
Wed Mar 16 02:32:00 GMT 2005


On Tue, Mar 15, 2005 at 12:38:45PM -0800, H. J. Lu wrote:
> On Tue, Mar 15, 2005 at 11:58:24AM -0800, H. J. Lu wrote:
> > On Tue, Mar 15, 2005 at 08:45:44AM +1030, Alan Modra wrote:
> > > On Mon, Mar 14, 2005 at 08:10:48AM -0800, H. J. Lu wrote:
> > > > On Mon, Mar 14, 2005 at 07:05:15PM +1030, Alan Modra wrote:
> > > > > On Sun, Mar 13, 2005 at 10:31:41PM -0800, H. J. Lu wrote:
> > > > > > @@ -4883,7 +4893,7 @@ lang_process (void)
> > > > > >      lang_check_section_addresses ();
> > > > > >  
> > > > > >    /* Final stuffs.  */
> > > > > > -
> > > > > > +  lang_mark_used_section ();
> > > > > >    ldemul_finish ();
> > > > > >    lang_finish ();
> > > > > >  }
> > > > > 
> > > > > Isn't this too late to strip sections?  What happens if one of the
> > > > > sections stripped has a dynamic section symbol?
> > > > 
> > > > An empty section has a dynamic section symbol. Do you have a testcase
> > > > for that?
> > > 
> > > Easy.  This also demonstrates another potential problem with removing
> > > empty sections;  Their alignment can affect layout of other sections.
> > > 
> > 
> > Here is the output from readelf -Sls after removing empty sections.
> > Removing an empty section will certainly change the layout of other
> > sections. I don't think it should be a problem. I believe that
> > anything depending on alignment of an empty section is broken.
> > 
> > 3 local entries in .dynsym have UND index since they are removed. It
> > is hard to remove them since it is done too late. I don't think it
> > should cause any probleme though.
> > 
> 
> FYI, removing empty sections doesn't change the layout. I will see
> if I can remove those UND entries in .dynsym.
> 

One benefit of removing empty sections late is there will be no
layout changes. The only changes are

1. No empty sections in section table.
2. Some undefine section symbols in .dynsym.
3. No empty segment.

bash-3.00$ cat foo.c
int
_start ()
{
  return 0;
}
bash-3.00$ /usr/bin/ld foo.o
bash-3.00$ readelf -l a.out

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

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg
Align
  LOAD           0x000000 0x08048000 0x08048000 0x0009e 0x0009e R E
0x1000
  LOAD           0x0000a0 0x080490a0 0x080490a0 0x00000 0x00000 RW
0x1000
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4

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

With the new linker,

bash-3.00$ ./ld foo.o
bash-3.00$ readelf -l a.out

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

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg
Align
  LOAD           0x000000 0x08048000 0x08048000 0x0009e 0x0009e R E
0x1000
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4

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


H.J.



More information about the Binutils mailing list