Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/IR/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,9 @@ class LLVM_ABI Module {

/// Set the target variant version build SDK version metadata.
void setDarwinTargetVariantSDKVersion(VersionTuple Version);

/// Returns target-abi from MDString, null if target-abi is absent.
StringRef getTargetABIFromMD();
};

/// Given "llvm.used" or "llvm.compiler.used" as a global name, collect the
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/IR/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,3 +915,11 @@ VersionTuple Module::getDarwinTargetVariantSDKVersion() const {
void Module::setDarwinTargetVariantSDKVersion(VersionTuple Version) {
addSDKVersionMD(Version, *this, "darwin.target_variant.SDK Version");
}

StringRef Module::getTargetABIFromMD() {
StringRef TargetABI;
if (auto *TargetABIMD =
dyn_cast_or_null<MDString>(getModuleFlag("target-abi")))
TargetABI = TargetABIMD->getString();
return TargetABI;
}
7 changes: 6 additions & 1 deletion llvm/lib/LTO/LTOBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,13 @@ createTargetMachine(const Config &Conf, const Target *TheTarget, Module &M) {
else
CodeModel = M.getCodeModel();

TargetOptions TargetOpts = Conf.Options;
if (TargetOpts.MCOptions.ABIName.empty()) {
TargetOpts.MCOptions.ABIName = M.getTargetABIFromMD();
}

std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
TheTriple.str(), Conf.CPU, Features.getString(), Conf.Options, RelocModel,
TheTriple.str(), Conf.CPU, Features.getString(), TargetOpts, RelocModel,
CodeModel, Conf.CGOptLevel));

assert(TM && "Failed to create target machine");
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/LTO/RISCV/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if "RISCV" not in config.root.targets:
config.unsupported = True
21 changes: 21 additions & 0 deletions llvm/test/LTO/RISCV/riscv-ilp32e.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; Check that we don't crash on DataLayout incompatibility issue.
; RUN: llvm-as %s -o %t.o
; RUN: llvm-lto2 run -r %t.o,_start %t.o -o %t.elf
; RUN: llvm-readobj -h %t.elf.0 | FileCheck %s --check-prefixes=CHECK
; CHECK: Machine: EM_RISCV (0xF3)
; CHECK: EF_RISCV_RVE (0x8)


target datalayout = "e-m:e-p:32:32-i64:64-n32-S32"
target triple = "riscv32-unknown-unknown-elf"

define dso_local i32 @_start() #0 {
entry:
ret i32 0
}

attributes #0 = { "target-cpu"="generic-rv32" "target-features"="+32bit,+e" }

!llvm.module.flags = !{!0}

!0 = !{i32 1, !"target-abi", !"ilp32e"}