Index: lld/trunk/ELF/Arch/PPC64.cpp =================================================================== --- lld/trunk/ELF/Arch/PPC64.cpp +++ lld/trunk/ELF/Arch/PPC64.cpp @@ -545,10 +545,10 @@ case R_PPC64_TOC16_LO_DS: return Config->TocOptimize ? R_PPC64_RELAX_TOC : R_GOTREL; case R_PPC64_TOC: - return R_PPC_TOC; + return R_PPC64_TOCBASE; case R_PPC64_REL14: case R_PPC64_REL24: - return R_PPC_CALL_PLT; + return R_PPC64_CALL_PLT; case R_PPC64_REL16_LO: case R_PPC64_REL16_HA: case R_PPC64_REL32: Index: lld/trunk/ELF/InputSection.cpp =================================================================== --- lld/trunk/ELF/InputSection.cpp +++ lld/trunk/ELF/InputSection.cpp @@ -717,9 +717,9 @@ case R_PLT: return Sym.getPltVA() + A; case R_PLT_PC: - case R_PPC_CALL_PLT: + case R_PPC64_CALL_PLT: return Sym.getPltVA() + A - P; - case R_PPC_CALL: { + case R_PPC64_CALL: { uint64_t SymVA = Sym.getVA(A); // If we have an undefined weak symbol, we might get here with a symbol // address of zero. That could overflow, but the code must be unreachable, @@ -735,7 +735,7 @@ // branching to the local entry point. return SymVA - P + getPPC64GlobalEntryToLocalEntryOffset(Sym.StOther); } - case R_PPC_TOC: + case R_PPC64_TOCBASE: return getPPC64TocBase() + A; case R_RELAX_GOT_PC: return Sym.getVA(A) - P; @@ -922,7 +922,7 @@ case R_RELAX_TLS_GD_TO_IE_GOTPLT: Target->relaxTlsGdToIe(BufLoc, Type, TargetVA); break; - case R_PPC_CALL: + case R_PPC64_CALL: // If this is a call to __tls_get_addr, it may be part of a TLS // sequence that has been relaxed and turned into a nop. In this // case, we don't want to handle it as a call. Index: lld/trunk/ELF/Relocations.h =================================================================== --- lld/trunk/ELF/Relocations.h +++ lld/trunk/ELF/Relocations.h @@ -91,10 +91,10 @@ R_MIPS_GOT_OFF32, R_MIPS_TLSGD, R_MIPS_TLSLD, - R_PPC_CALL, - R_PPC_CALL_PLT, - R_PPC_TOC, + R_PPC64_CALL, + R_PPC64_CALL_PLT, R_PPC64_RELAX_TOC, + R_PPC64_TOCBASE, R_RISCV_PC_INDIRECT, }; Index: lld/trunk/ELF/Relocations.cpp =================================================================== --- lld/trunk/ELF/Relocations.cpp +++ lld/trunk/ELF/Relocations.cpp @@ -363,7 +363,7 @@ // Returns true if Expr refers a PLT entry. static bool needsPlt(RelExpr Expr) { - return oneof(Expr); + return oneof(Expr); } // Returns true if Expr refers a GOT entry. Note that this function @@ -378,8 +378,9 @@ // True if this expression is of the form Sym - X, where X is a position in the // file (PC, or GOT for example). static bool isRelExpr(RelExpr Expr) { - return oneof(Expr); + return oneof(Expr); } // Returns true if a given relocation can be computed at link-time. @@ -398,7 +399,7 @@ R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOTREL, R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32, R_MIPS_GOT_GP_PC, R_MIPS_TLSGD, R_AARCH64_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC, R_GOTPLTONLY_PC, - R_PLT_PC, R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC, R_PPC_CALL_PLT, + R_PLT_PC, R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC, R_PPC64_CALL_PLT, R_PPC64_RELAX_TOC, R_TLSDESC_CALL, R_TLSDESC_PC, R_AARCH64_TLSDESC_PAGE, R_HINT, R_TLSLD_HINT, R_TLSIE_HINT>(E)) return true; @@ -452,8 +453,8 @@ static RelExpr toPlt(RelExpr Expr) { switch (Expr) { - case R_PPC_CALL: - return R_PPC_CALL_PLT; + case R_PPC64_CALL: + return R_PPC64_CALL_PLT; case R_PC: return R_PLT_PC; case R_ABS: @@ -469,8 +470,8 @@ switch (Expr) { case R_PLT_PC: return R_PC; - case R_PPC_CALL_PLT: - return R_PPC_CALL; + case R_PPC64_CALL_PLT: + return R_PPC64_CALL; case R_PLT: return R_ABS; default: @@ -1125,7 +1126,8 @@ // The 4 types that relative GOTPLT are all x86 and x86-64 specific. if (oneof(Expr)) { In.GotPlt->HasGotPltOffRel = true; - } else if (oneof(Expr)) { + } else if (oneof( + Expr)) { In.Got->HasGotOffRel = true; } Index: lld/trunk/test/ELF/ppc64-relocs.s =================================================================== --- lld/trunk/test/ELF/ppc64-relocs.s +++ lld/trunk/test/ELF/ppc64-relocs.s @@ -2,12 +2,12 @@ # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o # RUN: ld.lld --no-toc-optimize %t.o -o %t -# RUN: llvm-readelf -x .rodata -x .eh_frame %t | FileCheck %s --check-prefix=DATALE +# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC -x .eh_frame %t | FileCheck %s --check-prefix=DATALE # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o # RUN: ld.lld --no-toc-optimize %t.o -o %t -# RUN: llvm-readelf -x .rodata -x .eh_frame %t | FileCheck %s --check-prefix=DATABE +# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC -x .eh_frame %t | FileCheck %s --check-prefix=DATABE # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s .text @@ -139,14 +139,26 @@ __foo: li 3,0 +.section .R_PPC64_TOC,"a",@progbits + .quad .TOC.@tocbase + +# SEC: .got PROGBITS 0000000010020000 + +## tocbase = .got+0x8000 = 0x10028000 +# DATALE-LABEL: section '.R_PPC64_TOC': +# DATALE: 00800210 00000000 + +# DATABE-LABEL: section '.R_PPC64_TOC': +# DATABE: 00000000 10028000 + # Check that the personality (relocated by R_PPC64_REL64) in the .eh_frame # equals the address of __foo. -# 0x100001e2 + 0x76fe = 0x10010058 +# 0x100001ea + 0xfe6e = 0x10010058 # DATALE: section '.eh_frame': -# DATALE: 0x100001e0 {{....}}76fe +# DATALE: 0x100001e8 {{....}}6efe # DATABE: section '.eh_frame': -# DATABE: 0x100001e0 {{[0-9a-f]+ [0-9a-f]+}} fe76{{....}} +# DATABE: 0x100001e8 {{[0-9a-f]+ [0-9a-f]+}} fe6e{{....}} # CHECK: __foo # CHECK-NEXT: 10010058: li 3, 0