Subject: Re: objcopy making a mess of converting kernels to a.out format
To: None <Richard.Earnshaw@buzzard.freeserve.co.uk>
From: Chris Gilbert <chris@dokein.co.uk>
List: port-cats
Date: 02/29/2004 20:25:39
On Sun, 29 Feb 2004 19:04:33 +0000
Richard Earnshaw <rearnsha@buzzard.freeserve.co.uk> wrote:

> 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?

I seem to get different output, also concerning about yours is that the
.data isn't starting on the same addresses, the headers I got were:

> /extra/tools/current/cats/bin/arm--netbsdelf-objdump -h netbsd

netbsd:     file format elf32-littlearm

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00426c9f  f0000020  f0000020  00008020  2**5
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 link_set_malloc_types 0000014c  f0426cc0  f0426cc0  0042ecc0  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  2 link_set_sysctl_funcs 000000b8  f0426e0c  f0426e0c  0042ee0c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 link_set_evcnts 00000004  f0426ec4  f0426ec4  0042eec4  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  4 .data         00010554  f0427000  f0427000  0042f000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  5 .bss          00044864  f0437554  f0437554  0043f554  2**2
                  ALLOC
  6 .arm.atpcs    00000000  00000000  00000000  0043f554  2**0
                  CONTENTS, READONLY
  7 .comment      00008a9d  00000000  00000000  0043f554  2**0
                  CONTENTS, READONLY
  8 .ident        0000a29e  00000000  00000000  00447ff1  2**0
                  CONTENTS, READONLY
> /extra/tools/current/cats/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         00426fe0  f0000020  f0000020  00000020  2**2
                  CONTENTS, ALLOC, LOAD, CODE
  1 .data         00011000  f0427000  f0427000  00427000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00043db8  f0438000  f0438000  00000000  2**2
                  ALLOC

Note this is GENERIC cats -current kernel.  Which kernel are you trying
to build?  And how uptodate are your tools?

Chris