forked from OSchip/llvm-project
[ELF][PPC64] Rename some PPC64 ELFv2 specific RelExpr from R_PPC_* to R_PPC64_*
The following abstract relocation types (RelExpr) are PPC64 ELFv2 ABI specific, not used by PPC32. So rename them to prevent confusion when the PPC32 port is improved. * R_PPC_CALL R_PPC_CALL_PLT: R_PPC_CALL_PLT represents R_PPC64_REL14 and R_PPC64_REL24. If the function is not preemptable, R_PPC_CALL_PLT can be optimized to R_PPC_CALL: the formula adjusts the symbol VA from the global entry point to the local entry point. * R_PPC_TOC: represents R_PPC64_TOC. We don't have a test. Add one to ppc64-relocs.s Rename it to R_PPC64_TOCBASE because `@tocbase` is the assembly form. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D62800 llvm-svn: 362359
This commit is contained in:
parent
ea0c66be55
commit
8522d579b8
|
@ -545,10 +545,10 @@ RelExpr PPC64::getRelExpr(RelType Type, const Symbol &S,
|
||||||
case R_PPC64_TOC16_LO_DS:
|
case R_PPC64_TOC16_LO_DS:
|
||||||
return Config->TocOptimize ? R_PPC64_RELAX_TOC : R_GOTREL;
|
return Config->TocOptimize ? R_PPC64_RELAX_TOC : R_GOTREL;
|
||||||
case R_PPC64_TOC:
|
case R_PPC64_TOC:
|
||||||
return R_PPC_TOC;
|
return R_PPC64_TOCBASE;
|
||||||
case R_PPC64_REL14:
|
case R_PPC64_REL14:
|
||||||
case R_PPC64_REL24:
|
case R_PPC64_REL24:
|
||||||
return R_PPC_CALL_PLT;
|
return R_PPC64_CALL_PLT;
|
||||||
case R_PPC64_REL16_LO:
|
case R_PPC64_REL16_LO:
|
||||||
case R_PPC64_REL16_HA:
|
case R_PPC64_REL16_HA:
|
||||||
case R_PPC64_REL32:
|
case R_PPC64_REL32:
|
||||||
|
|
|
@ -717,9 +717,9 @@ static uint64_t getRelocTargetVA(const InputFile *File, RelType Type, int64_t A,
|
||||||
case R_PLT:
|
case R_PLT:
|
||||||
return Sym.getPltVA() + A;
|
return Sym.getPltVA() + A;
|
||||||
case R_PLT_PC:
|
case R_PLT_PC:
|
||||||
case R_PPC_CALL_PLT:
|
case R_PPC64_CALL_PLT:
|
||||||
return Sym.getPltVA() + A - P;
|
return Sym.getPltVA() + A - P;
|
||||||
case R_PPC_CALL: {
|
case R_PPC64_CALL: {
|
||||||
uint64_t SymVA = Sym.getVA(A);
|
uint64_t SymVA = Sym.getVA(A);
|
||||||
// If we have an undefined weak symbol, we might get here with a symbol
|
// 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,
|
// address of zero. That could overflow, but the code must be unreachable,
|
||||||
|
@ -735,7 +735,7 @@ static uint64_t getRelocTargetVA(const InputFile *File, RelType Type, int64_t A,
|
||||||
// branching to the local entry point.
|
// branching to the local entry point.
|
||||||
return SymVA - P + getPPC64GlobalEntryToLocalEntryOffset(Sym.StOther);
|
return SymVA - P + getPPC64GlobalEntryToLocalEntryOffset(Sym.StOther);
|
||||||
}
|
}
|
||||||
case R_PPC_TOC:
|
case R_PPC64_TOCBASE:
|
||||||
return getPPC64TocBase() + A;
|
return getPPC64TocBase() + A;
|
||||||
case R_RELAX_GOT_PC:
|
case R_RELAX_GOT_PC:
|
||||||
return Sym.getVA(A) - P;
|
return Sym.getVA(A) - P;
|
||||||
|
@ -922,7 +922,7 @@ void InputSectionBase::relocateAlloc(uint8_t *Buf, uint8_t *BufEnd) {
|
||||||
case R_RELAX_TLS_GD_TO_IE_GOTPLT:
|
case R_RELAX_TLS_GD_TO_IE_GOTPLT:
|
||||||
Target->relaxTlsGdToIe(BufLoc, Type, TargetVA);
|
Target->relaxTlsGdToIe(BufLoc, Type, TargetVA);
|
||||||
break;
|
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
|
// 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
|
// sequence that has been relaxed and turned into a nop. In this
|
||||||
// case, we don't want to handle it as a call.
|
// case, we don't want to handle it as a call.
|
||||||
|
|
|
@ -363,7 +363,7 @@ static bool isAbsoluteValue(const Symbol &Sym) {
|
||||||
|
|
||||||
// Returns true if Expr refers a PLT entry.
|
// Returns true if Expr refers a PLT entry.
|
||||||
static bool needsPlt(RelExpr Expr) {
|
static bool needsPlt(RelExpr Expr) {
|
||||||
return oneof<R_PLT_PC, R_PPC_CALL_PLT, R_PLT>(Expr);
|
return oneof<R_PLT_PC, R_PPC64_CALL_PLT, R_PLT>(Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if Expr refers a GOT entry. Note that this function
|
// Returns true if Expr refers a GOT entry. Note that this function
|
||||||
|
@ -378,8 +378,9 @@ static bool needsGot(RelExpr Expr) {
|
||||||
// True if this expression is of the form Sym - X, where X is a position in the
|
// True if this expression is of the form Sym - X, where X is a position in the
|
||||||
// file (PC, or GOT for example).
|
// file (PC, or GOT for example).
|
||||||
static bool isRelExpr(RelExpr Expr) {
|
static bool isRelExpr(RelExpr Expr) {
|
||||||
return oneof<R_PC, R_GOTREL, R_GOTPLTREL, R_MIPS_GOTREL, R_PPC_CALL,
|
return oneof<R_PC, R_GOTREL, R_GOTPLTREL, R_MIPS_GOTREL, R_PPC64_CALL,
|
||||||
R_PPC64_RELAX_TOC, R_PPC_CALL_PLT, R_AARCH64_PAGE_PC, R_RELAX_GOT_PC>(Expr);
|
R_PPC64_CALL_PLT, R_PPC64_RELAX_TOC, R_AARCH64_PAGE_PC,
|
||||||
|
R_RELAX_GOT_PC>(Expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if a given relocation can be computed at link-time.
|
// Returns true if a given relocation can be computed at link-time.
|
||||||
|
@ -398,7 +399,7 @@ static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, const Symbol &Sym,
|
||||||
R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOTREL, R_MIPS_GOT_OFF,
|
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_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_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_PPC64_RELAX_TOC, R_TLSDESC_CALL, R_TLSDESC_PC,
|
||||||
R_AARCH64_TLSDESC_PAGE, R_HINT, R_TLSLD_HINT, R_TLSIE_HINT>(E))
|
R_AARCH64_TLSDESC_PAGE, R_HINT, R_TLSLD_HINT, R_TLSIE_HINT>(E))
|
||||||
return true;
|
return true;
|
||||||
|
@ -452,8 +453,8 @@ static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, const Symbol &Sym,
|
||||||
|
|
||||||
static RelExpr toPlt(RelExpr Expr) {
|
static RelExpr toPlt(RelExpr Expr) {
|
||||||
switch (Expr) {
|
switch (Expr) {
|
||||||
case R_PPC_CALL:
|
case R_PPC64_CALL:
|
||||||
return R_PPC_CALL_PLT;
|
return R_PPC64_CALL_PLT;
|
||||||
case R_PC:
|
case R_PC:
|
||||||
return R_PLT_PC;
|
return R_PLT_PC;
|
||||||
case R_ABS:
|
case R_ABS:
|
||||||
|
@ -469,8 +470,8 @@ static RelExpr fromPlt(RelExpr Expr) {
|
||||||
switch (Expr) {
|
switch (Expr) {
|
||||||
case R_PLT_PC:
|
case R_PLT_PC:
|
||||||
return R_PC;
|
return R_PC;
|
||||||
case R_PPC_CALL_PLT:
|
case R_PPC64_CALL_PLT:
|
||||||
return R_PPC_CALL;
|
return R_PPC64_CALL;
|
||||||
case R_PLT:
|
case R_PLT:
|
||||||
return R_ABS;
|
return R_ABS;
|
||||||
default:
|
default:
|
||||||
|
@ -1125,7 +1126,8 @@ static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I,
|
||||||
// The 4 types that relative GOTPLT are all x86 and x86-64 specific.
|
// The 4 types that relative GOTPLT are all x86 and x86-64 specific.
|
||||||
if (oneof<R_GOTPLTONLY_PC, R_GOTPLTREL, R_GOTPLT, R_TLSGD_GOTPLT>(Expr)) {
|
if (oneof<R_GOTPLTONLY_PC, R_GOTPLTREL, R_GOTPLT, R_TLSGD_GOTPLT>(Expr)) {
|
||||||
In.GotPlt->HasGotPltOffRel = true;
|
In.GotPlt->HasGotPltOffRel = true;
|
||||||
} else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC_TOC, R_PPC64_RELAX_TOC>(Expr)) {
|
} else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC64_TOCBASE, R_PPC64_RELAX_TOC>(
|
||||||
|
Expr)) {
|
||||||
In.Got->HasGotOffRel = true;
|
In.Got->HasGotOffRel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,10 +91,10 @@ enum RelExpr {
|
||||||
R_MIPS_GOT_OFF32,
|
R_MIPS_GOT_OFF32,
|
||||||
R_MIPS_TLSGD,
|
R_MIPS_TLSGD,
|
||||||
R_MIPS_TLSLD,
|
R_MIPS_TLSLD,
|
||||||
R_PPC_CALL,
|
R_PPC64_CALL,
|
||||||
R_PPC_CALL_PLT,
|
R_PPC64_CALL_PLT,
|
||||||
R_PPC_TOC,
|
|
||||||
R_PPC64_RELAX_TOC,
|
R_PPC64_RELAX_TOC,
|
||||||
|
R_PPC64_TOCBASE,
|
||||||
R_RISCV_PC_INDIRECT,
|
R_RISCV_PC_INDIRECT,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
|
# RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
|
||||||
# RUN: ld.lld --no-toc-optimize %t.o -o %t
|
# 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-objdump -d --no-show-raw-insn %t | FileCheck %s
|
||||||
|
|
||||||
# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
|
# RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
|
||||||
# RUN: ld.lld --no-toc-optimize %t.o -o %t
|
# 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
|
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
|
||||||
|
|
||||||
.text
|
.text
|
||||||
|
@ -139,14 +139,26 @@ _start:
|
||||||
__foo:
|
__foo:
|
||||||
li 3,0
|
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
|
# Check that the personality (relocated by R_PPC64_REL64) in the .eh_frame
|
||||||
# equals the address of __foo.
|
# equals the address of __foo.
|
||||||
# 0x100001e2 + 0x76fe = 0x10010058
|
# 0x100001ea + 0xfe6e = 0x10010058
|
||||||
# DATALE: section '.eh_frame':
|
# DATALE: section '.eh_frame':
|
||||||
# DATALE: 0x100001e0 {{....}}76fe
|
# DATALE: 0x100001e8 {{....}}6efe
|
||||||
|
|
||||||
# DATABE: section '.eh_frame':
|
# 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: __foo
|
||||||
# CHECK-NEXT: 10010058: li 3, 0
|
# CHECK-NEXT: 10010058: li 3, 0
|
||||||
|
|
Loading…
Reference in New Issue