diff --git a/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def b/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def --- a/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def +++ b/llvm/include/llvm/BinaryFormat/ELFRelocs/LoongArch.def @@ -60,3 +60,45 @@ ELF_RELOC(R_LARCH_SUB64, 56) ELF_RELOC(R_LARCH_GNU_VTINHERIT, 57) ELF_RELOC(R_LARCH_GNU_VTENTRY, 58) + +// And finally, the new-style relocs whose processing do not require a stack +// machine. +// +// Spec addition: https://github.com/loongson/LoongArch-Documentation/pull/57 +// Binutils commit 6d13722a97cee3fd397e116bde3bcedbb1e220be +ELF_RELOC(R_LARCH_B16, 64) +ELF_RELOC(R_LARCH_B21, 65) +ELF_RELOC(R_LARCH_B26, 66) +ELF_RELOC(R_LARCH_ABS_HI20, 67) +ELF_RELOC(R_LARCH_ABS_LO12, 68) +ELF_RELOC(R_LARCH_ABS64_LO20, 69) +ELF_RELOC(R_LARCH_ABS64_HI12, 70) +ELF_RELOC(R_LARCH_PCALA_HI20, 71) +ELF_RELOC(R_LARCH_PCALA_LO12, 72) +ELF_RELOC(R_LARCH_PCALA64_LO20, 73) +ELF_RELOC(R_LARCH_PCALA64_HI12, 74) +ELF_RELOC(R_LARCH_GOT_PC_HI20, 75) +ELF_RELOC(R_LARCH_GOT_PC_LO12, 76) +ELF_RELOC(R_LARCH_GOT64_PC_LO20, 77) +ELF_RELOC(R_LARCH_GOT64_PC_HI12, 78) +ELF_RELOC(R_LARCH_GOT_HI20, 79) +ELF_RELOC(R_LARCH_GOT_LO12, 80) +ELF_RELOC(R_LARCH_GOT64_LO20, 81) +ELF_RELOC(R_LARCH_GOT64_HI12, 82) +ELF_RELOC(R_LARCH_TLS_LE_HI20, 83) +ELF_RELOC(R_LARCH_TLS_LE_LO12, 84) +ELF_RELOC(R_LARCH_TLS_LE64_LO20, 85) +ELF_RELOC(R_LARCH_TLS_LE64_HI12, 86) +ELF_RELOC(R_LARCH_TLS_IE_PC_HI20, 87) +ELF_RELOC(R_LARCH_TLS_IE_PC_LO12, 88) +ELF_RELOC(R_LARCH_TLS_IE64_PC_LO20, 89) +ELF_RELOC(R_LARCH_TLS_IE64_PC_HI12, 90) +ELF_RELOC(R_LARCH_TLS_IE_HI20, 91) +ELF_RELOC(R_LARCH_TLS_IE_LO12, 92) +ELF_RELOC(R_LARCH_TLS_IE64_LO20, 93) +ELF_RELOC(R_LARCH_TLS_IE64_HI12, 94) +ELF_RELOC(R_LARCH_TLS_LD_PC_HI20, 95) +ELF_RELOC(R_LARCH_TLS_LD_HI20, 96) +ELF_RELOC(R_LARCH_TLS_GD_PC_HI20, 97) +ELF_RELOC(R_LARCH_TLS_GD_HI20, 98) +ELF_RELOC(R_LARCH_RELAX, 99) diff --git a/llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test b/llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test --- a/llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test +++ b/llvm/test/tools/llvm-readobj/ELF/reloc-types-loongarch64.test @@ -56,6 +56,42 @@ # CHECK: Type: R_LARCH_SUB64 (56) # CHECK: Type: R_LARCH_GNU_VTINHERIT (57) # CHECK: Type: R_LARCH_GNU_VTENTRY (58) +# CHECK: Type: R_LARCH_B16 (64) +# CHECK: Type: R_LARCH_B21 (65) +# CHECK: Type: R_LARCH_B26 (66) +# CHECK: Type: R_LARCH_ABS_HI20 (67) +# CHECK: Type: R_LARCH_ABS_LO12 (68) +# CHECK: Type: R_LARCH_ABS64_LO20 (69) +# CHECK: Type: R_LARCH_ABS64_HI12 (70) +# CHECK: Type: R_LARCH_PCALA_HI20 (71) +# CHECK: Type: R_LARCH_PCALA_LO12 (72) +# CHECK: Type: R_LARCH_PCALA64_LO20 (73) +# CHECK: Type: R_LARCH_PCALA64_HI12 (74) +# CHECK: Type: R_LARCH_GOT_PC_HI20 (75) +# CHECK: Type: R_LARCH_GOT_PC_LO12 (76) +# CHECK: Type: R_LARCH_GOT64_PC_LO20 (77) +# CHECK: Type: R_LARCH_GOT64_PC_HI12 (78) +# CHECK: Type: R_LARCH_GOT_HI20 (79) +# CHECK: Type: R_LARCH_GOT_LO12 (80) +# CHECK: Type: R_LARCH_GOT64_LO20 (81) +# CHECK: Type: R_LARCH_GOT64_HI12 (82) +# CHECK: Type: R_LARCH_TLS_LE_HI20 (83) +# CHECK: Type: R_LARCH_TLS_LE_LO12 (84) +# CHECK: Type: R_LARCH_TLS_LE64_LO20 (85) +# CHECK: Type: R_LARCH_TLS_LE64_HI12 (86) +# CHECK: Type: R_LARCH_TLS_IE_PC_HI20 (87) +# CHECK: Type: R_LARCH_TLS_IE_PC_LO12 (88) +# CHECK: Type: R_LARCH_TLS_IE64_PC_LO20 (89) +# CHECK: Type: R_LARCH_TLS_IE64_PC_HI12 (90) +# CHECK: Type: R_LARCH_TLS_IE_HI20 (91) +# CHECK: Type: R_LARCH_TLS_IE_LO12 (92) +# CHECK: Type: R_LARCH_TLS_IE64_LO20 (93) +# CHECK: Type: R_LARCH_TLS_IE64_HI12 (94) +# CHECK: Type: R_LARCH_TLS_LD_PC_HI20 (95) +# CHECK: Type: R_LARCH_TLS_LD_HI20 (96) +# CHECK: Type: R_LARCH_TLS_GD_PC_HI20 (97) +# CHECK: Type: R_LARCH_TLS_GD_HI20 (98) +# CHECK: Type: R_LARCH_RELAX (99) --- !ELF FileHeader: @@ -119,3 +155,39 @@ - Type: R_LARCH_SUB64 - Type: R_LARCH_GNU_VTINHERIT - Type: R_LARCH_GNU_VTENTRY + - Type: R_LARCH_B16 + - Type: R_LARCH_B21 + - Type: R_LARCH_B26 + - Type: R_LARCH_ABS_HI20 + - Type: R_LARCH_ABS_LO12 + - Type: R_LARCH_ABS64_LO20 + - Type: R_LARCH_ABS64_HI12 + - Type: R_LARCH_PCALA_HI20 + - Type: R_LARCH_PCALA_LO12 + - Type: R_LARCH_PCALA64_LO20 + - Type: R_LARCH_PCALA64_HI12 + - Type: R_LARCH_GOT_PC_HI20 + - Type: R_LARCH_GOT_PC_LO12 + - Type: R_LARCH_GOT64_PC_LO20 + - Type: R_LARCH_GOT64_PC_HI12 + - Type: R_LARCH_GOT_HI20 + - Type: R_LARCH_GOT_LO12 + - Type: R_LARCH_GOT64_LO20 + - Type: R_LARCH_GOT64_HI12 + - Type: R_LARCH_TLS_LE_HI20 + - Type: R_LARCH_TLS_LE_LO12 + - Type: R_LARCH_TLS_LE64_LO20 + - Type: R_LARCH_TLS_LE64_HI12 + - Type: R_LARCH_TLS_IE_PC_HI20 + - Type: R_LARCH_TLS_IE_PC_LO12 + - Type: R_LARCH_TLS_IE64_PC_LO20 + - Type: R_LARCH_TLS_IE64_PC_HI12 + - Type: R_LARCH_TLS_IE_HI20 + - Type: R_LARCH_TLS_IE_LO12 + - Type: R_LARCH_TLS_IE64_LO20 + - Type: R_LARCH_TLS_IE64_HI12 + - Type: R_LARCH_TLS_LD_PC_HI20 + - Type: R_LARCH_TLS_LD_HI20 + - Type: R_LARCH_TLS_GD_PC_HI20 + - Type: R_LARCH_TLS_GD_HI20 + - Type: R_LARCH_RELAX diff --git a/llvm/unittests/Object/ELFTest.cpp b/llvm/unittests/Object/ELFTest.cpp --- a/llvm/unittests/Object/ELFTest.cpp +++ b/llvm/unittests/Object/ELFTest.cpp @@ -159,6 +159,78 @@ getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_GNU_VTINHERIT)); EXPECT_EQ("R_LARCH_GNU_VTENTRY", getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_GNU_VTENTRY)); + EXPECT_EQ("R_LARCH_B16", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_B16)); + EXPECT_EQ("R_LARCH_B21", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_B21)); + EXPECT_EQ("R_LARCH_B26", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_B26)); + EXPECT_EQ("R_LARCH_ABS_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_ABS_HI20)); + EXPECT_EQ("R_LARCH_ABS_LO12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_ABS_LO12)); + EXPECT_EQ("R_LARCH_ABS64_LO20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_ABS64_LO20)); + EXPECT_EQ("R_LARCH_ABS64_HI12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_ABS64_HI12)); + EXPECT_EQ("R_LARCH_PCALA_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_PCALA_HI20)); + EXPECT_EQ("R_LARCH_PCALA_LO12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_PCALA_LO12)); + EXPECT_EQ("R_LARCH_PCALA64_LO20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_PCALA64_LO20)); + EXPECT_EQ("R_LARCH_PCALA64_HI12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_PCALA64_HI12)); + EXPECT_EQ("R_LARCH_GOT_PC_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_GOT_PC_HI20)); + EXPECT_EQ("R_LARCH_GOT_PC_LO12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_GOT_PC_LO12)); + EXPECT_EQ("R_LARCH_GOT64_PC_LO20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_GOT64_PC_LO20)); + EXPECT_EQ("R_LARCH_GOT64_PC_HI12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_GOT64_PC_HI12)); + EXPECT_EQ("R_LARCH_GOT_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_GOT_HI20)); + EXPECT_EQ("R_LARCH_GOT_LO12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_GOT_LO12)); + EXPECT_EQ("R_LARCH_GOT64_LO20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_GOT64_LO20)); + EXPECT_EQ("R_LARCH_GOT64_HI12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_GOT64_HI12)); + EXPECT_EQ("R_LARCH_TLS_LE_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_LE_HI20)); + EXPECT_EQ("R_LARCH_TLS_LE_LO12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_LE_LO12)); + EXPECT_EQ("R_LARCH_TLS_LE64_LO20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_LE64_LO20)); + EXPECT_EQ("R_LARCH_TLS_LE64_HI12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_LE64_HI12)); + EXPECT_EQ("R_LARCH_TLS_IE_PC_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_IE_PC_HI20)); + EXPECT_EQ("R_LARCH_TLS_IE_PC_LO12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_IE_PC_LO12)); + EXPECT_EQ("R_LARCH_TLS_IE64_PC_LO20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_IE64_PC_LO20)); + EXPECT_EQ("R_LARCH_TLS_IE64_PC_HI12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_IE64_PC_HI12)); + EXPECT_EQ("R_LARCH_TLS_IE_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_IE_HI20)); + EXPECT_EQ("R_LARCH_TLS_IE_LO12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_IE_LO12)); + EXPECT_EQ("R_LARCH_TLS_IE64_LO20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_IE64_LO20)); + EXPECT_EQ("R_LARCH_TLS_IE64_HI12", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_IE64_HI12)); + EXPECT_EQ("R_LARCH_TLS_LD_PC_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_LD_PC_HI20)); + EXPECT_EQ("R_LARCH_TLS_LD_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_LD_HI20)); + EXPECT_EQ("R_LARCH_TLS_GD_PC_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_GD_PC_HI20)); + EXPECT_EQ("R_LARCH_TLS_GD_HI20", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_TLS_GD_HI20)); + EXPECT_EQ("R_LARCH_RELAX", + getELFRelocationTypeName(EM_LOONGARCH, R_LARCH_RELAX)); } TEST(ELFTest, getELFRelativeRelocationType) {