Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 562460

Summary: cross-*/binutils with sys-libs/binutils-libs - executables incorrectly linked to host lib{bfd,opcodes}.so rather than target libraries
Product: Gentoo Linux Reporter: Andrew Church <achurch+gentoo>
Component: [OLD] Core systemAssignee: Gentoo Toolchain Maintainers <toolchain>
Status: RESOLVED FIXED    
Severity: major CC: alexander, biergaizi2009, halyx, j-pi, navid.zamani, orzel, plaes, proteuss, rose, sakaki, xaviermiller
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 564174    
Attachments: emerge-info.txt
build.log
no-binutils-libs-build.log
binutils-config-5.patch
binutils-config-5.patch

Description Andrew Church 2015-10-07 07:34:17 UTC
If sys-libs/binutils-libs is installed, attempting to build cross-binutils creates a broken assembler which fails to run, because the assembler binary is incorrectly linked to the copy of lib{opcodes,bfd}.so in /usr/lib (for the host) rather than the one in the target-specific install directory:

$ arm-unknown-linux-gnueabi-as
Assembler messages:
Fatal error: selected target format 'elf32-littlearm' unknown
$ ldd /usr/bin/arm-unknown-linux-gnueabi-as
        linux-vdso.so.1 (0x00007ffe3f90b000)
        libopcodes-2.25.1.so => /usr/lib64/libopcodes-2.25.1.so (0x00007f4bb021d000)
        libbfd-2.25.1.so => /usr/lib64/libbfd-2.25.1.so (0x00007f4bafef4000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f4bafcde000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f4baf941000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f4baf73d000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f4bb05a4000)

Note that installing binutils-libs by itself does not cause any problems; the breakage occurs when trying to build a new cross-binutils when binutils-libs is already installed.

I had thought that the problem could be worked around by uninstalling binutils-libs, building cross-binutils, then reinstalling binutils-libs, but that doesn't seem to work; the resulting executable still attempts to link to libraries in /usr/lib, thus failing to load due to missing libraries.  Since cross-*/binutils are just symlinks to sys-devel/binutils, I also suspect that if the host binutils has been rebuilt in the presence of binutils-libs, uninstalling binutils-libs would break the toolchain entirely (though I'm not about to test this on my own system).
Comment 1 Andrew Church 2015-10-07 07:36:05 UTC
Created attachment 413958 [details]
emerge-info.txt

emerge --info
Comment 2 Andrew Church 2015-10-07 07:37:15 UTC
Created attachment 413960 [details]
build.log

Build log for cross-arm-unknown-linux-gnueabi/binutils (with binutils-libs installed)
Comment 3 Andrew Church 2015-10-07 07:38:48 UTC
Created attachment 413962 [details]
no-binutils-libs-build.log

Build log for cross-arm-unknown-linux-gnueabi/binutils (after uninstalling binutils-libs)
Comment 4 Alexander Tsoy 2015-10-08 00:01:39 UTC
Do you have LD_LIBRARY_PATH is your environment?
Comment 5 Andrew Church 2015-10-08 04:25:53 UTC
(In reply to Alexander Tsoy from comment #4)
> Do you have LD_LIBRARY_PATH is your environment?

No, I don't.
Comment 6 Alexander Tsoy 2015-10-08 07:09:23 UTC
Probably a bug in binutils-config-5. Missing symlinks in /usr/${HOST}/${TARGET}/lib:

# objdump -p /usr/bin/armv7a-hardfloat-linux-gnueabi-as | grep PATH
  RUNPATH              /usr/x86_64-pc-linux-gnu/armv7a-hardfloat-linux-gnueabi/lib

# ls -l /usr/x86_64-pc-linux-gnu/armv7a-hardfloat-linux-gnueabi/lib
total 4
lrwxrwxrwx 1 root root 67 Oct  8 09:38 ldscripts -> /usr/lib64/binutils/armv7a-hardfloat-linux-gnueabi/2.25.1/ldscripts
Comment 7 Alexander Tsoy 2015-10-08 07:32:46 UTC
Created attachment 414046 [details, diff]
binutils-config-5.patch

Attached patch works for me.
Comment 8 Andrew Church 2015-10-08 08:17:42 UTC
The patch works for me as well, thanks.
Comment 9 Pinky 2015-10-14 11:22:01 UTC
Aplying patch and rebuilding binutils works for my.
Comment 10 Alexander Tsoy 2015-10-20 01:49:18 UTC
Created attachment 414948 [details, diff]
binutils-config-5.patch

Better patch. Github pull request: https://github.com/gentoo/gentoo/pull/267
Comment 11 Tom Li 2015-10-31 05:05:03 UTC
*** Bug 564514 has been marked as a duplicate of this bug. ***
Comment 12 Michael Palimaka (kensington) gentoo-dev 2015-11-10 15:27:57 UTC
*** Bug 564580 has been marked as a duplicate of this bug. ***
Comment 13 sakaki 2015-11-17 18:54:35 UTC
Fix also works for me: after applying the patch in #10 and emerging binutils-config-5-r2, crossdev is usable again (targets: armv5tel-softfloat-linux-gnueabi and powerpc-e300c3-linux-gnu, --stable). crossdev was previously dying at "Emerging cross-gcc-stage1 ..." every time.
Comment 14 SpanKY gentoo-dev 2015-11-23 09:56:57 UTC
this is because the bfd build does:
  # libbfd.a is a host library containing target dependent code
  bfdlibdir='$(libdir)'
  bfdincludedir='$(includedir)'
  if test "${host}" != "${target}"; then
    bfdlibdir='$(exec_prefix)/$(host_noncanonical)/$(target_noncanonical)/lib'
    bfdincludedir='$(exec_prefix)/$(host_noncanonical)/$(target_noncanonical)/include'
  fi

so even though we took care of setting up proper libdir/includedir paths for the cross-compiler, the bfd build went ahead and ignored those on us.

all of this comes from:
  https://www.sourceware.org/ml/binutils/2002-05/msg00184.html
Comment 15 SpanKY gentoo-dev 2015-11-23 10:24:51 UTC
newer binutils builds are fixed by:
http://gitweb.gentoo.org/repo/gentoo.git/commit/?id=03d8ab7d71176b80b20abb3309be3c294717676e

existing builds are automatically detected and will warn users, but also keep around the old symlinks until they rebuild.  we still don't want to use these paths with newer builds, so making it unconditional (i.e. reverting to previous behavior) isn't the route we want to take.
http://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7fbeab2ed7339b602b134a2bba4016e977266a54
Comment 16 SpanKY gentoo-dev 2015-11-23 10:56:14 UTC
*** Bug 563024 has been marked as a duplicate of this bug. ***
Comment 17 SpanKY gentoo-dev 2015-11-23 10:56:16 UTC
*** Bug 563754 has been marked as a duplicate of this bug. ***
Comment 18 SpanKY gentoo-dev 2015-11-23 10:56:19 UTC
*** Bug 564614 has been marked as a duplicate of this bug. ***
Comment 19 Xavier Miller (RETIRED) gentoo-dev 2015-11-23 12:24:14 UTC
Hi!

I have file collisions cross-emerging gcc-5.2.0: (target i686-gentoo-linux-gnu):
>>> Installing (1 of 1) cross-i686-gentoo-linux-gnu/gcc-5.2.0::local
 * This package will overwrite one or more files that may belong to other
 * packages (see list below). You can use a command such as `portageq
 * owners / <filename>` to identify the installed package that owns a
 * file. If portageq reports that only one package owns a file then do
 * NOT file a bug report. A bug report is only useful if it identifies at
 * least two or more packages that are known to install the same file(s).
 * If a collision occurs and you can not explain where the file came from
 * then you should simply ignore the collision since there is not enough
 * information to determine if a real problem exists. Please do NOT file
 * a bug report at http://bugs.gentoo.org unless you report exactly which
 * two packages install the same file(s). See
 * http://wiki.gentoo.org/wiki/Knowledge_Base:Blockers for tips on how to
 * solve the problem. And once again, please do NOT file a bug report
 * unless you have completely understood the above message.
 * 
 * Detected file collision(s):
 * 
 * 	/usr/lib64/libcc1.la
 * 	/usr/lib64/libcc1.so.0.0.0
 * 	/usr/lib64/libcc1.so
 * 	/usr/lib64/libcc1.so.0
 * 
 * Searching all installed packages for file collisions...
 * 


is it related or an other bug ?
Comment 20 Andrew Church 2015-11-23 13:37:00 UTC
Cross-toolchains seem to work properly now after rebuilding with the fixed eclass, even using unpatched binutils-config.  Thanks for the fix!

(In reply to Xavier Miller from comment #19)
>I have file collisions cross-emerging gcc-5.2.0: (target i686-gentoo-linux-gnu):

This bug is for binutils, so that's a separate bug.  Though it might have a similar root cause, who knows.
Comment 21 Alexander Tsoy 2015-11-23 14:10:36 UTC
(In reply to Xavier Miller from comment #19)
> ...
> is it related or an other bug ?

It's a bug 547754
Comment 22 Larry the Git Cow gentoo-dev 2018-04-13 04:06:11 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=35db5bfb5ce3af08ad8181c657a7b4f81c9dfe3b

commit 35db5bfb5ce3af08ad8181c657a7b4f81c9dfe3b
Author:     Benda Xu <heroxbd@gentoo.org>
AuthorDate: 2018-04-13 03:56:34 +0000
Commit:     Benda Xu <heroxbd@gentoo.org>
CommitDate: 2018-04-13 03:59:56 +0000

    sys-devel/binutils-config: revert accidental commit in 62c75f76eb.
    
      I have made a mistake to overwrite changes to binutils-config-5.
    
    Suggested-By: slyfox
    Bug: https://bugs.gentoo.org/531616
    Bug: https://bugs.gentoo.org/562460
    Package-Manager: Portage-2.3.28, Repoman-2.3.9

 sys-devel/binutils-config/files/binutils-config-5   | 15 ++++++++++++---
 sys-devel/binutils-config/files/binutils-config-5.1 | 15 ++++++++++++---
 2 files changed, 24 insertions(+), 6 deletions(-)}
Comment 23 Xavier Miller (RETIRED) gentoo-dev 2018-04-13 07:00:21 UTC
Nice, but the ebuild is not revbumped, so the update is not applied on installed systems...

(In reply to Larry the Git Cow from comment #22)
> The bug has been referenced in the following commit(s):
> 
> https://gitweb.gentoo.org/repo/gentoo.git/commit/
> ?id=35db5bfb5ce3af08ad8181c657a7b4f81c9dfe3b
> 
> commit 35db5bfb5ce3af08ad8181c657a7b4f81c9dfe3b
> Author:     Benda Xu <heroxbd@gentoo.org>
> AuthorDate: 2018-04-13 03:56:34 +0000
> Commit:     Benda Xu <heroxbd@gentoo.org>
> CommitDate: 2018-04-13 03:59:56 +0000
> 
>     sys-devel/binutils-config: revert accidental commit in 62c75f76eb.
>     
>       I have made a mistake to overwrite changes to binutils-config-5.
>     
>     Suggested-By: slyfox
>     Bug: https://bugs.gentoo.org/531616
>     Bug: https://bugs.gentoo.org/562460
>     Package-Manager: Portage-2.3.28, Repoman-2.3.9
> 
>  sys-devel/binutils-config/files/binutils-config-5   | 15 ++++++++++++---
>  sys-devel/binutils-config/files/binutils-config-5.1 | 15 ++++++++++++---
>  2 files changed, 24 insertions(+), 6 deletions(-)}