Skip to content

bolt: fails to build with /usr/bin/ld.gold: internal error in do_layout, at ../../gold/object.cc:1939 #57545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sylvestre opened this issue Sep 3, 2022 · 11 comments

Comments

@sylvestre
Copy link
Collaborator

sylvestre commented Sep 3, 2022

Trying to build bolt in 15 rc3:

: && "/home/sylvestre/dev/debian/pkg-llvm/llvm-toolchain/branches/llvm-toolchain-15-15.0.0~+rc3/build-llvm/./bin/clang++" -fstack-protector-strong -Wformat -Werror=format-security -Wno-unused-command-line-argument -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -ffile-prefix-map=/home/sylvestre/dev/debian/pkg-llvm/llvm-toolchain/branches/llvm-toolchain-15-15.0.0~+rc3/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -ffile-prefix-map=/home/sylvestre/dev/debian/pkg-llvm/llvm-toolchain/branches/llvm-toolchain-15-15.0.0~+rc3/= -no-canonical-prefixes -O3 -DNDEBUG -Wl,-z,relro -Wl,--build-id -fuse-ld=gold    -Wl,--gc-sections  -Xlinker --emit-relocs tools/bolt/tools/merge-fdata/CMakeFiles/merge-fdata.dir/merge-fdata.cpp.o -o bin/merge-fdata  -Wl,-rpath,"\$ORIGIN/../lib"  lib/libLLVM-15.so.1 && :
/usr/bin/ld.gold: internal error in do_layout, at ../../gold/object.cc:1939
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
@llvmbot
Copy link
Member

llvmbot commented Sep 3, 2022

@llvm/issue-subscribers-bolt

@MaskRay
Copy link
Member

MaskRay commented Sep 3, 2022

Can you re-link the output with -fuse-ld=lld -Wl,--reproduce=/tmp/rep.tar and upload the tarball somewhere?

Having the gold version information will be useful, too.

@sylvestre
Copy link
Collaborator Author

Of course, it works with lld ;)
I uploaded it here: http://sylvestre.ledru.info/bordel/rep.tar.gz

gold version (debian testing)

$ ld.gold --version
GNU gold (GNU Binutils for Debian 2.38) 1.16
Copyright (C) 2022 Free Software Foundation, Inc.
Ce logiciel est libre ; vous pouvez le redistribuer selon les termes de la
version 3 ou suivante de la licence GNU General Public License.
Ce programme n'est couvert par AUCUNE garantie.

@aaupov
Copy link
Contributor

aaupov commented Sep 4, 2022

Hi @sylvestre,

Thank you for flagging. It's a known problem that gold linker doesn't support emit-relocs together with icf. Merge-fdata binary is linked with relocs for one BOLT test. You can disable tests for your build with -DLLVM_INCLUDE_TESTS=OFF.

I guess we can try to detect the host linker and disable that particular test if the linker is gold.

@MaskRay
Copy link
Member

MaskRay commented Sep 4, 2022

This is https://sourceware.org/bugzilla/show_bug.cgi?id=25968

With --emit-relocs + (--gc-sections || --icf), a very simple object file with .rela.eh_frame can trigger the gold assertion bug.
http://sylvestre.ledru.info/bordel/rep.tar.gz uses --emit-relocs --gc-sections.

@sylvestre
Copy link
Collaborator Author

As I am building with stage2, maybe we could use lld to do the linking ?

@sylvestre
Copy link
Collaborator Author

Not ideal but this skips the issue:

Index: llvm-toolchain-15-15.0.0~+rc3/bolt/tools/merge-fdata/CMakeLists.txt
===================================================================
--- llvm-toolchain-15-15.0.0~+rc3.orig/bolt/tools/merge-fdata/CMakeLists.txt
+++ llvm-toolchain-15-15.0.0~+rc3/bolt/tools/merge-fdata/CMakeLists.txt
@@ -9,6 +9,6 @@ add_bolt_tool(merge-fdata
 set_target_properties(merge-fdata PROPERTIES FOLDER "BOLT")
 
 # Emit relocations for BOLT meta test (bolt/test/runtime/meta-merge-fdata.test)
-if (BOLT_INCLUDE_TESTS AND UNIX AND NOT APPLE)
-  target_link_options(merge-fdata PRIVATE LINKER:--emit-relocs)
-endif()
+# if (BOLT_INCLUDE_TESTS AND UNIX AND NOT APPLE)
+#   target_link_options(merge-fdata PRIVATE LINKER:--emit-relocs)
+# endif()

@aaupov
Copy link
Contributor

aaupov commented Sep 4, 2022

As I am building with stage2, maybe we could use lld to do the linking ?

Yes, I think adding -DLLVM_ENABLE_LLD=ON is a good idea in a multi-stage build.

@v01dXYZ
Copy link
Contributor

v01dXYZ commented Jun 26, 2023

Hello,

Any news from the LLVM maintainers of bolt ? The problem is still present

target_link_options(merge-fdata PRIVATE LINKER:--emit-relocs)

@sylvestre seems to have solved it the hard way in the debian build script (https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/-/blob/snapshot/debian/patches/bolt-disable-emit-relocs.patch).

@aaupov
Copy link
Contributor

aaupov commented Jun 27, 2023

The problem falls squarely on gold linker, see Fangrui's comment above.

We add emit-relocs to this secondary tool for testing purposes, under BOLT_INCLUDE_TESTS cmake variable. If fixing the linker is not a priority, there are several ways to work around the issue, with the one used in debian build script being quite acceptable. One can also simply disable BOLT_INCLUDE_TESTS, or disable gc-sections during the build.

@aaupov aaupov closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2023
@v01dXYZ
Copy link
Contributor

v01dXYZ commented Jun 27, 2023

Thank for the response. The binutils linker issue seems pretty old now (at least 17 yo) so I guess it will remain that way forever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants