-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Workaround MSVC Linker Issue when Cross-Compiling for ARM64EC #143659
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
Workaround MSVC Linker Issue when Cross-Compiling for ARM64EC #143659
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-backend-aarch64 @llvm/pr-subscribers-llvm-ir Author: Jiachen Yuan (JiachenYuan) ChangesThis MR presents a temporary workaround for the issue described at #143575. While an upstream MSVC bug is reported, it makes sense to apply a workaround in LLVM code to quickly unblock anyone affected. Full diff: https://github.com/llvm/llvm-project/pull/143659.diff 3 Files Affected:
diff --git a/llvm/include/llvm/IR/Mangler.h b/llvm/include/llvm/IR/Mangler.h
index e3dfe1eac6189..508d85631edf9 100644
--- a/llvm/include/llvm/IR/Mangler.h
+++ b/llvm/include/llvm/IR/Mangler.h
@@ -26,7 +26,16 @@ class Triple;
class Twine;
class raw_ostream;
-constexpr std::string_view HybridPatchableTargetSuffix = "$hp_target";
+// TODO: There is a linker failure that is only hit when compiling llvm for
+// arm64ec on windows. While it is not clear what the root cause is, removing
+// the dollar sign from the following variable and re-concatenating the string
+// at its uses is a **temporary** workaround to help eliminate the linker
+// failure. The description and context of the issue is at
+// https://github.com/llvm/llvm-project/issues/143575#issuecomment-2960369418.
+// The upstream MSVC bug is filed at
+// https://developercommunity.visualstudio.com/t/MSVC-Linker-Issue-When-Cross-
+// Compiling-L/10920141.
+constexpr std::string_view HybridPatchableTargetSuffix = "hp_target";
class Mangler {
/// We need to give global values the same name every time they are mangled.
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index e13e92378d4aa..a449b1cd7521f 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -4729,6 +4729,8 @@ AsmPrinter::getCodeViewJumpTableInfo(int JTI, const MachineInstr *BranchInstr,
codeview::JumpTableEntrySize::Int32);
}
+static const std::string HPSuffix = ("$" + HybridPatchableTargetSuffix).str();
+
void AsmPrinter::emitCOFFReplaceableFunctionData(Module &M) {
const Triple &TT = TM.getTargetTriple();
assert(TT.isOSBinFormatCOFF());
@@ -4749,9 +4751,8 @@ void AsmPrinter::emitCOFFReplaceableFunctionData(Module &M) {
// For hybrid-patchable targets, strip the prefix so that we can mark
// the real function as replaceable.
- if (IsTargetArm64EC && Name.ends_with(HybridPatchableTargetSuffix)) {
- Name = Name.drop_back(HybridPatchableTargetSuffix.size());
- }
+ if (IsTargetArm64EC && Name.ends_with(HPSuffix))
+ Name = Name.drop_back(HPSuffix.size());
MCSymbol *FuncOverrideSymbol =
MMI->getContext().getOrCreateSymbol(Name + "_$fo$");
diff --git a/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp b/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
index 509cbb092705d..af1c4528990b7 100644
--- a/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp
@@ -760,6 +760,8 @@ void AArch64Arm64ECCallLowering::lowerCall(CallBase *CB) {
CB->setCalledOperand(GuardCheck);
}
+static const std::string HPSuffix = ("$" + HybridPatchableTargetSuffix).str();
+
bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
if (!GenerateThunks)
return false;
@@ -815,7 +817,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
if (!F.hasFnAttribute(Attribute::HybridPatchable) || F.isDeclaration() ||
F.hasLocalLinkage() ||
- F.getName().ends_with(HybridPatchableTargetSuffix))
+ F.getName().ends_with(HPSuffix))
continue;
// Rename hybrid patchable functions and change callers to use a global
@@ -823,7 +825,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
if (std::optional<std::string> MangledName =
getArm64ECMangledFunctionName(F.getName().str())) {
std::string OrigName(F.getName());
- F.setName(MangledName.value() + HybridPatchableTargetSuffix);
+ F.setName(MangledName.value() + HPSuffix);
// The unmangled symbol is a weak alias to an undefined symbol with the
// "EXP+" prefix. This undefined symbol is resolved by the linker by
|
@efriedma-quic to review. Thank you! |
@@ -4729,6 +4729,8 @@ AsmPrinter::getCodeViewJumpTableInfo(int JTI, const MachineInstr *BranchInstr, | |||
codeview::JumpTableEntrySize::Int32); | |||
} | |||
|
|||
static const std::string HPSuffix = ("$" + HybridPatchableTargetSuffix).str(); |
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.
We usually try to avoid global constructors...
Maybe try something like the following:
constexpr char HybridPatchableTargetSuffix_Arr[] = "$hp_target";
constexpr std::string_view HybridPatchableTargetSuffix = HybridPatchableTargetSuffix_Arr;
That should avoid declaring any symbols with $hp_target
in the mangled name, I think.
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.
It works. Thanks, I have adjusted accordingly.
7b87c4c
to
f77d33e
Compare
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
@JiachenYuan Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…43659) This MR presents a temporary workaround for the issue described at llvm#143575. While an [upstream MSVC bug](https://developercommunity.visualstudio.com/t/MSVC-Linker-Issue-When-Cross-Compiling-L/10920141) is reported, it makes sense to apply a workaround in LLVM code to quickly unblock anyone affected.
…43659) This MR presents a temporary workaround for the issue described at llvm#143575. While an [upstream MSVC bug](https://developercommunity.visualstudio.com/t/MSVC-Linker-Issue-When-Cross-Compiling-L/10920141) is reported, it makes sense to apply a workaround in LLVM code to quickly unblock anyone affected.
This MR presents a temporary workaround for the issue described at #143575. While an upstream MSVC bug is reported, it makes sense to apply a workaround in LLVM code to quickly unblock anyone affected.