JuliaPackaging/BinaryBuilderBase.jl

"unrecognized relocation" error in FreeBSD with GCC 4 and 5

Closed this issue · 3 comments

We recently started observing a new bug in the FreeBSD toolchain with GCC 4 and 5:

% julia -e 'using BinaryBuilderBase; BinaryBuilderBase.runshell(Platform("x86_64", "freebsd"); preferred_gcc_version=v"4")'
sandbox:${WORKSPACE} # make -C /usr/share/testsuite/
make: Entering directory '/usr/share/testsuite'
make[1]: Entering directory '/usr/share/testsuite/c/dyn_link'
x86_64-unknown-freebsd11.1-cc -shared -o /tmp/testsuite/x86_64-unknown-freebsd11.1/c/dyn_link/libfoo/libfoo.so -fPIC -g -O2 -lm libfoo/libfoo.c
x86_64-unknown-freebsd11.1-cc -o /tmp/testsuite/x86_64-unknown-freebsd11.1/c/dyn_link/dyn_link -I/usr/share/testsuite/c/dyn_link/libfoo -fPIC -g -O2 -Wl,-z,origin -Wl,-rpath,$ORIGIN/libfoo -L/tmp/testsuite/x86_64-unknown-freebsd11.1/c/dyn_link/libfoo -lfoo dyn_link.c
make[1]: Leaving directory '/usr/share/testsuite/c/dyn_link'
make[1]: Entering directory '/usr/share/testsuite/c/hello_world'
x86_64-unknown-freebsd11.1-cc -o /tmp/testsuite/x86_64-unknown-freebsd11.1/c/hello_world/hello_world -g -O2 hello_world.c
make[1]: Leaving directory '/usr/share/testsuite/c/hello_world'
make[1]: Entering directory '/usr/share/testsuite/c/openmp'
gcc -o /tmp/testsuite/x86_64-unknown-freebsd11.1/c/openmp/openmp -g -O2 -fopenmp openmp.c
make[1]: Leaving directory '/usr/share/testsuite/c/openmp'
make[1]: Entering directory '/usr/share/testsuite/cxx/dyn_link'
x86_64-unknown-freebsd11.1-c++ -shared -o /tmp/testsuite/x86_64-unknown-freebsd11.1/cxx/dyn_link/librepeater/librepeater.so -fPIC -g -O2 -lm librepeater/librepeater.cc
x86_64-unknown-freebsd11.1-c++ -o /tmp/testsuite/x86_64-unknown-freebsd11.1/cxx/dyn_link/dyn_link -I/usr/share/testsuite/cxx/dyn_link/librepeater -fPIC -g -O2 -Wl,-z,origin -Wl,-rpath,$ORIGIN/librepeater -L/tmp/testsuite/x86_64-unknown-freebsd11.1/cxx/dyn_link/librepeater -lrepeater dyn_link.cc
/opt/x86_64-unknown-freebsd11.1/bin/x86_64-unknown-freebsd11.1-ld: /tmp/dyn_link-4e028c.o: unrecognized relocation (0x2a) in section `.text'
/opt/x86_64-unknown-freebsd11.1/bin/x86_64-unknown-freebsd11.1-ld: final link failed: Bad value
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:8: /tmp/testsuite/x86_64-unknown-freebsd11.1/cxx/dyn_link/dyn_link] Error 1
make[1]: Leaving directory '/usr/share/testsuite/cxx/dyn_link'
make: *** [Makefile:45: build-project-cxx-dyn_link] Error 2
make: Leaving directory '/usr/share/testsuite'
sandbox:${WORKSPACE} #

You can observe the same with preferred_gcc_version=v"5", but no other versions. I'm not really sure why this depends on the version of GCC, maybe that's a proxy for something like binutils? Also, I have no clue why we're seeing this now (v0.6.10 currently), I believe this wasn't an issue until some time ago and we didn't change anything in FreeBSD specifically lately. I'll try to bisect the issue.

I bisected the issue to 5684f20 (#155): LLVM 12. I can confirm that tests pass with BinaryBuilderBase.runshell(Platform("x86_64", "freebsd"); preferred_gcc_version=v"4", preferred_llvm_version=v"11")

'm not really sure why this depends on the version of GCC, maybe that's a proxy for something like binutils?

It turns out I was right and this issue is also already mentioned in our very own documentation: LLVMBootstrap 12 was built with GCCBootstrap 7 because of #112 (comment), and ld from GCCBootstrap 4-5 can't link those objects.

Strictly speaking, this isn't fixed, but #160 makes sure we never use GCC 4-5 together with LLVM 12 for FreeBSD, so that this shouldn't be a problem in practice: if a user really needs GCC 4-5 they can request an older LLVM 11, if they are going to compile only with LLVM then the actual version of GCC shouldn't matter much but at least they get a working binutils. For these reasons, I'm going to close this ticket.