Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 891993 - >=sys-devel/lld-15.0.7 fails to cross-compile with: /bin/sh: line 1: /usr/aarch64-unknown-linux-gnu/usr/lib/llvm/15/bin/llvm-tblgen: cannot execute binary file: Exec format error
Summary: >=sys-devel/lld-15.0.7 fails to cross-compile with: /bin/sh: line 1: /usr/aar...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: LLVM support project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-25 09:22 UTC by tt_1
Modified: 2023-01-29 21:34 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
compressed build log from aarch64-cross (build.log.gz,3.00 KB, application/gzip)
2023-01-25 09:22 UTC, tt_1
Details
output from emerge --info (aarch64) (emerge-info-aarch64,5.34 KB, text/plain)
2023-01-25 09:23 UTC, tt_1
Details

Note You need to log in before you can comment on or make changes to this bug.
Description tt_1 2023-01-25 09:22:39 UTC
Created attachment 849173 [details]
compressed build log from aarch64-cross

seems the hosts portage can't make use of the llvm-tblgen within the prefix:

[1/130] cd /var/tmp/portage/sys-devel/lld-15.0.7/work/lld_build && /usr/aarch64-unknown-linux-gnu/usr/lib/llvm/15/bin/llvm-tblgen -gen-opt-parser-defs -I /var/tmp/portage/sys-devel/lld-15.0.7/work/lld/COFF -I/var/tmp/portage/sys-devel/lld-15.0.7/work/lld/include -I/var/tmp/portage/sys-devel/lld-15.0.7/work/lld_build/include -I/include -I/usr/aarch64-unknown-linux-gnu/usr/lib/llvm/15/include /var/tmp/portage/sys-devel/lld-15.0.7/work/lld/COFF/Options.td --write-if-changed -o COFF/Options.inc -d COFF/Options.inc.d
FAILED: COFF/Options.inc /var/tmp/portage/sys-devel/lld-15.0.7/work/lld_build/COFF/Options.inc 
cd /var/tmp/portage/sys-devel/lld-15.0.7/work/lld_build && /usr/aarch64-unknown-linux-gnu/usr/lib/llvm/15/bin/llvm-tblgen -gen-opt-parser-defs -I /var/tmp/portage/sys-devel/lld-15.0.7/work/lld/COFF -I/var/tmp/portage/sys-devel/lld-15.0.7/work/lld/include -I/var/tmp/portage/sys-devel/lld-15.0.7/work/lld_build/include -I/include -I/usr/aarch64-unknown-linux-gnu/usr/lib/llvm/15/include /var/tmp/portage/sys-devel/lld-15.0.7/work/lld/COFF/Options.td --write-if-changed -o COFF/Options.inc -d COFF/Options.inc.d
/bin/sh: line 1: /usr/aarch64-unknown-linux-gnu/usr/lib/llvm/15/bin/llvm-tblgen: cannot execute binary file: Exec format error
Comment 1 tt_1 2023-01-25 09:23:18 UTC
Created attachment 849175 [details]
output from emerge --info (aarch64)
Comment 2 me@kylemanke.com 2023-01-26 22:22:52 UTC
I can second this one. The ebuild tries to use the tools from the root you're merging into which obviously fails if you're cross compiling. 

Removing llvm_pkg_setup from the lld ebuild gets it through the configure stage, but there must be something else happening in cmake because it still tries to use the wrong llvm-tblgen.
Comment 3 James Le Cuirot gentoo-dev 2023-01-26 23:37:23 UTC
I thought it may just need the same treatment I gave Clang recently, but that doesn't work. I'll look closer at the weekend.
Comment 4 me@kylemanke.com 2023-01-27 15:11:42 UTC
I dug into this a little yesterday and believe I've found two issues:

1. llvm_pkg_setup will prepend ${ESYSROOT}/usr/lib/llvm/${PV}/bin to the path in front of any existing llvm installations it finds. Thus the target's llvm install will be placed before the host's llvm.

2. The main CMakeLists.txt for lld searches for the llvm installation using find_package. This only searches the sysroot and thus it finds the target's llvm installation. That's desired for any libraries it needs to link against, but it also sets LLVM_TOOLS_BINARY_DIR to the bin folder in the sysroot and subsequently uses that path to locate some build tools.

As a quick and dirty workaround, I've commented out the call to llvm_pkg_setup in the lld ebuild and manually set LLVM_TOOLS_BINARY_DIR to my llvm bin dir in CMakeLists.txt after the find_package call on line 65 and the merge succeeded.
Comment 5 James Le Cuirot gentoo-dev 2023-01-27 16:18:08 UTC
That's what I found with Clang too, but there's a CMake-related reason that I don't fully understand for why ${ESYSROOT}/usr/lib/llvm/${PV}/bin needs to be in the PATH. I was able to fix Clang without removing that from the PATH.
Comment 6 James Le Cuirot gentoo-dev 2023-01-29 21:34:39 UTC
This is now fixed.