Subject: ELF ld bug or do I misunderstand the concept?
To: None <tech-toolchain@netbsd.org>
From: Ignatios Souvatzis <is@jocelyn.rhein.de>
List: tech-toolchain
Date: 09/07/1998 21:33:24
--CE+1k2dSO48ffgeK
Content-Type: text/plain; charset=us-ascii
Hello,
as far as I understand, ELF files have (up to) two independent sets of
tables describing the data:
a) the section table, with entries for .text, .data, .bss, and some
strange ones.
b) the Program header, intended for actual program loading, only describing
memory regions needed for an executable file loader.
While playing around with my cross-toolchain, trying to verify what I
understood, I found this (see the test.dump attachment):
idx name size vma lma file off alignment
5 .sbss 00000000 f000082c f000082c 000008a0 2**0
CONTENTS
6 .bss 00000100 f0000830 f0000830 000008a0 2**4
ALLOC
As I understand, the .bss should be 16 byte aligned, and is thus moved to
virtual offset f0000830 -- f000092f (instead of f000082c -- f00009cb).
The _end symbol tells the same story:
f0000930 g O *ABS* 00000000 _end
However, in the program header, we have:
LOAD off 0x00000074 vaddr 0xf0000000 paddr 0xf0000000 align 2**4
filesz 0x0000082c memsz 0x0000092c flags rwx
which tells me that the program header generating code didn't notice that .bss
was moved to satisfy its alignment restrictions.
a) do I read this wrongly?
b) if no: was this noticed (and fixed) in newer ld code?
Regards,
Ignatios Souvatzis
P.S: Program versions:
jocelyn test !% powerpc-netbsd-as -V
GNU assembler version 2.8.1 (powerpc-netbsd), using BFD version 2.8.1
jocelyn test !% powerpc-netbsd-ld -V
GNU ld version 2.8.1 (with BFD 2.8.1)
Supported emulations:
elf32ppc
jocelyn test !% powerpc-netbsd-objdump -V
GNU objdump 2.8.1
jocelyn test !% powerpc-netbsd-gcc -v
Reading specs from /usr/local/lib/gcc-lib/powerpc-netbsd/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)
Set up as a cross compiler from NetBSD/m68k.
--CE+1k2dSO48ffgeK
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="test.dump"
test: file format elf32-powerpc
test
architecture: powerpc:common, flags 0x00000012:
EXEC_P, HAS_SYMS
start address 0xf0000000
Program Header:
LOAD off 0x00000074 vaddr 0xf0000000 paddr 0xf0000000 align 2**4
filesz 0x0000082c memsz 0x0000092c flags rwx
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000018 f0000000 f0000000 00000074 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .sdata2 00000000 f0000018 f0000018 0000008c 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .data 00000800 f0000018 f0000018 0000008c 2**2
CONTENTS, ALLOC, LOAD, DATA
3 .got 00000010 f0000818 f0000818 0000088c 2**2
CONTENTS, ALLOC, LOAD, DATA
4 .sdata 00000004 f0000828 f0000828 0000089c 2**2
CONTENTS, ALLOC, LOAD, DATA
5 .sbss 00000000 f000082c f000082c 000008a0 2**0
CONTENTS
6 .bss 00000100 f0000830 f0000830 000008a0 2**4
ALLOC
7 .comment 00000035 f0000930 f0000930 000008a0 2**0
CONTENTS, READONLY
SYMBOL TABLE:
f0000000 l d .text 00000000
f0000018 l d .sdata2 00000000
f0000018 l d .data 00000000
f0000818 l d .got 00000000
f0000828 l d .sdata 00000000
f000082c l d .sbss 00000000
f0000830 l d .bss 00000000
f0000930 l d .comment 00000000
00000000 l d *ABS* 00000000
00000000 l d *ABS* 00000000
00000000 l d *ABS* 00000000
00000000 l df *ABS* 00000000 test.c
f0000000 l O .text 00000000 gcc2_compiled.
f0000018 g O *ABS* 00000000 _etext
f0000828 g O .sdata 00000004 blubb
f0000000 g F .text 00000018 test1
f000882c g O .sdata 00000000 _SDA_BASE_
f0000018 g O .data 00000800 bla
f0000830 g O .bss 00000100 foo
f000082c g O *ABS* 00000000 _edata
f0000930 g O *ABS* 00000000 _end
f0008018 g O .sdata2 00000000 _SDA2_BASE_
--CE+1k2dSO48ffgeK--