diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h --- a/llvm/include/llvm/Object/ELFObjectFile.h +++ b/llvm/include/llvm/Object/ELFObjectFile.h @@ -56,6 +56,7 @@ SubtargetFeatures getMIPSFeatures() const; SubtargetFeatures getARMFeatures() const; SubtargetFeatures getRISCVFeatures() const; + SubtargetFeatures getLoongArchFeatures() const; StringRef getAMDGPUCPUName() const; diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -223,6 +223,8 @@ break; case ELF::EM_BPF: break; + case ELF::EM_LOONGARCH: + return ELF::R_LARCH_RELATIVE; default: break; } diff --git a/llvm/lib/Object/ELFObjectFile.cpp b/llvm/lib/Object/ELFObjectFile.cpp --- a/llvm/lib/Object/ELFObjectFile.cpp +++ b/llvm/lib/Object/ELFObjectFile.cpp @@ -341,6 +341,26 @@ return Features; } +SubtargetFeatures ELFObjectFileBase::getLoongArchFeatures() const { + SubtargetFeatures Features; + + switch (getPlatformFlags() & ELF::EF_LOONGARCH_ABI_MODIFIER_MASK) { + case ELF::EF_LOONGARCH_ABI_SOFT_FLOAT: + break; + case ELF::EF_LOONGARCH_ABI_DOUBLE_FLOAT: + Features.AddFeature("d"); + // D implies F according to LoongArch ISA spec. + // It's only two features so don't bother with [[fallthrough]] at present. + Features.AddFeature("f"); + break; + case ELF::EF_LOONGARCH_ABI_SINGLE_FLOAT: + Features.AddFeature("f"); + break; + } + + return Features; +} + SubtargetFeatures ELFObjectFileBase::getFeatures() const { switch (getEMachine()) { case ELF::EM_MIPS: @@ -349,6 +369,8 @@ return getARMFeatures(); case ELF::EM_RISCV: return getRISCVFeatures(); + case ELF::EM_LOONGARCH: + return getLoongArchFeatures(); default: return SubtargetFeatures(); }