Skip to content

Commit

Permalink
[ELF] Support R_PPC_NONE/R_PPC64_NONE in getImplicitAddend
Browse files Browse the repository at this point in the history
Similar to f457863

(cherry picked from commit 53fc5d9)
  • Loading branch information
MaskRay committed Feb 4, 2022
1 parent 31868be commit ff421be
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lld/ELF/Arch/PPC.cpp
Expand Up @@ -30,6 +30,7 @@ class PPC final : public TargetInfo {
RelExpr getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const override;
RelType getDynRel(RelType type) const override;
int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override;
void writeGotHeader(uint8_t *buf) const override;
void writePltHeader(uint8_t *buf) const override {
llvm_unreachable("should call writePPC32GlinkSection() instead");
Expand Down Expand Up @@ -275,6 +276,17 @@ RelType PPC::getDynRel(RelType type) const {
return R_PPC_NONE;
}

int64_t PPC::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
case R_PPC_NONE:
return 0;
default:
internalLinkerError(getErrorLocation(buf),
"cannot read addend for relocation " + toString(type));
return 0;
}
}

static std::pair<RelType, uint64_t> fromDTPREL(RelType type, uint64_t val) {
uint64_t dtpBiasedVal = val - 0x8000;
switch (type) {
Expand Down
12 changes: 12 additions & 0 deletions lld/ELF/Arch/PPC64.cpp
Expand Up @@ -363,6 +363,7 @@ class PPC64 final : public TargetInfo {
RelExpr getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const override;
RelType getDynRel(RelType type) const override;
int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override;
void writePltHeader(uint8_t *buf) const override;
void writePlt(uint8_t *buf, const Symbol &sym,
uint64_t pltEntryAddr) const override;
Expand Down Expand Up @@ -1059,6 +1060,17 @@ RelType PPC64::getDynRel(RelType type) const {
return R_PPC64_NONE;
}

int64_t PPC64::getImplicitAddend(const uint8_t *buf, RelType type) const {
switch (type) {
case R_PPC64_NONE:
return 0;
default:
internalLinkerError(getErrorLocation(buf),
"cannot read addend for relocation " + toString(type));
return 0;
}
}

void PPC64::writeGotHeader(uint8_t *buf) const {
write64(buf, getPPC64TocBase());
}
Expand Down
8 changes: 8 additions & 0 deletions lld/test/ELF/relocation-none.test
Expand Up @@ -15,6 +15,14 @@
# RUN: ld.lld -r %t.o -o %t
# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s

# RUN: yaml2obj -DBITS=32 -DMACHINE=PPC %s -o %t.o
# RUN: ld.lld -r %t.o -o %t
# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s

# RUN: yaml2obj -DMACHINE=PPC64 %s -o %t.o
# RUN: ld.lld -r %t.o -o %t
# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s

# RUN: yaml2obj -DMACHINE=RISCV %s -o %t.o
# RUN: ld.lld -r %t.o -o %t
# RUN: llvm-readobj -r %t | FileCheck --check-prefix=RELOC %s
Expand Down

0 comments on commit ff421be

Please sign in to comment.