Bug 2218 - Weak undefined symbol doesn't work properly with PIE
Summary: Weak undefined symbol doesn't work properly with PIE
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks: 2251
  Show dependency treegraph
 
Reported: 2006-01-26 23:36 UTC by H.J. Lu
Modified: 2006-03-30 03:20 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A testcase (548 bytes, application/octet-stream)
2006-01-26 23:39 UTC, H.J. Lu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2006-01-26 23:36:58 UTC
Weak undefined symbol doesn't work proper with PIE. I see it on x86, x86-64
and IPF. See

http://gcc.gnu.org/ml/gcc/2006-01/msg01007.html
Comment 1 H.J. Lu 2006-01-26 23:39:41 UTC
Created attachment 852 [details]
A testcase

On x86,

[hjl@gnu-d pie-4]$ make
gcc -B./ -c -fPIC -g -DBROKEN -o foo.o foo.c
gcc -B./ -pie -o foo foo.o -Wl,-z,nocombreloc
gcc -B./ -c -fPIC -g -DOK2 -o bar.o foo.c
gcc -B./ -pie -o bar bar.o -Wl,-z,nocombreloc
gcc -B./ -o exec foo.o -Wl,-z,nocombreloc
./exec
this should be null: (nil)
./bar
this should be null: (nil)
this should be null: (nil)
./foo
this should be null: 0x1cc000

On x86-64:

[hjl@gnu-13 pie-4]$ make CC=gcc
gcc -c -fPIC -g -DBROKEN -o foo.o foo.c
gcc -pie -o foo foo.o -Wl,-z,nocombreloc
gcc -c -fPIC -g -DOK2 -o bar.o foo.c
gcc -pie -o bar bar.o -Wl,-z,nocombreloc
gcc -o exec foo.o -Wl,-z,nocombreloc
./exec
this should be null: (nil)
./bar
this should be null: (nil)
this should be null: (nil)
./foo
this should be null: 0x552aaaa000
[hjl@gnu-13 pie-4]$

On ia64,

[hjl@gnu-11 pie-4]$ make
./exec
this should be null: (nil)
./bar
this should be null: (nil)
this should be null: 0x2000000800000000
./foo
this should be null: 0x2000000800000000
[hjl@gnu-11 pie-4]$
Comment 2 H.J. Lu 2006-01-27 07:13:39 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2006-01/msg00193.html
Comment 3 H.J. Lu 2006-01-31 19:11:36 UTC
An updated patch is posted at

http://sourceware.org/ml/binutils/2006-01/msg00224.html
Comment 4 Ben Elliston 2006-03-30 03:20:10 UTC
2006-02-24  H.J. Lu  <hongjiu.lu@intel.com>

        PR ld/2218
        * elf-bfd.h (elf_backend_data): Add elf_backend_fixup_symbol.
        (_bfd_elf_link_hash_fixup_symbol): New.

        * elflink.c (_bfd_elf_link_hash_fixup_symbol): New.
        (_bfd_elf_fix_symbol_flags): Call elf_backend_fixup_symbol if
        it isn't NULL.

        * elfxx-ia64.c (elf_backend_fixup_symbol): Defined.

        * elfxx-target.h (elf_backend_fixup_symbol): New.
        (elfNN_bed): Initialize elf_backend_fixup_symbol.

2006-02-21  Alan Modra  <amodra@bigpond.net.au>

        PR ld/2218
        * elf32-arm.c (allocate_dynrelocs): Ensure undef weak sym in pie
        is dynamic.
        * elf32-hppa.c (allocate_dynrelocs): Likewise.
        * elf32-i386.c (allocate_dynrelocs): Likewise.
        * elf32-s390.c (allocate_dynrelocs): Likewise.
        * elf32-sh.c (allocate_dynrelocs): Likewise.
        * elf64-s390.c (allocate_dynrelocs): Likewise.
        * elf64-x86-64.c (allocate_dynrelocs): Likewise.
        * elf32-m32r.c (allocate_dynrelocs): Likewise.  Discard relocs
        on undef weak with non-default visibility too.
        * elfxx-sparc.c (allocate_dynrelocs): Ditto.

2006-02-17  Alan Modra  <amodra@bigpond.net.au>

        PR ld/2218
        * elf64-ppc.c (allocate_dynrelocs): Ensure undef weak sym is
        dynamic.
        (ppc64_elf_relocate_section): Check output reloc section size.
        * elf32-ppc.c (allocate_dynrelocs): Simplify undef weak test.