-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[AArch64] Make IFUNC opt-in rather than opt-out. #171648
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
Conversation
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
|
@llvm/pr-subscribers-backend-aarch64 Author: Harald van Dijk (hvdijk) ChangesIFUNCs require loader support, so for arbitrary environments, the safe assumption is to assume that they are not supported. In particular, aarch64-linux-pauthtest may be used with musl, and was wrongly detected as supporting IFUNCs. Full diff: https://github.com/llvm/llvm-project/pull/171648.diff 1 Files Affected:
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 25fc59e3fc258..daf20591b6731 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -2402,11 +2402,8 @@ static bool targetSupportsIRelativeRelocation(const Triple &TT) {
if (!TT.isOSBinFormatELF())
return false;
- // musl doesn't support IFUNCs.
- if (TT.isMusl())
- return false;
-
- return true;
+ // IFUNCs are supported on glibc.
+ return TT.isGNUEnvironment();
}
// Emit an ifunc resolver that returns a signed pointer to the specified target,
|
|
Oh, I see a problem. From So basically, we need to disable PAuth relocations for glibc, but we also need to disable IFUNC for anything not glibc. What target is meant to be handled here? Either way, even without this PR, #133533 looks like it has a problem, it results in a crash if the existing test is updated to use |
|
Several other libcs support IFUNC, musl is the exception. Can we make it so that |
I do not think musl is alone in not supporting it, I see no support for it in uclibc-ng either.
I think that would be wrong, What are the other triples that do support IFUNCs? Searching a bit more, I find FreeBSD and bionic and have no issue adding these in this PR, are there more? |
Yeah, there are some others that don't support it.
I wanted to avoid this turning into a long list of libcs but maybe that would be better than the somewhat confusing predicate that I added in #133533. From a quick look:
So how about we make the logic like this: if the libc supports IFUNC (according to the list above), use IFUNC, otherwise use PAuth relocations. That's still not 100% correct because we will end up using PAuth relocations even when we don't know that the target supports them, but that was the status quo before so maybe that's fine.
Okay, I was under the impression that |
Thanks, I'll update this PR accordingly. I've posted the details about the crash that I noticed earlier on #133533, but I think we can handle that separately from this PR.
That is how we are using it, but we are doing that through config file overrides. What has been merged into LLVM does not make |
0bb2d20 to
0184403
Compare
|
Updated accordingly, does that look okay? I'm a little bit concerned that a global fix like |
0184403 to
9458793
Compare
|
The current test update no longer works now that |
IFUNCs require loader support, so for arbitrary environments, the safe assumption is to assume that they are not supported. In particular, aarch64-linux-pauthtest may be used with musl, and was wrongly detected as supporting IFUNCs.
9458793 to
d9f5db5
Compare
|
I took out the removal of |
kovdan01
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! This resolves the following linker errors which started to appear after #133533 when building libcxx with signed GOT enabled:
ld.lld: error: both AUTH and non-AUTH GOT entries for '_ZTVNSt3__113basic_istreamIcNS_11char_traitsIcEEEE' requested, but only one type of GOT entry per symbol is supported
ld.lld: error: both AUTH and non-AUTH GOT entries for '_ZTVNSt3__113basic_ostreamIcNS_11char_traitsIcEEEE' requested, but only one type of GOT entry per symbol is supported
ld.lld: error: both AUTH and non-AUTH GOT entries for '_ZTVNSt3__114basic_iostreamIcNS_11char_traitsIcEEEE' requested, but only one type of GOT entry per symbol is supported
ld.lld: error: both AUTH and non-AUTH GOT entries for '_ZTVNSt3__113basic_istreamIwNS_11char_traitsIwEEEE' requested, but only one type of GOT entry per symbol is supported
ld.lld: error: both AUTH and non-AUTH GOT entries for '_ZTVNSt3__113basic_ostreamIwNS_11char_traitsIwEEEE' requested, but only one type of GOT entry per symbol is supported
ld.lld: error: both AUTH and non-AUTH GOT entries for '_ZTVNSt3__114basic_ifstreamIcNS_11char_traitsIcEEEE' requested, but only one type of GOT entry per symbol is supported
ld.lld: error: both AUTH and non-AUTH GOT entries for '_ZTVNSt3__114basic_ofstreamIcNS_11char_traitsIcEEEE' requested, but only one type of GOT entry per symbol is supported
@pcc I would appreciate if you could take a look at this as soon as you can since your changes from #133533 unfortunately break pauthtest toolchain build with signed GOT enabled, and this PR resolves the issue.
I do mention already that this fixes aarch64-linux-pauthtest, but that particular error can still occur for other targets, because that is not specific to aarch64-linux-pauthtest, but to -fptrauth-elf-got. I am working on a separate PR fixing that. |
| return (getOS() == Triple::Linux || getOS() == Triple::KFreeBSD || | ||
| getOS() == Triple::Hurd) && | ||
| !isAndroid() && !isMusl(); | ||
| !isAndroid() && !isMusl() && getEnvironment() != Triple::PAuthTest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comment that pauthtest as of now implies not particular libc implementation
| static bool targetSupportsPAuthRelocation(const Triple &TT, | ||
| const MCExpr *Target, | ||
| const MCExpr *DSExpr) { | ||
| // No released version of glibc supports PAuth relocations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change above also implicitly changed the behavior here (as isOSGlibc() started to return false for pauthtest). In order to correctly represent the intended semantics we need to gate the libc check with environment check first as this also would protect us from potential future changes if / when pautest might imply a particular libc implementation.
Ideally the check whether pauth relocations are supported or not, should also be opt-in rather than opt-out, but we'd need to add some additional hooks for this, so probably not worth at the present time.
| const MCExpr *Target, | ||
| const MCExpr *DSExpr) { | ||
| // No released version of glibc supports PAuth relocations. | ||
| if (TT.isOSGlibc() || TT.isMusl()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (TT.getEnvironment() != Triple::PAuthTest && | |
| (TT.isOSGlibc() || TT.isMusl())) |
| ; RUN: llc < ok.ll -mtriple arm64e-apple-darwin \ | ||
| ; RUN: | FileCheck %s --check-prefix=CHECK-MACHO | ||
| ; RUN: llc < ok.ll -mtriple aarch64-elf -mattr=+pauth \ | ||
| ; RUN: llc < ok.ll -mtriple aarch64-android -mattr=+pauth \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests should remain test elf triple.
|
This is not productive. |
IFUNCs require loader support, so for arbitrary environments, the safe assumption is to assume that they are not supported.
In particular, aarch64-linux-pauthtest may be used with musl, and was wrongly detected as supporting IFUNCs.