diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h --- a/llvm/include/llvm/BinaryFormat/ELF.h +++ b/llvm/include/llvm/BinaryFormat/ELF.h @@ -903,22 +903,20 @@ // LoongArch Specific e_flags enum : unsigned { - // Reference: https://github.com/loongson/LoongArch-Documentation. - // The last commit hash (main branch) is - // 99016636af64d02dee05e39974d4c1e55875c45b. - // Note that there is an open PR - // https://github.com/loongson/LoongArch-Documentation/pull/47 - // talking about using 0x1, 0x2, 0x3 for ILP32S/F/D and use EI_CLASS to - // distinguish LP64 and ILP32. If this PR get merged, we will update - // the definition here. - // Base ABI Types. - EF_LOONGARCH_BASE_ABI_LP64S = 0x1, // LP64 soft-float ABI - EF_LOONGARCH_BASE_ABI_LP64F = 0x2, // LP64 single-float ABI - EF_LOONGARCH_BASE_ABI_LP64D = 0x3, // LP64 double-float ABI - EF_LOONGARCH_BASE_ABI_ILP32S = 0x5, // ILP32 soft-float ABI - EF_LOONGARCH_BASE_ABI_ILP32F = 0x6, // ILP32 single-float ABI - EF_LOONGARCH_BASE_ABI_ILP32D = 0x7, // ILP32 double-float ABI - EF_LOONGARCH_BASE_ABI_MASK = 0x7, // Mask for selecting base ABI + // Definitions from LoongArch ELF psABI v2.01. + // Reference: https://github.com/loongson/LoongArch-Documentation + // (commit hash 296de4def055c871809068e0816325a4ac04eb12) + + // Base ABI Modifiers + EF_LOONGARCH_ABI_SOFT_FLOAT = 0x1, + EF_LOONGARCH_ABI_SINGLE_FLOAT = 0x2, + EF_LOONGARCH_ABI_DOUBLE_FLOAT = 0x3, + EF_LOONGARCH_ABI_MODIFIER_MASK = 0x7, + + // Object file ABI versions + EF_LOONGARCH_OBJABI_V0 = 0x0, + EF_LOONGARCH_OBJABI_V1 = 0x40, + EF_LOONGARCH_OBJABI_MASK = 0xC0, }; // ELF Relocation types for LoongArch diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -520,12 +520,11 @@ BCase(EF_AVR_LINKRELAX_PREPARED); break; case ELF::EM_LOONGARCH: - BCaseMask(EF_LOONGARCH_BASE_ABI_ILP32S, EF_LOONGARCH_BASE_ABI_MASK); - BCaseMask(EF_LOONGARCH_BASE_ABI_ILP32F, EF_LOONGARCH_BASE_ABI_MASK); - BCaseMask(EF_LOONGARCH_BASE_ABI_ILP32D, EF_LOONGARCH_BASE_ABI_MASK); - BCaseMask(EF_LOONGARCH_BASE_ABI_LP64S, EF_LOONGARCH_BASE_ABI_MASK); - BCaseMask(EF_LOONGARCH_BASE_ABI_LP64F, EF_LOONGARCH_BASE_ABI_MASK); - BCaseMask(EF_LOONGARCH_BASE_ABI_LP64D, EF_LOONGARCH_BASE_ABI_MASK); + BCaseMask(EF_LOONGARCH_ABI_SOFT_FLOAT, EF_LOONGARCH_ABI_MODIFIER_MASK); + BCaseMask(EF_LOONGARCH_ABI_SINGLE_FLOAT, EF_LOONGARCH_ABI_MODIFIER_MASK); + BCaseMask(EF_LOONGARCH_ABI_DOUBLE_FLOAT, EF_LOONGARCH_ABI_MODIFIER_MASK); + BCaseMask(EF_LOONGARCH_OBJABI_V0, EF_LOONGARCH_OBJABI_MASK); + BCaseMask(EF_LOONGARCH_OBJABI_V1, EF_LOONGARCH_OBJABI_MASK); break; case ELF::EM_RISCV: BCase(EF_RISCV_RVC); diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp --- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp +++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFStreamer.cpp @@ -37,33 +37,28 @@ MCAssembler &MCA = getStreamer().getAssembler(); LoongArchABI::ABI ABI = getTargetABI(); - // FIXME: - // There are several PRs [1][2][3] that may affect the e_flags. - // After they got closed or merged, we should update the implementation here - // accordingly. + // Figure out the e_flags. // - // [1] https://github.com/loongson/LoongArch-Documentation/pull/33 - // [2] https://github.com/loongson/LoongArch-Documentation/pull/47 - // [2] https://github.com/loongson/LoongArch-Documentation/pull/61 + // Bitness is already represented with the EI_CLASS byte in the current spec, + // so here we only record the base ABI modifier. Also set the object file ABI + // version to v1, as upstream LLVM cannot handle the previous stack-machine- + // based relocs from day one. + // + // Refer to LoongArch ELF psABI v2.01 for details. unsigned EFlags = MCA.getELFHeaderEFlags(); + EFlags |= ELF::EF_LOONGARCH_OBJABI_V1; switch (ABI) { case LoongArchABI::ABI_ILP32S: - EFlags |= ELF::EF_LOONGARCH_BASE_ABI_ILP32S; - break; - case LoongArchABI::ABI_ILP32F: - EFlags |= ELF::EF_LOONGARCH_BASE_ABI_ILP32F; - break; - case LoongArchABI::ABI_ILP32D: - EFlags |= ELF::EF_LOONGARCH_BASE_ABI_ILP32D; - break; case LoongArchABI::ABI_LP64S: - EFlags |= ELF::EF_LOONGARCH_BASE_ABI_LP64S; + EFlags |= ELF::EF_LOONGARCH_ABI_SOFT_FLOAT; break; + case LoongArchABI::ABI_ILP32F: case LoongArchABI::ABI_LP64F: - EFlags |= ELF::EF_LOONGARCH_BASE_ABI_LP64F; + EFlags |= ELF::EF_LOONGARCH_ABI_SINGLE_FLOAT; break; + case LoongArchABI::ABI_ILP32D: case LoongArchABI::ABI_LP64D: - EFlags |= ELF::EF_LOONGARCH_BASE_ABI_LP64D; + EFlags |= ELF::EF_LOONGARCH_ABI_DOUBLE_FLOAT; break; case LoongArchABI::ABI_Unknown: llvm_unreachable("Improperly initialized target ABI"); diff --git a/llvm/test/CodeGen/LoongArch/e_flags.ll b/llvm/test/CodeGen/LoongArch/e_flags.ll --- a/llvm/test/CodeGen/LoongArch/e_flags.ll +++ b/llvm/test/CodeGen/LoongArch/e_flags.ll @@ -1,14 +1,16 @@ ; RUN: llc --mtriple=loongarch32 --filetype=obj %s -o %t-la32 -; RUN: llvm-readelf -h %t-la32 | FileCheck %s --check-prefix=ILP32D --match-full-lines +; RUN: llvm-readelf -h %t-la32 | FileCheck %s --check-prefixes=ILP32,ABI-D --match-full-lines ; RUN: llc --mtriple=loongarch64 --filetype=obj %s -o %t-la64 -; RUN: llvm-readelf -h %t-la64 | FileCheck %s --check-prefix=LP64D --match-full-lines +; RUN: llvm-readelf -h %t-la64 | FileCheck %s --check-prefixes=LP64,ABI-D --match-full-lines ;; Note that we have not support the -target-abi option to select specific ABI. ;; See comments in LoongArchELFStreamer.cpp. So here we only check the default behaviour. ;; After -target-abi is supported, we can add more tests. -; LP64D: Flags: 0x3, LP64, DOUBLE-FLOAT -; ILP32D: Flags: 0x7, ILP32, DOUBLE-FLOAT +; LP64: Class: ELF64 +; ILP32: Class: ELF32 + +; ABI-D: Flags: 0x43, DOUBLE-FLOAT, OBJ-v1 define void @foo() { ret void diff --git a/llvm/test/tools/llvm-readobj/ELF/loongarch-eflags.test b/llvm/test/tools/llvm-readobj/ELF/loongarch-eflags.test --- a/llvm/test/tools/llvm-readobj/ELF/loongarch-eflags.test +++ b/llvm/test/tools/llvm-readobj/ELF/loongarch-eflags.test @@ -1,59 +1,95 @@ -## Check llvm-readobj is able to decode all possible LoongArch e_flags field values. +## Check llvm-readobj's ability to decode all possible LoongArch e_flags field +## values. -# RUN: yaml2obj %s -o %t-lp64s -DCLASS=64 -DFLAG=LP64S -# RUN: llvm-readobj -h %t-lp64s | FileCheck --check-prefix=READOBJ-LP64S %s -# RUN: llvm-readelf -h %t-lp64s | FileCheck --check-prefix=READELF-LP64S --match-full-lines %s +## Not all combinations covered here exist in reality (such as the v0 ILP32* +## objects) but they are included nevertheless for completeness. -# RUN: yaml2obj %s -o %t-lp64f -DCLASS=64 -DFLAG=LP64F -# RUN: llvm-readobj -h %t-lp64f | FileCheck --check-prefix=READOBJ-LP64F %s -# RUN: llvm-readelf -h %t-lp64f | FileCheck --check-prefix=READELF-LP64F --match-full-lines %s +# RUN: yaml2obj %s -o %t-lp64s -DCLASS=64 -DABI_MODIFIER=SOFT -DOBJABI_VER=0 +# RUN: llvm-readobj -h %t-lp64s | FileCheck --check-prefixes=READOBJ-LP64,READOBJ-SOFT-V0 %s +# RUN: llvm-readelf -h %t-lp64s | FileCheck --check-prefixes=READELF-LP64,READELF-SOFT-V0 --match-full-lines %s -# RUN: yaml2obj %s -o %t-lp64d -DCLASS=64 -DFLAG=LP64D -# RUN: llvm-readobj -h %t-lp64d | FileCheck --check-prefix=READOBJ-LP64D %s -# RUN: llvm-readelf -h %t-lp64d | FileCheck --check-prefix=READELF-LP64D --match-full-lines %s +# RUN: yaml2obj %s -o %t-lp64f -DCLASS=64 -DABI_MODIFIER=SINGLE -DOBJABI_VER=0 +# RUN: llvm-readobj -h %t-lp64f | FileCheck --check-prefixes=READOBJ-LP64,READOBJ-SINGLE-V0 %s +# RUN: llvm-readelf -h %t-lp64f | FileCheck --check-prefixes=READELF-LP64,READELF-SINGLE-V0 --match-full-lines %s -# RUN: yaml2obj %s -o %t-ilp32s -DCLASS=32 -DFLAG=ILP32S -# RUN: llvm-readobj -h %t-ilp32s | FileCheck --check-prefix=READOBJ-ILP32S %s -# RUN: llvm-readelf -h %t-ilp32s | FileCheck --check-prefix=READELF-ILP32S --match-full-lines %s +# RUN: yaml2obj %s -o %t-lp64d -DCLASS=64 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=0 +# RUN: llvm-readobj -h %t-lp64d | FileCheck --check-prefixes=READOBJ-LP64,READOBJ-DOUBLE-V0 %s +# RUN: llvm-readelf -h %t-lp64d | FileCheck --check-prefixes=READELF-LP64,READELF-DOUBLE-V0 --match-full-lines %s -# RUN: yaml2obj %s -o %t-ilp32f -DCLASS=32 -DFLAG=ILP32F -# RUN: llvm-readobj -h %t-ilp32f | FileCheck --check-prefix=READOBJ-ILP32F %s -# RUN: llvm-readelf -h %t-ilp32f | FileCheck --check-prefix=READELF-ILP32F --match-full-lines %s +# RUN: yaml2obj %s -o %t-ilp32s -DCLASS=32 -DABI_MODIFIER=SOFT -DOBJABI_VER=0 +# RUN: llvm-readobj -h %t-ilp32s | FileCheck --check-prefixes=READOBJ-ILP32,READOBJ-SOFT-V0 %s +# RUN: llvm-readelf -h %t-ilp32s | FileCheck --check-prefixes=READELF-ILP32,READELF-SOFT-V0 --match-full-lines %s -# RUN: yaml2obj %s -o %t-ilp32d -DCLASS=32 -DFLAG=ILP32D -# RUN: llvm-readobj -h %t-ilp32d | FileCheck --check-prefix=READOBJ-ILP32D %s -# RUN: llvm-readelf -h %t-ilp32d | FileCheck --check-prefix=READELF-ILP32D --match-full-lines %s +# RUN: yaml2obj %s -o %t-ilp32f -DCLASS=32 -DABI_MODIFIER=SINGLE -DOBJABI_VER=0 +# RUN: llvm-readobj -h %t-ilp32f | FileCheck --check-prefixes=READOBJ-ILP32,READOBJ-SINGLE-V0 %s +# RUN: llvm-readelf -h %t-ilp32f | FileCheck --check-prefixes=READELF-ILP32,READELF-SINGLE-V0 --match-full-lines %s -# READOBJ-LP64S: Flags [ (0x1) -# READOBJ-LP64S-NEXT: EF_LOONGARCH_BASE_ABI_LP64S (0x1) -# READOBJ-LP64S-NEXT: ] +# RUN: yaml2obj %s -o %t-ilp32d -DCLASS=32 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=0 +# RUN: llvm-readobj -h %t-ilp32d | FileCheck --check-prefixes=READOBJ-ILP32,READOBJ-DOUBLE-V0 %s +# RUN: llvm-readelf -h %t-ilp32d | FileCheck --check-prefixes=READELF-ILP32,READELF-DOUBLE-V0 --match-full-lines %s -# READOBJ-LP64F: Flags [ (0x2) -# READOBJ-LP64F-NEXT: EF_LOONGARCH_BASE_ABI_LP64F (0x2) -# READOBJ-LP64F-NEXT: ] +# RUN: yaml2obj %s -o %t-lp64s -DCLASS=64 -DABI_MODIFIER=SOFT -DOBJABI_VER=1 +# RUN: llvm-readobj -h %t-lp64s | FileCheck --check-prefixes=READOBJ-LP64,READOBJ-SOFT-V1 %s +# RUN: llvm-readelf -h %t-lp64s | FileCheck --check-prefixes=READELF-LP64,READELF-SOFT-V1 --match-full-lines %s -# READOBJ-LP64D: Flags [ (0x3) -# READOBJ-LP64D-NEXT: EF_LOONGARCH_BASE_ABI_LP64D (0x3) -# READOBJ-LP64D-NEXT: ] +# RUN: yaml2obj %s -o %t-lp64f -DCLASS=64 -DABI_MODIFIER=SINGLE -DOBJABI_VER=1 +# RUN: llvm-readobj -h %t-lp64f | FileCheck --check-prefixes=READOBJ-LP64,READOBJ-SINGLE-V1 %s +# RUN: llvm-readelf -h %t-lp64f | FileCheck --check-prefixes=READELF-LP64,READELF-SINGLE-V1 --match-full-lines %s -# READOBJ-ILP32S: Flags [ (0x5) -# READOBJ-ILP32S-NEXT: EF_LOONGARCH_BASE_ABI_ILP32S (0x5) -# READOBJ-ILP32S-NEXT: ] +# RUN: yaml2obj %s -o %t-lp64d -DCLASS=64 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=1 +# RUN: llvm-readobj -h %t-lp64d | FileCheck --check-prefixes=READOBJ-LP64,READOBJ-DOUBLE-V1 %s +# RUN: llvm-readelf -h %t-lp64d | FileCheck --check-prefixes=READELF-LP64,READELF-DOUBLE-V1 --match-full-lines %s -# READOBJ-ILP32F: Flags [ (0x6) -# READOBJ-ILP32F-NEXT: EF_LOONGARCH_BASE_ABI_ILP32F (0x6) -# READOBJ-ILP32F-NEXT: ] +# RUN: yaml2obj %s -o %t-ilp32s -DCLASS=32 -DABI_MODIFIER=SOFT -DOBJABI_VER=1 +# RUN: llvm-readobj -h %t-ilp32s | FileCheck --check-prefixes=READOBJ-ILP32,READOBJ-SOFT-V1 %s +# RUN: llvm-readelf -h %t-ilp32s | FileCheck --check-prefixes=READELF-ILP32,READELF-SOFT-V1 --match-full-lines %s -# READOBJ-ILP32D: Flags [ (0x7) -# READOBJ-ILP32D-NEXT: EF_LOONGARCH_BASE_ABI_ILP32D (0x7) -# READOBJ-ILP32D-NEXT: ] +# RUN: yaml2obj %s -o %t-ilp32f -DCLASS=32 -DABI_MODIFIER=SINGLE -DOBJABI_VER=1 +# RUN: llvm-readobj -h %t-ilp32f | FileCheck --check-prefixes=READOBJ-ILP32,READOBJ-SINGLE-V1 %s +# RUN: llvm-readelf -h %t-ilp32f | FileCheck --check-prefixes=READELF-ILP32,READELF-SINGLE-V1 --match-full-lines %s -# READELF-LP64S: Flags: 0x1, LP64, SOFT-FLOAT -# READELF-LP64F: Flags: 0x2, LP64, SINGLE-FLOAT -# READELF-LP64D: Flags: 0x3, LP64, DOUBLE-FLOAT -# READELF-ILP32S: Flags: 0x5, ILP32, SOFT-FLOAT -# READELF-ILP32F: Flags: 0x6, ILP32, SINGLE-FLOAT -# READELF-ILP32D: Flags: 0x7, ILP32, DOUBLE-FLOAT +# RUN: yaml2obj %s -o %t-ilp32d -DCLASS=32 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=1 +# RUN: llvm-readobj -h %t-ilp32d | FileCheck --check-prefixes=READOBJ-ILP32,READOBJ-DOUBLE-V1 %s +# RUN: llvm-readelf -h %t-ilp32d | FileCheck --check-prefixes=READELF-ILP32,READELF-DOUBLE-V1 --match-full-lines %s + +# READOBJ-LP64: Class: 64-bit (0x2) +# READELF-LP64: Class: ELF64 +# READOBJ-ILP32: Class: 32-bit (0x1) +# READELF-ILP32: Class: ELF32 + +# READOBJ-SOFT-V0: Flags [ (0x1) +# READOBJ-SOFT-V0-NEXT: EF_LOONGARCH_ABI_SOFT_FLOAT (0x1) +# READOBJ-SOFT-V0-NEXT: ] + +# READOBJ-SINGLE-V0: Flags [ (0x2) +# READOBJ-SINGLE-V0-NEXT: EF_LOONGARCH_ABI_SINGLE_FLOAT (0x2) +# READOBJ-SINGLE-V0-NEXT: ] + +# READOBJ-DOUBLE-V0: Flags [ (0x3) +# READOBJ-DOUBLE-V0-NEXT: EF_LOONGARCH_ABI_DOUBLE_FLOAT (0x3) +# READOBJ-DOUBLE-V0-NEXT: ] + +# READOBJ-SOFT-V1: Flags [ (0x41) +# READOBJ-SOFT-V1-NEXT: EF_LOONGARCH_ABI_SOFT_FLOAT (0x1) +# READOBJ-SOFT-V1-NEXT: EF_LOONGARCH_OBJABI_V1 (0x40) +# READOBJ-SOFT-V1-NEXT: ] + +# READOBJ-SINGLE-V1: Flags [ (0x42) +# READOBJ-SINGLE-V1-NEXT: EF_LOONGARCH_ABI_SINGLE_FLOAT (0x2) +# READOBJ-SINGLE-V1-NEXT: EF_LOONGARCH_OBJABI_V1 (0x40) +# READOBJ-SINGLE-V1-NEXT: ] + +# READOBJ-DOUBLE-V1: Flags [ (0x43) +# READOBJ-DOUBLE-V1-NEXT: EF_LOONGARCH_ABI_DOUBLE_FLOAT (0x3) +# READOBJ-DOUBLE-V1-NEXT: EF_LOONGARCH_OBJABI_V1 (0x40) +# READOBJ-DOUBLE-V1-NEXT: ] + +# READELF-SOFT-V0: Flags: 0x1, SOFT-FLOAT +# READELF-SINGLE-V0: Flags: 0x2, SINGLE-FLOAT +# READELF-DOUBLE-V0: Flags: 0x3, DOUBLE-FLOAT +# READELF-SOFT-V1: Flags: 0x41, SOFT-FLOAT, OBJ-v1 +# READELF-SINGLE-V1: Flags: 0x42, SINGLE-FLOAT, OBJ-v1 +# READELF-DOUBLE-V1: Flags: 0x43, DOUBLE-FLOAT, OBJ-v1 --- !ELF FileHeader: @@ -61,4 +97,7 @@ Data: ELFDATA2LSB Type: ET_EXEC Machine: EM_LOONGARCH - Flags: [ EF_LOONGARCH_BASE_ABI_[[FLAG]] ] + Flags: [ + EF_LOONGARCH_ABI_[[ABI_MODIFIER]]_FLOAT, + EF_LOONGARCH_OBJABI_V[[OBJABI_VER]], + ] diff --git a/llvm/test/tools/obj2yaml/ELF/loongarch-eflags.yaml b/llvm/test/tools/obj2yaml/ELF/loongarch-eflags.yaml --- a/llvm/test/tools/obj2yaml/ELF/loongarch-eflags.yaml +++ b/llvm/test/tools/obj2yaml/ELF/loongarch-eflags.yaml @@ -1,24 +1,43 @@ ## Check obj2yaml is able to decode all possible LoongArch e_flags field values. -# RUN: yaml2obj %s -o %t-lp64s -DCLASS=64 -DFLAG=LP64S -# RUN: obj2yaml %t-lp64s | FileCheck -DFLAG=LP64S %s +# RUN: yaml2obj %s -o %t-lp64s -DCLASS=64 -DABI_MODIFIER=SOFT -DOBJABI_VER=0 +# RUN: obj2yaml %t-lp64s | FileCheck -DCLASS=64 -DABI_MODIFIER=SOFT -DOBJABI_VER=0 %s -# RUN: yaml2obj %s -o %t-lp64f -DCLASS=64 -DFLAG=LP64F -# RUN: obj2yaml %t-lp64f | FileCheck -DFLAG=LP64F %s +# RUN: yaml2obj %s -o %t-lp64f -DCLASS=64 -DABI_MODIFIER=SINGLE -DOBJABI_VER=0 +# RUN: obj2yaml %t-lp64f | FileCheck -DCLASS=64 -DABI_MODIFIER=SINGLE -DOBJABI_VER=0 %s -# RUN: yaml2obj %s -o %t-lp64d -DCLASS=64 -DFLAG=LP64D -# RUN: obj2yaml %t-lp64d | FileCheck -DFLAG=LP64D %s +# RUN: yaml2obj %s -o %t-lp64d -DCLASS=64 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=0 +# RUN: obj2yaml %t-lp64d | FileCheck -DCLASS=64 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=0 %s -# RUN: yaml2obj %s -o %t-ilp32s -DCLASS=32 -DFLAG=ILP32S -# RUN: obj2yaml %t-ilp32s | FileCheck -DFLAG=ILP32S %s +# RUN: yaml2obj %s -o %t-ilp32s -DCLASS=32 -DABI_MODIFIER=SOFT -DOBJABI_VER=0 +# RUN: obj2yaml %t-ilp32s | FileCheck -DCLASS=32 -DABI_MODIFIER=SOFT -DOBJABI_VER=0 %s -# RUN: yaml2obj %s -o %t-ilp32f -DCLASS=32 -DFLAG=ILP32F -# RUN: obj2yaml %t-ilp32f | FileCheck -DFLAG=ILP32F %s +# RUN: yaml2obj %s -o %t-ilp32f -DCLASS=32 -DABI_MODIFIER=SINGLE -DOBJABI_VER=0 +# RUN: obj2yaml %t-ilp32f | FileCheck -DCLASS=32 -DABI_MODIFIER=SINGLE -DOBJABI_VER=0 %s -# RUN: yaml2obj %s -o %t-ilp32d -DCLASS=32 -DFLAG=ILP32D -# RUN: obj2yaml %t-ilp32d | FileCheck -DFLAG=ILP32D %s +# RUN: yaml2obj %s -o %t-ilp32d -DCLASS=32 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=0 +# RUN: obj2yaml %t-ilp32d | FileCheck -DCLASS=32 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=0 %s -# CHECK: Flags: [ EF_LOONGARCH_BASE_ABI_[[FLAG]] ] +# RUN: yaml2obj %s -o %t-lp64s -DCLASS=64 -DABI_MODIFIER=SOFT -DOBJABI_VER=1 +# RUN: obj2yaml %t-lp64s | FileCheck -DCLASS=64 -DABI_MODIFIER=SOFT -DOBJABI_VER=1 %s + +# RUN: yaml2obj %s -o %t-lp64f -DCLASS=64 -DABI_MODIFIER=SINGLE -DOBJABI_VER=1 +# RUN: obj2yaml %t-lp64f | FileCheck -DCLASS=64 -DABI_MODIFIER=SINGLE -DOBJABI_VER=1 %s + +# RUN: yaml2obj %s -o %t-lp64d -DCLASS=64 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=1 +# RUN: obj2yaml %t-lp64d | FileCheck -DCLASS=64 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=1 %s + +# RUN: yaml2obj %s -o %t-ilp32s -DCLASS=32 -DABI_MODIFIER=SOFT -DOBJABI_VER=1 +# RUN: obj2yaml %t-ilp32s | FileCheck -DCLASS=32 -DABI_MODIFIER=SOFT -DOBJABI_VER=1 %s + +# RUN: yaml2obj %s -o %t-ilp32f -DCLASS=32 -DABI_MODIFIER=SINGLE -DOBJABI_VER=1 +# RUN: obj2yaml %t-ilp32f | FileCheck -DCLASS=32 -DABI_MODIFIER=SINGLE -DOBJABI_VER=1 %s + +# RUN: yaml2obj %s -o %t-ilp32d -DCLASS=32 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=1 +# RUN: obj2yaml %t-ilp32d | FileCheck -DCLASS=32 -DABI_MODIFIER=DOUBLE -DOBJABI_VER=1 %s + +# CHECK: Class: ELFCLASS[[CLASS]] +# CHECK: Flags: [ EF_LOONGARCH_ABI_[[ABI_MODIFIER]]_FLOAT, EF_LOONGARCH_OBJABI_V[[OBJABI_VER]] ] --- !ELF FileHeader: @@ -26,4 +45,7 @@ Data: ELFDATA2LSB Type: ET_EXEC Machine: EM_LOONGARCH - Flags: [ EF_LOONGARCH_BASE_ABI_[[FLAG]] ] + Flags: [ + EF_LOONGARCH_ABI_[[ABI_MODIFIER]]_FLOAT, + EF_LOONGARCH_OBJABI_V[[OBJABI_VER]], + ] diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -1649,12 +1649,11 @@ }; const EnumEntry ElfHeaderLoongArchFlags[] = { - ENUM_ENT(EF_LOONGARCH_BASE_ABI_ILP32S, "ILP32, SOFT-FLOAT"), - ENUM_ENT(EF_LOONGARCH_BASE_ABI_ILP32F, "ILP32, SINGLE-FLOAT"), - ENUM_ENT(EF_LOONGARCH_BASE_ABI_ILP32D, "ILP32, DOUBLE-FLOAT"), - ENUM_ENT(EF_LOONGARCH_BASE_ABI_LP64S, "LP64, SOFT-FLOAT"), - ENUM_ENT(EF_LOONGARCH_BASE_ABI_LP64F, "LP64, SINGLE-FLOAT"), - ENUM_ENT(EF_LOONGARCH_BASE_ABI_LP64D, "LP64, DOUBLE-FLOAT"), + ENUM_ENT(EF_LOONGARCH_ABI_SOFT_FLOAT, "SOFT-FLOAT"), + ENUM_ENT(EF_LOONGARCH_ABI_SINGLE_FLOAT, "SINGLE-FLOAT"), + ENUM_ENT(EF_LOONGARCH_ABI_DOUBLE_FLOAT, "DOUBLE-FLOAT"), + ENUM_ENT(EF_LOONGARCH_OBJABI_V0, "OBJ-v0"), + ENUM_ENT(EF_LOONGARCH_OBJABI_V1, "OBJ-v1"), }; @@ -3368,7 +3367,8 @@ unsigned(ELF::EF_AVR_ARCH_MASK)); else if (e.e_machine == EM_LOONGARCH) ElfFlags = printFlags(e.e_flags, makeArrayRef(ElfHeaderLoongArchFlags), - unsigned(ELF::EF_LOONGARCH_BASE_ABI_MASK)); + unsigned(ELF::EF_LOONGARCH_ABI_MODIFIER_MASK), + unsigned(ELF::EF_LOONGARCH_OBJABI_MASK)); Str = "0x" + utohexstr(e.e_flags); if (!ElfFlags.empty()) Str = Str + ", " + ElfFlags; @@ -6546,7 +6546,8 @@ unsigned(ELF::EF_AVR_ARCH_MASK)); else if (E.e_machine == EM_LOONGARCH) W.printFlags("Flags", E.e_flags, makeArrayRef(ElfHeaderLoongArchFlags), - unsigned(ELF::EF_LOONGARCH_BASE_ABI_MASK)); + unsigned(ELF::EF_LOONGARCH_ABI_MODIFIER_MASK), + unsigned(ELF::EF_LOONGARCH_OBJABI_MASK)); else W.printFlags("Flags", E.e_flags); W.printNumber("HeaderSize", E.e_ehsize);