-
-
Notifications
You must be signed in to change notification settings - Fork 473
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
TLSLD reloc refers external symbol guard variable #145
Comments
Which are you linking, a share object file or an executable? |
I'm linking a shared library with the static one containing the to_string() call. |
Here's a simple test to reproduce the error: |
The direct cause of the error is that there's a relocation of type TLSLD which refers an exported symbol (a symbol defined in a shared object file). What is odd is that when you pass Can you share object files of your test case? Does this link fine with other linkers? |
Yes, it seems to only happen with gcc 7. Here is the result from building both with gcc 7 ( If I remove |
It looks like the object file compiled with gcc 7 contains a symbol with the GNU_UNIQUE binding. I believe it's a deprecated feature, but I probably should support it for backward compatibility. Do you mind if I ask you to add |
It fails also with that flag: mold-test-no-unique.tar.gz |
https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html
Doesn't look deprecated to me. |
I believe this is a gcc 7's bug. Here is what I found:
Therefore, it's likely a bug in gcc 7 that it generates TLSLD relocations against STB_GNU_UNIQUE symbols. I think it should have generated TLSGD relocations instead. Indeed, the most recent version of gcc does that. I believe mold is doing the right thing -- finding an error in an input file and report it to the user. I think we have two choices:
I personally prefer 1, but it looks like what other linkers are doing is 2. So, from a practical point of view, I'll make mold to ignore this error. |
Now I get another error:
|
How about applying this patch?
|
With that patch I get this:
Now I get the shared library. But is it possible to hide the warnings? Even if they are correct, there's nothing I can do about them (except switching compiler, right?) so from my POV they are noise that I would like to avoid introducing in my build output. |
Yeah, maybe we can hide the warnings, but first of all, did the produced binary work? |
Yes. I've tried building my real project using mold and it works. |
It's probably fine to remove these error checks, but let me think a bit more about it to figure out if there's a better way than simply removing a sanity check. Even if a generated binary works fine in most cases, a binary that would trigger this error message is corrupted and possibly crash at runtime. That's probably already the case with other linkers, because other linkers don't check this error conditions, though... I'll update this bug again. |
This reverts commit 1baac27. In order to link gcc 7's output, relaxing this error check wasn't enough as reported on #145. We need to remove more error checks or keep them as-is. For now, I'll restore all the error checks, but before making another release, I may remove all error checks to accept gcc 7's buggy output files.
@MaskRay may chime in. So, it looks like there are object files in the wild that contain TLSLD relocations against non-local symbols. Because existing linkers don't check the condition, it doesn't cause any error but instead results in silently creating a corrupted binaries. Is this also the case for lld? IIRC, lld doesn't also have a check if TLSLD relocation refers a local symbol. And if that's the case, what is your opinion on how to handle the situation? I think we can't add a strict error check as it breaks (bug-)compatibility with gcc 7. |
This is suspicious, but I do not call it a bug. For a STT_TLS symbol, the glibc ld.so behavior may be similar to regular STB_GLOBAL, or it may have the STT_OBJECT STB_GNU_UNIQUE. I think GNU ld, gold, and ld.lld just handle STB_GNU_UNIQUE like the normal STB_GLOBAL, and change the output binding.
STB_GNU_UNIQUE is questionable and gets many complaints (https://news.ycombinator.com/item?id=21555752 https://www.openwall.com/lists/musl/2015/08/31/3 MaskRay/ccls#363 (comment) pytorch/pytorch#54245). |
Recent versions of GCC always emit TLSGD relocations against such symbols. So, here is my understanding:
1 and 2 contradict, no? |
If the suspicious STT_TLS/STB_GNU_UNIQUE symbol is referenced by a TLSLD relocation, I agree this is a compiler bug.
Right. |
It looks like no one except mold has code to verify that TLSLD is actually referring a non-imported symbol. Ideally, we should add this check to lld and other linkers because it can catch a compiler bug that is otherwise hard to find. However, it's probably too late. |
I have a static library that contains an object built from code that looks like this:
When I try to link with this library using mold I get the following error:
The text was updated successfully, but these errors were encountered: