Bug 10515 - Linker corrupts the paddr and vaddr in program header
Summary: Linker corrupts the paddr and vaddr in program header
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-13 05:21 UTC by harry he
Modified: 2009-10-29 06:11 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: powerpc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments
sample code and scripts produce different elfs (2.47 KB, application/x-tar)
2009-08-13 05:22 UTC, harry he
Details

Note You need to log in before you can comment on or make changes to this bug.
Description harry he 2009-08-13 05:21:02 UTC
I am attaching a sample program compiled using two different linker scripts
producing two different ELF files.

The two linker scripts are test_good.lds test_faulty.lds.
There is a trivial difference between two files.
In test_good.lds, 'ro_data' PHDRS entry is in first place.
In test_faulty.lds, 'ro_data' PHDRS entry is in second place.


The two elf files produced are test_good.elf, test_faulty.elf.

'objdump -p' of both the files is shown below.

[sample]$ objdump -p test_good.elf 

test_good.elf:     file format elf32-big

Program Header:
    LOAD off    0x00000000 vaddr 0x0c000000 paddr 0x00100000 align 2**16
         filesz 0x00100000 memsz 0x00100000 flags r-x
    LOAD off    0x00100000 vaddr 0x00200000 paddr 0x00200000 align 2**16
         filesz 0x00100000 memsz 0x00100000 flags rw- 400000
    LOAD off    0x00200000 vaddr 0x08000000 paddr 0x08000000 align 2**16
         filesz 0x00000000 memsz 0x04000000 flags rw- 400000
    LOAD off    0x00200000 vaddr 0x00300000 paddr 0x00300000 align 2**16
         filesz 0x00010000 memsz 0x00070000 flags rw-
     0x8 off    0x00000000 vaddr 0x01000000 paddr 0x01000000 align 2**0
         filesz 0x00000000 memsz 0x07000000 flags rw-
     0x8 off    0x00000000 vaddr 0x2c000000 paddr 0x2c000000 align 2**0
         filesz 0x00000000 memsz 0x04000000 flags rw- 400000
     0x8 off    0x00000000 vaddr 0x10000000 paddr 0x10000000 align 2**0
         filesz 0x00000000 memsz 0x04000000 flags rw- a00000
     0x8 off    0x00000000 vaddr 0x28000000 paddr 0x28000000 align 2**0
         filesz 0x00000000 memsz 0x04000000 flags rw- 400000

[sample]$ objdump -p test_faulty.elf 

test_faulty.elf:     file format elf32-big

Program Header:
    LOAD off    0x00010000 vaddr 0x00200000 paddr 0x00200000 align 2**16
         filesz 0x00100000 memsz 0x00100000 flags rw- 400000
    LOAD off    0x00000000 vaddr 0x0bf00000 paddr 0x00000000 align 2**16
         filesz 0x00200000 memsz 0x00200000 flags r-x
    LOAD off    0x00200000 vaddr 0x08000000 paddr 0x08000000 align 2**16
         filesz 0x00000000 memsz 0x04000000 flags rw- 400000
    LOAD off    0x00200000 vaddr 0x00300000 paddr 0x00300000 align 2**16
         filesz 0x00010000 memsz 0x00070000 flags rw-
     0x8 off    0x00000000 vaddr 0x01000000 paddr 0x01000000 align 2**0
         filesz 0x00000000 memsz 0x07000000 flags rw-
     0x8 off    0x00000000 vaddr 0x2c000000 paddr 0x2c000000 align 2**0
         filesz 0x00000000 memsz 0x04000000 flags rw- 400000
     0x8 off    0x00000000 vaddr 0x10000000 paddr 0x10000000 align 2**0
         filesz 0x00000000 memsz 0x04000000 flags rw- a00000
     0x8 off    0x00000000 vaddr 0x28000000 paddr 0x28000000 align 2**0
         filesz 0x00000000 memsz 0x04000000 flags rw- 400000



Check that in 'objdump -p test_faulty.elf ' output, the second segement entry
contains paddr as 0 and vaddr as 0x0bf00000. Where is it should have been 
vaddr = 0x0c000000, paddr = 0x00100000.
Comment 1 harry he 2009-08-13 05:22:44 UTC
Created attachment 4130 [details]
sample code and scripts produce different elfs
Comment 2 Sourceware Commits 2009-08-26 01:22:13 UTC
Subject: Bug 10515

CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2009-08-26 01:21:56

Modified files:
	bfd            : ChangeLog linker.c 

Log message:
	PR ld/10515
	* linker.c (bfd_find_version_for_sym): Override a "*" match by any
	other wildcard match.  Warn on multiple wildcard matches.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4744&r2=1.4745
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/linker.c.diff?cvsroot=src&r1=1.70&r2=1.71

Comment 3 Sourceware Commits 2009-08-26 04:33:57 UTC
Subject: Bug 10515

CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2009-08-26 04:33:42

Modified files:
	bfd            : ChangeLog linker.c 

Log message:
	PR ld/10515
	* linker.c (bfd_find_version_for_sym): Revert warning.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4745&r2=1.4746
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/linker.c.diff?cvsroot=src&r1=1.71&r2=1.72

Comment 4 Alan Modra 2009-10-29 06:11:47 UTC
ld now gives an error "PHDRS and FILEHDR are not supported when prior PT_LOAD
headers lack them"