Skip to content

Commit

Permalink
[ELF] Support R_PPC64_ADDR16_HIGH
Browse files Browse the repository at this point in the history
R_PPC64_ADDR16_HI represents bits 16-31 of a 32-bit value
R_PPC64_ADDR16_HIGH represents bits 16-31 of a 64-bit value.

In the Linux kernel, `LOAD_REG_IMMEDIATE_SYM` defined in `arch/powerpc/include/asm/ppc_asm.h`
uses @l, @high, @higher, @highest to load the 64-bit value of a symbol.

Fixes ClangBuiltLinux/linux#1260
  • Loading branch information
MaskRay committed Jan 19, 2021
1 parent e12e0d6 commit 5fcb412
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lld/ELF/Arch/PPC64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ RelExpr PPC64::getRelExpr(RelType type, const Symbol &s,
case R_PPC64_ADDR16_DS:
case R_PPC64_ADDR16_HA:
case R_PPC64_ADDR16_HI:
case R_PPC64_ADDR16_HIGH:
case R_PPC64_ADDR16_HIGHER:
case R_PPC64_ADDR16_HIGHERA:
case R_PPC64_ADDR16_HIGHEST:
Expand Down Expand Up @@ -1230,6 +1231,9 @@ void PPC64::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
checkInt(loc, val, 32, rel);
write16(loc, hi(val));
break;
case R_PPC64_ADDR16_HIGH:
write16(loc, hi(val));
break;
case R_PPC64_ADDR16_HIGHER:
case R_PPC64_TPREL16_HIGHER:
write16(loc, higher(val));
Expand Down
5 changes: 5 additions & 0 deletions lld/test/ELF/ppc64-reloc-addr.s
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
.section .R_PPC64_ADDR16_HA,"ax",@progbits
lis 4, b@ha

# CHECK-LABEL: <.R_PPC64_ADDR16_HIGH>:
# CHECK-NEXT: lis 4, -30293
.section .R_PPC64_ADDR16_HIGH,"ax",@progbits
lis 4, a@high

# CHECK-LABEL: <.R_PPC64_ADDR16_HIGHER>:
# CHECK-NEXT: li 3, 17767
.section .R_PPC64_ADDR16_HIGHER,"ax",@progbits
Expand Down
2 changes: 2 additions & 0 deletions lld/test/ELF/ppc64-reloc-addr16-err.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ lis 4, a@h # R_PPC64_ADDR16_HI
.ifdef HA
lis 4, a@ha # R_PPC64_ADDR16_HA
.endif

lis 4, a@high # R_PPC64_ADDR16_HIGH

0 comments on commit 5fcb412

Please sign in to comment.