Subject: objcopy making a mess of converting kernels to a.out format
To: None <port-arm@netbsd.org, port-cats@netbsd.org>
From: Richard Earnshaw <rearnsha@buzzard.freeserve.co.uk>
List: port-arm
Date: 02/29/2004 19:04:33
I'm finding evidence of objcopy making a mess of creating kernels for 
machines that boot a.out.  Here's a dump of the headers:

/work/rearnsha/netbsd/build/cats/tools/bin/arm--netbsdelf-objdump -h netbsd

netbsd:     file format elf32-littlearm

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0023bf43  f0000020  f0000020  00008020  2**5
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 link_set_malloc_types 00000120  f023bf64  f023bf64  00243f64  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 link_set_sysctl_funcs 0000008c  f023c084  f023c084  00244084  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 link_set_evcnts 00000004  f023c110  f023c110  00244110  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .data         000462c0  f023d000  f023d000  00245000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  5 .bss          00030f64  f02832c0  f02832c0  0028b2c0  2**2
                  ALLOC
  6 .arm.atpcs    00000000  00000000  00000000  0028b2c0  2**0
                  CONTENTS, READONLY
  7 .comment      000056d7  00000000  00000000  0028b2c0  2**0
                  CONTENTS, READONLY
  8 .ident        000062cd  00000000  00000000  00290997  2**0
                  CONTENTS, READONLY

/work/rearnsha/netbsd/build/cats/tools/bin/arm--netbsdelf-objdump -h 
netbsd.aout

netbsd.aout:     file format a.out-arm-netbsd

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         0023bfe0  f0000020  f0000020  00000020  2**2
                  CONTENTS, ALLOC, LOAD, CODE
  1 .data         00047000  f023c000  f023c000  0023c000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00030224  f0283000  f0283000  00000000  2**2
                  ALLOC

note that in the file generated by objcopy (netbsd.aout) the bss is marked 
to start at VA 0xf0283000, which is earlier than the end of the .data 
section in the original -- the result of this will be that the end of the 
data section is corrupted when the image loaded (it will be set to zero).

I'm not sure, but I suspect that the culprit is those link_sections, which 
aren't being fully accounted in the size of the data section.  The result 
is that when the size of the .data section is calculated for the a.out 
file it comes out one page too small (in the a.out file the start of the 
.bss should be statically zeroed data in the last page of the .data 
section).

Ideas anyone?

R.