|
67 | 67 | #include "llvm/Support/CommandLine.h"
|
68 | 68 | #include "llvm/Support/ConvertUTF.h"
|
69 | 69 | #include "llvm/Support/ErrorHandling.h"
|
| 70 | +#include "llvm/Support/RISCVISAInfo.h" |
70 | 71 | #include "llvm/Support/TimeProfiler.h"
|
71 | 72 | #include "llvm/Support/xxhash.h"
|
72 | 73 | #include "llvm/TargetParser/Triple.h"
|
@@ -1059,6 +1060,19 @@ void CodeGenModule::Release() {
|
1059 | 1060 | llvm::LLVMContext &Ctx = TheModule.getContext();
|
1060 | 1061 | getModule().addModuleFlag(llvm::Module::Error, "target-abi",
|
1061 | 1062 | llvm::MDString::get(Ctx, ABIStr));
|
| 1063 | + |
| 1064 | + // Add the canonical ISA string as metadata so the backend can set the ELF |
| 1065 | + // attributes correctly. We use AppendUnique so LTO will keep all of the |
| 1066 | + // unique ISA strings that were linked together. |
| 1067 | + const std::vector<std::string> &Features = |
| 1068 | + getTarget().getTargetOpts().Features; |
| 1069 | + auto ParseResult = llvm::RISCVISAInfo::parseFeatures( |
| 1070 | + Arch == llvm::Triple::riscv64 ? 64 : 32, Features); |
| 1071 | + if (!errorToBool(ParseResult.takeError())) |
| 1072 | + getModule().addModuleFlag( |
| 1073 | + llvm::Module::AppendUnique, "riscv-isa", |
| 1074 | + llvm::MDNode::get( |
| 1075 | + Ctx, llvm::MDString::get(Ctx, (*ParseResult)->toString()))); |
1062 | 1076 | }
|
1063 | 1077 |
|
1064 | 1078 | if (CodeGenOpts.SanitizeCfiCrossDso) {
|
|
0 commit comments