Skip to content
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

Fails to link on alpha: relocation truncated to fit: GPREL16 #1166

Open
matoro opened this issue Dec 12, 2023 · 6 comments
Open

Fails to link on alpha: relocation truncated to fit: GPREL16 #1166

matoro opened this issue Dec 12, 2023 · 6 comments

Comments

@matoro
Copy link

matoro commented Dec 12, 2023

Hi, I am trying to build natively on alpha, but the final pass fails to link, with the following output.

This is using gcc 13.2.1, binutils 2.41, glibc 2.38.

After running through c++filt:

CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o: in function `std::basic_string_view<char, std::char_traits<char> > mold::elf::get_output_name<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&, std::basic_string_view<char, std::char_traits<char> >, unsigned long)':
(.text._ZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_m[std::basic_string_view<char, std::char_traits<char> > mold::elf::get_output_name<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&, std::basic_string_view<char, std::char_traits<char> >, unsigned long)]+0xc4): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::get_output_name<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&, std::basic_string_view<char, std::char_traits<char> >, unsigned long)::prefixes' defined in .sbss._ZGVZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_mE8prefixes[guard variable for mold::elf::get_output_name<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&, std::basic_string_view<char, std::char_traits<char> >, unsigned long)::prefixes] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_m[std::basic_string_view<char, std::char_traits<char> > mold::elf::get_output_name<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&, std::basic_string_view<char, std::char_traits<char> >, unsigned long)]+0x130): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::get_output_name<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&, std::basic_string_view<char, std::char_traits<char> >, unsigned long)::prefixes' defined in .sbss._ZGVZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_mE8prefixes_0[guard variable for mold::elf::get_output_name<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&, std::basic_string_view<char, std::char_traits<char> >, unsigned long)::prefixes] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o: in function `void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)':
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)]+0x1c): relocation truncated to fit: GPREL16 against symbol `mold::Counter::enabled' defined in .sbss._ZN4mold7Counter7enabledE[mold::Counter::enabled] section in CMakeFiles/mold.dir/elf/cmdline.cc.X86_64.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)]+0x50): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::defined' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE7defined[guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::defined] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)]+0x74): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::undefined' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE9undefined[guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::undefined] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)]+0x28c): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::alloc' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE5alloc[guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::alloc] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)]+0x2a0): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::nonalloc' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE8nonalloc[guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::nonalloc] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)]+0x490): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::comdats' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE7comdats[guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::comdats] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)]+0x4b0): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::removed_comdats' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE15removed_comdats[guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::removed_comdats] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)]+0x51c): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::num_cies' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE8num_cies[guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::num_cies] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)]+0x53c): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status

I offer free shell access to the machine I reproduced this on if it will help debugging the problem.

@rui314
Copy link
Owner

rui314 commented Dec 12, 2023

Ah, nice, so you have a physical Alpha machine. Let me try to debug it. I'll send you an email for a remote access.

@matoro
Copy link
Author

matoro commented Dec 12, 2023

Ah, nice, so you have a physical Alpha machine. Let me try to debug it. I'll send you an email for a remote access.

Sure thing thanks! You should be able to log in as g-ruiu now. I've preinstalled all the deps for mold as well. Let me know if there's anything else you need!

@rui314
Copy link
Owner

rui314 commented Dec 16, 2023

When I tried to build mold on your Alpha machine, the last link step failed probably due to the out-of-memory error of the GNU linker. Do you mind if I ask how you built mold?

@matoro
Copy link
Author

matoro commented Dec 18, 2023

When I tried to build mold on your Alpha machine, the last link step failed probably due to the out-of-memory error of the GNU linker. Do you mind if I ask how you built mold?

What CFLAGS were you using? I have 10G of swap set up but after testing it myself I didn't even go through the 2G of physical RAM.

Here is a tarball of the build directory. Here's a minimal reproducer to trigger the error, from inside mold-2.4.0/work/mold-2.4.0_build:

$ time $(cat ../../temp/build.log | grep "create_symlink" | tail -n 1 | cut -d "&" -f 3)
CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o: in function `std::basic_string_view<char, std::char_traits<char> > mold::elf::get_output_name<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&, std::basic_string_view<char, std::char_traits<char> >, unsigned long)':
(.text._ZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_m[_ZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_m]+0xc4): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::get_output_name<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&, std::basic_string_view<char, std::char_traits<char> >, unsigned long)::prefixes' defined in .sbss._ZGVZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_mE8prefixes[_ZGVZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_mE8prefixes] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_m[_ZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_m]+0x130): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::get_output_name<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&, std::basic_string_view<char, std::char_traits<char> >, unsigned long)::prefixes' defined in .sbss._ZGVZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_mE8prefixes_0[_ZGVZN4mold3elf15get_output_nameINS0_6RV64BEEEESt17basic_string_viewIcSt11char_traitsIcEERNS0_7ContextIT_EES6_mE8prefixes_0] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o: in function `void mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)':
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[_ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE]+0x1c): relocation truncated to fit: GPREL16 against symbol `mold::Counter::enabled' defined in .sbss._ZN4mold7Counter7enabledE[_ZN4mold7Counter7enabledE] section in CMakeFiles/mold.dir/elf/cmdline.cc.X86_64.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[_ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE]+0x50): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::defined' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE7defined[_ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE7defined] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[_ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE]+0x74): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::undefined' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE9undefined[_ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE9undefined] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[_ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE]+0x28c): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::alloc' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE5alloc[_ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE5alloc] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[_ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE]+0x2a0): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::nonalloc' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE8nonalloc[_ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE8nonalloc] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[_ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE]+0x490): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::comdats' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE7comdats[_ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE7comdats] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[_ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE]+0x4b0): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::removed_comdats' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE15removed_comdats[_ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE15removed_comdats] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[_ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE]+0x51c): relocation truncated to fit: GPREL16 against symbol `guard variable for mold::elf::show_stats<mold::elf::RV64BE>(mold::elf::Context<mold::elf::RV64BE>&)::num_cies' defined in .sbss._ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE8num_cies[_ZGVZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EEE8num_cies] section in CMakeFiles/mold.dir/elf/passes.cc.RV64BE.cc.o
(.text._ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE[_ZN4mold3elf10show_statsINS0_6RV64BEEEEvRNS0_7ContextIT_EE]+0x53c): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status

real    0m36.050s
user    0m12.340s
sys     0m4.609s

If you want to build from scratch with these settings, I think the following command should modify the build files:

find . -type f | while read line ; do sed -i "s#/var/tmp/portage/sys-devel/mold-2.4.0#${HOME}/mold-2.4.0#g" "${line}" ; done

Let me know if that is enough info to reproduce for you?

matoro referenced this issue Sep 26, 2024
Keeping DEC Alpha support is difficult because there are no Alpha
machines available for toolchain developers, and even if there were,
no modern Linux distros still support Alpha. For example, Debian
dropped Alpha support in Debian 6.0. As a result, I cannot test my
linker with real-world programs.

In fact, I believe mold has never been able to link real-world large
programs. Object files for Alpha are compiled with the small code
model by default, so it is not easy to support it in the linker.

There's no means to verify that my implementation is correct for Alpha
because Alpha's psABI has never been published by DEC. The most
"reliable" source of correctness is GNU ld's source code and comments.

Last but not least, I believe there are literally zero mold/Alpha
users. Unlike some other retro computers like the m68k, Alpha doesn't
seem to get much love from the community, perhaps because the
availability of Alpha machines was limited in the first place, even in
the 90s.

Therefore, I'll remove Alpha support now. If there's someone who wants
to keep it, we can resurrect and re-test it.

This change should make the mold binary size a little smaller.
@matoro
Copy link
Author

matoro commented Sep 30, 2024

As requested, I reran this using current binutils and latest mold tag (2.33.0). It now builds, but I get some test failures. See the following log: build.log

Test failures seem to look like this:

+ alpha-unknown-linux-gnu-g++ -c -o out/test/elf/alpha/exception/b.o out/test/elf/alpha/exception/a.cc -fPIC
+ alpha-unknown-linux-gnu-g++ -c -o out/test/elf/alpha/exception/c.o out/test/elf/alpha/exception/a.cc -fno-PIC
+ alpha-unknown-linux-gnu-g++ -B. -o out/test/elf/alpha/exception/exe1 out/test/elf/alpha/exception/b.o -static -pthread
mimalloc: warning: unable to allocate aligned OS memory directly, fall back to over-allocation (size: 0x2000000 bytes, address: 0x020002B6C000, alignment: 0x2000000, commit: 1)
mold: error: duplicate symbol: /usr/lib/libc.a(divlu.o): /usr/lib/libc.a(divl.o): __divbyzero
mold: error: duplicate symbol: /usr/lib/libc.a(divq.o): /usr/lib/libc.a(divl.o): __divbyzero
mold: error: duplicate symbol: /usr/lib/libc.a(divqu.o): /usr/lib/libc.a(divl.o): __divbyzero
mold: error: duplicate symbol: /usr/lib/libc.a(reml.o): /usr/lib/libc.a(divl.o): __divbyzero
mold: error: duplicate symbol: /usr/lib/libc.a(remlu.o): /usr/lib/libc.a(divl.o): __divbyzero
mold: error: duplicate symbol: /usr/lib/libc.a(remqu.o): /usr/lib/libc.a(divl.o): __divbyzero
collect2: error: ld returned 1 exit status

@rui314
Copy link
Owner

rui314 commented Sep 30, 2024

I could actually build mold 2.33.0 on qemu-system-alpha (even though the build took very long because qemu-system-alpha doesn't support SMP), and all tests pass in my case. However, mold built using mold crash with SIGSEGV. It indicated that mold mis-links large programs. I suspect that that failed because of a similar reason as a (not integrated) MIPS support, as Alpha code seems to be compiled for the small code model by default. I don't think I have enough time to fix it.

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

No branches or pull requests

2 participants