diff --git a/llvm/test/tools/llvm-snippy/mabi-affects-elf-abi.yaml b/llvm/test/tools/llvm-snippy/mabi-affects-elf-abi.yaml new file mode 100644 index 000000000000..3c7b4f51c1c2 --- /dev/null +++ b/llvm/test/tools/llvm-snippy/mabi-affects-elf-abi.yaml @@ -0,0 +1,16 @@ +# RUN: llvm-snippy %s -o %t.elf -model-plugin None +# RUN: llvm-readelf -h %t.elf | FileCheck %s + +options: + march: rv64gc + mtriple: riscv64 + mabi: lp64d + +include: + - Inputs/sections.yaml + +histogram: + - [ADD, 1] + +# CHECK: Machine: RISC-V +# CHECK: Flags: 0x5, RVC, double-float ABI diff --git a/llvm/tools/llvm-snippy/include/snippy/GeneratorUtils/LLVMState.h b/llvm/tools/llvm-snippy/include/snippy/GeneratorUtils/LLVMState.h index 1fe5e88cc558..d374904177fd 100644 --- a/llvm/tools/llvm-snippy/include/snippy/GeneratorUtils/LLVMState.h +++ b/llvm/tools/llvm-snippy/include/snippy/GeneratorUtils/LLVMState.h @@ -50,6 +50,7 @@ struct SelectedTargetInfo final { std::string MArch; std::string CPU; std::string Features; + std::string ABI; }; // An object to initialize LLVM and prepare objects needed to run the diff --git a/llvm/tools/llvm-snippy/lib/GeneratorUtils/LLVMState.cpp b/llvm/tools/llvm-snippy/lib/GeneratorUtils/LLVMState.cpp index 73731fe33856..d5ef34fd47fd 100644 --- a/llvm/tools/llvm-snippy/lib/GeneratorUtils/LLVMState.cpp +++ b/llvm/tools/llvm-snippy/lib/GeneratorUtils/LLVMState.cpp @@ -154,7 +154,10 @@ Expected LLVMState::create(const SelectedTargetInfo &TargetInfo) { TargetFeatures += ","; TargetFeatures += TargetInfo.Features; - const TargetOptions Options; + + TargetOptions Options; + Options.MCOptions.ABIName = TargetInfo.ABI; + auto TM = std::unique_ptr(static_cast( Tgt->createTargetMachine(TheTriple, TargetInfo.CPU, TargetFeatures, Options, Reloc::Model::Static))); diff --git a/llvm/tools/llvm-snippy/llvm-snippy.cpp b/llvm/tools/llvm-snippy/llvm-snippy.cpp index 119a6ecdd8a9..8c00c4fe5401 100644 --- a/llvm/tools/llvm-snippy/llvm-snippy.cpp +++ b/llvm/tools/llvm-snippy/llvm-snippy.cpp @@ -170,6 +170,8 @@ static SelectedTargetInfo getSelectedTargetInfo(const ProgramOptions &Opts) { TargetInfo.Triple = Opts.MTargetTriple; TargetInfo.CPU = Opts.CpuName; TargetInfo.Features = Opts.MAttr; + TargetInfo.ABI = Opts.ABI; + if (!Opts.MTargetTriple.isSpecified()) { TargetInfo.Triple = sys::getProcessTriple(); if (Opts.MArch.isSpecified())