Bug 19171 - [Regression] ld assertion fail ../../bfd/elf32-i386.c:5245 on i686-linux-gnu
Summary: [Regression] ld assertion fail ../../bfd/elf32-i386.c:5245 on i686-linux-gnu
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.26
Assignee: H.J. Lu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-25 23:44 UTC by Matthias Klose
Modified: 2015-10-26 15:18 UTC (History)
1 user (show)

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


Attachments
test case (2.44 MB, application/x-xz)
2015-10-25 23:44 UTC, Matthias Klose
Details
A patch (1014 bytes, patch)
2015-10-26 02:35 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2015-10-25 23:44:51 UTC
Created attachment 8739 [details]
test case

seen with trunk 20151022 on i686-linux-gnu

$ sh -x link.sh + ld -L. --build-id --eh-frame-hdr -m elf_i386 --hash-style=gnu --as-needed -shared -z relro -o liblttng-ust.so.0.0.0 crti.o crtbeginS.o --whole-archive libustsnprintf.a liblttng-ust-comm.a liblttng-ust-runtime.a liblttng-ust-support.a --no-whole-archive -ldl liblttng-ust-tracepoint.so -lrt -lurcu-bp -lurcu-cds -lpthread -Bsymbolic-functions -z relro -soname liblttng-ust.so.0 -lssp_nonshared -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtendS.o crtn.o
liblttng-ust-support.a(libringbuffer_la-shm.o): In function `_shm_object_table_alloc_shm':
/home/packages/tmp/x/ust-2.6.3/libringbuffer/shm.c:150: warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
ld: BFD (GNU Binutils for Ubuntu) 2.25.51.20151022 assertion fail ../../bfd/elf32-i386.c:5245
Comment 1 H.J. Lu 2015-10-26 00:26:20 UTC
Please provide prepossessed lttng-ust-baddr.c in liblttng-ust-runtime.a.
Comment 2 H.J. Lu 2015-10-26 00:31:16 UTC
(In reply to H.J. Lu from comment #1)
> Please provide prepossessed lttng-ust-baddr.c in liblttng-ust-runtime.a.

Never mind.  I know what went wrong.
Comment 3 H.J. Lu 2015-10-26 01:44:06 UTC
[hjl@gnu-tools-1 pr19161]$ cat x.c
extern int a;

extern int __start_my_section __attribute__((weak,visibility("hidden")));

int
dump1()
{
   int* ap = &__start_my_section;
   return ap[0];
}
[hjl@gnu-tools-1 pr19161]$ cat y.c
extern int a[];

extern int __start_my_section __attribute__((weak,visibility("hidden")));

int
dump2()
{
   int* ap = &__start_my_section;
   return ap[0];
}
[hjl@gnu-tools-1 pr19161]$ cat z.c
int __attribute__((section("my_section"))) a[2] = {0x1234, 0x5678};

extern int __start_my_section __attribute__((weak,visibility("hidden")));

int
dump3()
{
   int* ap = &__start_my_section;
   return ap[0];
}
[hjl@gnu-tools-1 pr19161]$ gcc -fPIC -O2 -c x.c y.c z.c -m32
[hjl@gnu-tools-1 pr19161]$  ld -m elf_i386   x.o y.o  z.o  -shared 
ld: BFD (Linux/GNU Binutils) 2.25.51.0.4.20151022 assertion fail /net/gnu-6/export/linux/src/binutils/binutils/bfd/elf32-i386.c:5281
[hjl@gnu-tools-1 pr19161]$
Comment 4 H.J. Lu 2015-10-26 02:35:02 UTC
Created attachment 8740 [details]
A patch

Please try this.
Comment 5 Matthias Klose 2015-10-26 03:02:49 UTC
this patch allows the package to build.
Comment 6 cvs-commit@gcc.gnu.org 2015-10-26 15:16:32 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a6af384b19c63bab4a1803c09592c5b5bd8674c2

commit a6af384b19c63bab4a1803c09592c5b5bd8674c2
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Oct 26 06:10:23 2015 -0700

    Properly convert address load of __start_XXX/__stop_XXX
    
    Since __start_XXX and __stop_XXX symbols aren't defined when address
    load is being converted, we need to check if there is an XXX output
    section to get their section and value.  This patch adds a new function,
    bfd_link_get_defined_symbol, to search for the XXX output section to
    check if __start_XXX and __stop_XXX symbols are defined.
    
    bfd/
    
    	PR ld/19171
    	* elf32-i386.c (elf_i386_convert_load): Call
    	bfd_link_get_defined_symbol to check if a symbol is defined.
    	* elf64-x86-64.c (elf_x86_64_convert_load): Call
    	bfd_link_get_defined_symbol to get defined symbol section and
    	value.
    	* linker.c (bfd_link_get_defined_symbol): New function.
    	* bfd-in2.h: Regenerated.
    
    ld/testsuite/
    
    	PR ld/19171
    	* ld-i386/lea1.s: Add tests for address load of __start_XXX
    	and __stop_XXX.
    	* ld-i386/mov1.s: Likewise.
    	* ld-x86-64/lea1.s: Likewise.
    	* ld-x86-64/mov1.s: Likewise.
    	* ld-i386/lea1a.d: Updated.
    	* ld-i386/lea1b.d: Likewise.
    	* ld-i386/lea1c.d: Likewise.
    	* ld-i386/mov1a.d: Likewise.
    	* ld-i386/mov1b.d: Likewise.
    	* ld-x86-64/lea1a.d: Likewise.
    	* ld-x86-64/lea1b.d: Likewise.
    	* ld-x86-64/lea1c.d: Likewise.
    	* ld-x86-64/lea1d.d: Likewise.
    	* ld-x86-64/lea1e.d: Likewise.
    	* ld-x86-64/lea1f.d: Likewise.
    	* ld-x86-64/mov1a.d: Likewise.
    	* ld-x86-64/mov1b.d: Likewise.
    	* ld-x86-64/mov1c.d: Likewise.
    	* ld-x86-64/mov1d.d: Likewise.
Comment 7 H.J. Lu 2015-10-26 15:18:52 UTC
Fixed.