Subject: MIPS binary sizes with binutils 2.15
To: None <tech-toolchain@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-toolchain
Date: 11/18/2005 22:59:00
Folks,

With binutils 2.15, small binaries have grown to a minimum size of over
64kB.  Here's an older (binutils 2.14) and -current (binutils 2.15) /bin/sync:

  9 -r-xr-xr-x  1 simonb  wheel   8787 Mar 14  2005 sync-old*
 13 -rwxr-xr-x  1 simonb  wheel  69768 Nov 18 08:58 sync-current

This is because as of binutils 2.15 the ELF_MAXPAGESIZE constant changed
from 4kB to 64kB, and the data section is aligned in the linked program
to that pagesize.  At least the binutils 2.15 binary is a sparse file.
The comments in elf32-mips.c describe why this constant changed size:

  /* The SVR4 MIPS ABI says that this should be 0x10000, but Irix 5 uses
     a value of 0x1000, and we are compatible.  */
  #define ELF_MAXPAGESIZE                 0x1000
  ...
  /* The SVR4 MIPS ABI says that this should be 0x10000, and Linux uses
     page sizes of up to that limit, so we need to respect it.  */
  #define ELF_MAXPAGESIZE                 0x10000

The sections leading up to the data section of a -current program show
where this gap is:

 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
  ...
  11 .rodata       00000050  00400d30  00400d30  00000d30  2**4
                   CONTENTS, ALLOC, LOAD, READONLY, DATA
  12 .copyright    00000064  00400d80  00400d80  00000d80  2**2
                   CONTENTS, ALLOC, LOAD, READONLY, DATA
  13 .data         00000020  10000000  10000000  00010000  2**4
                   CONTENTS, ALLOC, LOAD, DATA

Nick Hudson pointed out the change in
http://sourceware.org/ml/binutils/2005-05/msg00712.html where the data
section is now tacked straight on to the end of the text section with no
gap at all.  The same program linked with a modified linker script now
shows:

 Sections:
 Idx Name          Size      VMA       LMA       File off  Algn
  ...
  11 .rodata       00000050  00400d30  00400d30  00000d30  2**4
                   CONTENTS, ALLOC, LOAD, READONLY, DATA
  12 .copyright    00000064  00400d80  00400d80  00000d80  2**2
                   CONTENTS, ALLOC, LOAD, READONLY, DATA
  13 .data         00000020  00400df0  00400df0  00000df0  2**4
                   CONTENTS, ALLOC, LOAD, DATA


For at least the 3.0 release I'd like to add one of two changes to
NetBSD:

 1) Revert ELF_MAXPAGESIZE back to 0x1000 (4kB)

 2) Remove the text/data gap.

Reasons for 1) are "this is the way it's always been" prior to binutils
2.15, and so has effectively been tested pretty much forever.

Reasons for 2) are that this is the way binutils does it now, and that
it follows the MIPS ELF spec.

I'm personally leaning towards 1) because even though we will be
violating the MIPS ELF spec, the implications of are well known because
we've always violated the spec in this regard, and I don't see it as a
big change leading up to the NetBSD 3.0 release compared with moving the
data section directly to the end of the text section.

Comments?

Simon.
--
Simon Burge                                   <simonb@wasabisystems.com>
NetBSD Development, Support and Service:   http://www.wasabisystems.com/