[Bug ld/24815] New: ld fails to find symbols from DT_NEEDED entries

2019-07-17 Thread ismael at linux dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

Bug ID: 24815
   Summary: ld fails to find symbols from DT_NEEDED entries
   Product: binutils
   Version: unspecified
Status: UNCONFIRMED
  Severity: normal
  Priority: P2
 Component: ld
  Assignee: unassigned at sourceware dot org
  Reporter: ismael at linux dot com
  Target Milestone: ---

The system I'm having problems with is a musl-libc based system; I've an almost
identical system with glibc which works fine.

$ echo 'int main(){return 0;}' > test.c
$ gcc -c test.c
$ gcc test.o -lxml2 -fuse-ld=gold
$ gcc test.o -lxml2 -llzma
$ gcc test.o -lxml2
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: unde
fined reference to `lzma_properties_decode@XZ_5.0'
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: unde
fined reference to `lzma_code@XZ_5.0'
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: unde
fined reference to `lzma_auto_decoder@XZ_5.0'
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: unde
fined reference to `lzma_end@XZ_5.0'
collect2: error: ld returned 1 exit status
$ readelf -d /usr/lib/libxml2.so|grep lzma
 0x0001 (NEEDED) Shared library: [liblzma.so.5]
$ ldd /usr/lib/liblzma.so.5
ldd (0x7f6bc784b000)
libc.so => ldd (0x7f6bc784b000)

Files liked with all libraries specified on the command line work fine; I'm
guessing something on the binutils build is different.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/24815] ld fails to find symbols from DT_NEEDED entries

2019-07-29 Thread ismael at linux dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

--- Comment #2 from Ismael Luceno  ---
(In reply to Nick Clifton from comment #1)
> Hi Ismael,
> 
>   Have you tried linking with the "--allow-shlib-undefined" linker command
>   line option enabled ?
> 
>   By default the ld linker insists that undefined symbols in shared libraries
>   must be resolved by other libraries/objects present on the linker command
>   line.  (The gold linker does not default to this behaviour by the way).
>   The reason being that it forces builders to put all of the shared libraries
>   that their application needs on the command line.  Thus making it clear
>   to anyone examining the command line, or the build system, exactly which
>   shared libraries are needed by the application.

Hi Nick,

That seems to work fine. Now, the thing is that I don't see GCC calling ld with
that argument on the glibc-based system... yet it links the file correctly...

One fundamental difference though, is that the glibc system is using the lto
plugin.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/24815] ld fails to find symbols from DT_NEEDED entries

2019-07-29 Thread ismael at linux dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

--- Comment #3 from Ismael Luceno  ---
Just for the record:

# One random glibc system (gcc 8):
$ gcc -v test.c 2>&1 | awk '$1~/collect2$/{for(i=1;i<=NF;i++)print$i;exit}'
/usr/lib/gcc/x86_64-linux-gnu/8/collect2
-plugin
/usr/lib/gcc/x86_64-linux-gnu/8/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccwQ9xtT.res
-plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s
--build-id
--eh-frame-hdr
-m
elf_x86_64
--hash-style=gnu
--as-needed
-dynamic-linker
/lib64/ld-linux-x86-64.so.2
-pie
-z
now
-z
relro
/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o
/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/8/crtbeginS.o
-L/usr/lib/gcc/x86_64-linux-gnu/8
-L/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu
-L/usr/lib/gcc/x86_64-linux-gnu/8/../../../../lib
-L/lib/x86_64-linux-gnu
-L/lib/../lib
-L/usr/lib/x86_64-linux-gnu
-L/usr/lib/../lib
-L/usr/lib/gcc/x86_64-linux-gnu/8/../../..
/tmp/ccpw46ew.o
-lgcc
--push-state
--as-needed
-lgcc_s
--pop-state
-lc
-lgcc
--push-state
--as-needed
-lgcc_s
--pop-state
/usr/lib/gcc/x86_64-linux-gnu/8/crtendS.o
/usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/crtn.o


# The musl system (gcc 9.1):
$ gcc -v test.c 2>&1 | awk '$1~/collect2$/{for(i=1;i<=NF;i++)print$i;exit}'
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/collect2
--build-id
--eh-frame-hdr
--hash-style=gnu
-m
elf_x86_64
-dynamic-linker
/lib/ld-musl-x86_64.so.1
-pie
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/Scrt1.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/crti.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginS.o
-L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0
-L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib
-L/lib/../lib
-L/usr/lib/../lib
-L/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../..
/tmp/ccicfHhp.o
-lgcc
--push-state
--as-needed
-lgcc_s
--pop-state
-lc
-lgcc
--push-state
--as-needed
-lgcc_s
--pop-state
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtendS.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/crtn.o

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/24815] ld fails to find symbols from DT_NEEDED entries

2019-07-29 Thread ismael at linux dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

--- Comment #5 from Ismael Luceno  ---
(In reply to Alan Modra from comment #4)
> What target did you use to configure binutils?  If it didn't match
> *-*-linux-* then some linker features are not enabled.

From the build log:
> checking build system type... x86_64-pc-linux-musl

It's the same for GCC.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/24815] ld fails to find symbols from DT_NEEDED entries

2019-07-30 Thread ismael at linux dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

--- Comment #8 from Ismael Luceno  ---
# For completeness, this is from the glibc system that's otherwise equal to the
musl-libc one:
$ gcc -v test.c -lxml2 2>&1 | awk
'$1~/collect2$/{for(i=1;i<=NF;i++)print$i;exit}'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/collect2
-plugin
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccweSB2s.res
-plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s
--build-id
--eh-frame-hdr
--hash-style=gnu
-m
elf_x86_64
-dynamic-linker
/lib/ld-linux-x86-64.so.2
-pie
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/Scrt1.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/crti.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/crtbeginS.o
-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0
-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/lib/../lib
-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib
-L/lib/../lib
-L/usr/lib/../lib
-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/lib
-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../..
/tmp/ccQzormI.o
-lxml2
-lgcc
--push-state
--as-needed
-lgcc_s
--pop-state
-lc
-lgcc
--push-state
--as-needed
-lgcc_s
--pop-state
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/crtendS.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/crtn.o

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/24815] ld fails to find symbols from DT_NEEDED entries

2019-07-30 Thread ismael at linux dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

--- Comment #9 from Ismael Luceno  ---
(In reply to Fangrui Song from comment #7)
> -Wl,-t,-y,lzma_end is also useful
> 
> When linking an executable, something like --no-allow-shlib-undefined is the
> default (the opposite allow-shlib-undefine is used when linking a DSO), if
> all of libxml2.so's DT_NEEDED libs are loaded, there can be an undefined
> reference.

# With glibc:
$ gcc test.c -lxml2  -Wl,-t,-y,lzma_end
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/Scrt1.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/crti.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/crtbeginS.o
/tmp/ccDXrw7S.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libxml2.so
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libgcc_s.so
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libgcc_s.so.1
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libc.so
/lib/libc.so.6
/usr/lib/libc_nonshared.a
/lib64/ld-linux-x86-64.so.2
/usr/lib/libc_nonshared.a
/lib64/ld-linux-x86-64.so.2
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libgcc_s.so
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/libgcc_s.so.1
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/crtendS.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../lib/crtn.o
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/bin/ld:
/lib/liblzma.so.5: definition of lzma_end

# With musl-libc:
$ gcc test.c -lxml2  -Wl,-t,-y,lzma_end
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/Scrt1.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/crti.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtbeginS.o
/tmp/ccnhkcpO.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libgcc_s.so
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libgcc_s.so.1
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libc.so
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libgcc_s.so
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libgcc_s.so.1
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/libgcc.a
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/crtendS.o
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/crtn.o
/usr/bin/ld: /lib/liblzma.so.5: definition of lzma_end
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: undefined
reference to `lzma_properties_decode@XZ_5.0'
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: undefined
reference to `lzma_code@XZ_5.0'
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: undefined
reference to `lzma_auto_decoder@XZ_5.0'
/usr/bin/ld:
/usr/lib/gcc/x86_64-pc-linux-musl/9.1.0/../../../../lib/libxml2.so: undefined
reference to `lzma_end@XZ_5.0'
collect2: error: ld returned 1 exit status

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/24815] ld fails to find symbols from DT_NEEDED entries

2019-07-30 Thread ismael at linux dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=24815

Ismael Luceno  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #11 from Ismael Luceno  ---
Nevermind. The issue was on the libxml2 build.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils