-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
[llvm] Fix the MCSubtargetInfo used for module-level assembly. #97685
base: main
Are you sure you want to change the base?
Conversation
Provide both the default target CPU and default target features from the module's context, rather than empty strings. Fixes llvm#61991.
@llvm/pr-subscribers-llvm-binary-utilities Author: Chris Copeland (chrisnc) ChangesProvide both the default target CPU and default target features from the Fixes #61991. Full diff: https://github.com/llvm/llvm-project/pull/97685.diff 1 Files Affected:
diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp
index d8f520ad02c2f..079c33c801f6e 100644
--- a/llvm/lib/Object/ModuleSymbolTable.cpp
+++ b/llvm/lib/Object/ModuleSymbolTable.cpp
@@ -22,6 +22,7 @@
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InlineAsm.h"
+#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
@@ -92,8 +93,11 @@ initializeRecordStreamer(const Module &M,
if (!MAI)
return;
+ LLVMContext &Context = M.getContext();
+
std::unique_ptr<MCSubtargetInfo> STI(
- T->createMCSubtargetInfo(TT.str(), "", ""));
+ T->createMCSubtargetInfo(TT.str(), Context.getDefaultTargetCPU(),
+ Context.getDefaultTargetFeatures()));
if (!STI)
return;
|
asm("vmsr fpexc, r0"); Without fix: $ bin/clang -target arm-none-eabi test.c -c -flto=thin -mcpu=cortex-r4
<inline asm>:1:1: error: instruction requires: VFP2
1 | vmsr fpexc, r0
| ^
1 error generated.
$ bin/clang -target arm-none-eabi test.c -c -flto=thin -mcpu=cortex-r5
<inline asm>:1:1: error: instruction requires: VFP2
1 | vmsr fpexc, r0
| ^
1 error generated. With fix, using $ bin/clang -target arm-none-eabi test.c -c -flto=thin -mcpu=cortex-r4
<inline asm>:1:1: error: instruction requires: VFP2
1 | vmsr fpexc, r0
| ^
1 error generated.
$ bin/clang -target arm-none-eabi test.c -c -flto=thin -mcpu=cortex-r5 |
Credit to #61991 (comment) @Dirbaio for finding where the problem was.
|
The idea here makes sense, but the API in question is likely to change, so I'd rather not add new uses of that API until we've sorted that out. See https://discourse.llvm.org/t/functions-generated-by-function-createwithdefaultattr-should-respect-target-features/79838 . |
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.
Request changes since the ABI will change. My summary:
#96721 implemented a strategy by storing the target features in LLVMContext
, which is not serialized.
Function::createWithDefaultAttr
will load the target features from LLVMContext
.
While 96721 works well, there is a drawback that the generate module from the LTO pre-link compilation does not contain sufficient information.
Running opt
without the correct target features would not mimick Clang .
To address this drawback, we can use module flags metadata that is dropped during merging.
Oh! I did not notice that the interfaces I'm using only appeared a week ago. Thanks for the additional context.
Is this something I can do now at this call-site, or something that needs more iteration on what the correct way to store/retrieve this information from various phases should be? |
https://bugs.webkit.org/show_bug.cgi?id=282900 Reviewed by NOBODY (OOPS!). This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang will lost after it got llvm side. So we have to set arch here. More related infomations are here: - rust-lang/rust#80608 - llvm/llvm-project#61991 - llvm/llvm-project#97685 * Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp: * Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:
https://bugs.webkit.org/show_bug.cgi?id=282900 Reviewed by NOBODY (OOPS!). This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang will lost after it got llvm side. So we have to set arch here. More related infomations are here: - rust-lang/rust#80608 - llvm/llvm-project#61991 - llvm/llvm-project#97685 * Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp: * Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:
https://bugs.webkit.org/show_bug.cgi?id=282900 Reviewed by NOBODY (OOPS!). This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang will lost after it got llvm side. So we have to set arch here. More related infomations are here: - rust-lang/rust#80608 - llvm/llvm-project#61991 - llvm/llvm-project#97685 * Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp: * Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:
https://bugs.webkit.org/show_bug.cgi?id=282900 Reviewed by NOBODY (OOPS!). This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang will lost after it got llvm side. So we have to set arch here. More related infomations are here: - rust-lang/rust#80608 - llvm/llvm-project#61991 - llvm/llvm-project#97685 * Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp: * Source/JavaScriptCore/llint/LowLevelInterpreter.cpp:
https://bugs.webkit.org/show_bug.cgi?id=282900 Reviewed by Yusuke Suzuki. This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang will lost after it got llvm side. So we have to set arch here. More related infomations are here: - rust-lang/rust#80608 - llvm/llvm-project#61991 - llvm/llvm-project#97685 * Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp: * Source/JavaScriptCore/llint/LowLevelInterpreter.cpp: Canonical link: https://commits.webkit.org/286815@main
…gi?id=282900 [RISCV] Fix instruction requires the following: 'D'/'F'/'M' https://bugs.webkit.org/show_bug.cgi?id=282900 Reviewed by Yusuke Suzuki. This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang will lost after it got llvm side. So we have to set arch here. More related infomations are here: - rust-lang/rust#80608 - llvm/llvm-project#61991 - llvm/llvm-project#97685 * Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp: * Source/JavaScriptCore/llint/LowLevelInterpreter.cpp: Canonical link: https://commits.webkit.org/286815@main Canonical link: https://commits.webkit.org/282416.360@webkitglib/2.46
https://bugs.webkit.org/show_bug.cgi?id=282900 Reviewed by Yusuke Suzuki. This is a llvm bug, passing `-march=riscv64gc -cpu=lp64d` from clang will lost after it got llvm side. So we have to set arch here. More related infomations are here: - rust-lang/rust#80608 - llvm/llvm-project#61991 - llvm/llvm-project#97685 * Source/JavaScriptCore/assembler/MacroAssemblerRISCV64.cpp: * Source/JavaScriptCore/llint/LowLevelInterpreter.cpp: Canonical link: https://commits.webkit.org/286815@main
Provide both the default target CPU and default target features from the
module's context, rather than empty strings.
Fixes #61991.