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

invalid relocation for non-allocated sections: R_X86_64_GOTPC64 #1003

Closed
faern opened this issue Mar 1, 2023 · 14 comments
Closed

invalid relocation for non-allocated sections: R_X86_64_GOTPC64 #1003

faern opened this issue Mar 1, 2023 · 14 comments

Comments

@faern
Copy link

faern commented Mar 1, 2023

I'm trying to switch over to mold for linking our Rust projects at https://github.com/mullvad/mullvadvpn-app/. But I get the following error when building Rust binaries that pull in our static library archive for libnftnl:

  = note: mold: fatal: /home/faern/src/mullvadvpn-app/dist-assets/binaries/x86_64-unknown-linux-gnu/libnftnl.a(utils.o):(.debug_info): invalid relocation for non-allocated sections: R_X86_64_GOTPC64
          clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

I can avoid the error and link fine if I rebuild libnftnl.a with either gcc or clang directly on my Fedora development machine (gcc 12.2.1 and clang 14.0.5) or with clang in our Debian 10 based build container (clang version 7.0.1-8+deb10u2). However, building libnftnl.a with gcc in the Debian 10 build container (gcc version 8.3.0)) is what triggers the error above.

Is the only recommended solution simply to use clang / upgrade the build environment, or is this issue fixable in mold in some way that allows us to continue building with gcc on Debian 10? I would prefer to not have to change compiler just for this, if possible.

Here is the Makefile used for building libnftnl. And here is the container definition.

Thank you for an amazingly fast linker <3

@rui314
Copy link
Owner

rui314 commented Mar 2, 2023

Thank you for your report! This should be fixed in mold. I'll make a change to support that relocation type.

@rui314
Copy link
Owner

rui314 commented Mar 2, 2023

On second thought, it is odd that a debug section contains a PC-relative relocation because the notion of PC-relative doesn't make sense for non-memory-mapped section. Can you upload your /home/faern/src/mullvadvpn-app/dist-assets/binaries/x86_64-unknown-linux-gnu/libnftnl.a so that I can take a look into it? It is likely a compiler bug that happens to work with GNU ld.

@faern
Copy link
Author

faern commented Mar 2, 2023

Absolutely. The version checked in to our repository has this issue. It's very old and built in Debian 9, but gives the same error. It's available here.

But I'll also upload a freshly built one that has the same issue but built on a newer build container (Debian 10). For comparison I'll also upload this one built in the same container from the exact same Makefile and source code, but with clang:

@rui314
Copy link
Owner

rui314 commented Mar 2, 2023

Can you also run the final link command with -Wl,--repro? If that flag is given, mold creates a tar file containing all input files with which it is very easy to re-run the same command with the same output. Please share that file with me.

@faern
Copy link
Author

faern commented Mar 2, 2023

Github will only allow me to upload 25 MiB files, and this repro tar achive is 1.3 GiB (~150MiB when compressed).... And I can't push it to a temporary git branch either because there files can only be 100 MiB... I'll sort this out somehow.

@faern
Copy link
Author

faern commented Mar 2, 2023

Here we go! The extra layer of zip is just because that's the only format Github allowed 😅

mullvad_daemon-96dd93fc4006358c.repro.tar.xz.zip

EDIT: I should probably also mention my mold version:

$ mold --version
mold 1.10.0 (compatible with GNU ld)

@rui314
Copy link
Owner

rui314 commented Mar 4, 2023

This is apparently a bug of an old version of GCC. According to its .comment section, utils.o was built by GCC 6.3.0. Are you sure you are using that old compiler? It was released in 2016.

@faern
Copy link
Author

faern commented Mar 4, 2023

The build I uploaded the repro from is indeed very old. We have not had any reason to rebuild libnftnl for a couple of years since we have had no need to upgrade it. But if we were to rebuild it today we would use our Debian 10 build images (the oldest distro our software supports, so we want to link to the oldest supported glibc), and Debian 10 currently has gcc 8.3.0 and there I see the same error message.

I can create a new repro build with the 8.3.0 build if you think that makes a difference. But it would be awesome if mold would support the newest GCC supported by Debian 10 (it's still supported, albeit in LTS now)

@rui314 rui314 closed this as completed in 77c4795 Mar 4, 2023
@rui314
Copy link
Owner

rui314 commented Mar 4, 2023

Does the above change work for you?

@faern
Copy link
Author

faern commented Mar 4, 2023

Interesting. This actually solves it for that specific version of libnftnl.a. However, when I re-build it with gcc 8.3.0 in Debian 10 I hit the same error again.. Was the fix too specific to 6.3.0?

Here is my repro for the failing build using libnftnl.a built by gcc 8.3.0 and with mold built from commit 77c4795:

mullvad_daemon-4eecad6dfc3f04fb.repro-gcc8.3.0.tar.xz

Thank you so much for paying attention to this gcc issue :)

@rui314
Copy link
Owner

rui314 commented Mar 4, 2023

Can you paste the new error message? It should be different from the previous one.

@rui314 rui314 reopened this Mar 4, 2023
@faern
Copy link
Author

faern commented Mar 4, 2023

  = note: mold: fatal: /home/faern/src/mullvadvpn-app/dist-assets/binaries/x86_64-unknown-linux-gnu/libnftnl.a(utils.o):(.debug_info): invalid relocation for non-allocated sections: R_X86_64_GOTOFF64
          clang-14: error: linker command failed with exit code 1 (use -v to see invocation)

I should not have trusted my eyes. I thought it looked the same, but it is indeed a different one!

@rui314 rui314 closed this as completed in d2970e0 Mar 5, 2023
@rui314
Copy link
Owner

rui314 commented Mar 5, 2023

Should be fixed in the above change.

@faern
Copy link
Author

faern commented Mar 5, 2023

This works! Thank you so much!

sambacha added a commit to sambacha/mullvadvpn-app that referenced this issue Apr 9, 2023
update to the commit that fixes this issue, rui314/mold#1003 
current commit points to version that does not contain fix. the issue was reopened after the commit detailing an issue that was unresolved, this commit contains that fix
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