[lld] r317781 - [MIPS] Fix calculation of the R_MICROMIPS_LO16 / HI16 relocations
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 9 04:10:14 PST 2017
Author: atanasyan
Date: Thu Nov 9 04:10:14 2017
New Revision: 317781
URL: http://llvm.org/viewvc/llvm-project?rev=317781&view=rev
Log:
[MIPS] Fix calculation of the R_MICROMIPS_LO16 / HI16 relocations
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/test/ELF/mips-micro-relocs.s
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=317781&r1=317780&r2=317781&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Nov 9 04:10:14 2017
@@ -540,9 +540,14 @@ static uint64_t getRelocTargetVA(RelType
// is _gp_disp symbol. In that case we should use the following
// formula for calculation "AHL + GP - P + 4". For details see p. 4-19 at
// ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
+ // microMIPS variants of these relocations use slightly different
+ // expressions: AHL + GP - P + 3 for %lo() and AHL + GP - P - 1 for %hi()
+ // to correctly handle less-sugnificant bit of the microMIPS symbol.
uint64_t V = InX::MipsGot->getGp() + A - P;
if (Type == R_MIPS_LO16 || Type == R_MICROMIPS_LO16)
V += 4;
+ if (Type == R_MICROMIPS_LO16 || Type == R_MICROMIPS_HI16)
+ V -= 1;
return V;
}
case R_MIPS_GOT_LOCAL_PAGE:
Modified: lld/trunk/test/ELF/mips-micro-relocs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-micro-relocs.s?rev=317781&r1=317780&r2=317781&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-micro-relocs.s (original)
+++ lld/trunk/test/ELF/mips-micro-relocs.s Thu Nov 9 04:10:14 2017
@@ -18,11 +18,9 @@
# REQUIRES: mips
-# Check disassembled code when LLD starts to setup
-# the least-significant bit for microMIPS symbols.
# EB: __start:
# EB-NEXT: 20010: 41 a3 00 01 lui $3, 1
-# EB-NEXT: 20014: 30 63 7f e0 addiu $3, $3, 32736
+# EB-NEXT: 20014: 30 63 7f df addiu $3, $3, 32735
# EB-NEXT: 20018: fc 7c 80 18 lw $3, -32744($gp)
# EB-NEXT: 2001c: fc 63 80 18 lw $3, -32744($3)
# EB-NEXT: 20020: 8f 70 beqz16 $6, -32
@@ -33,7 +31,7 @@
# EL: __start:
# EL-NEXT: 20010: a3 41 01 00 lui $3, 1
-# EL-NEXT: 20014: 63 30 e0 7f addiu $3, $3, 32736
+# EL-NEXT: 20014: 63 30 df 7f addiu $3, $3, 32735
# EL-NEXT: 20018: 7c fc 18 80 lw $3, -32744($gp)
# EL-NEXT: 2001c: 63 fc 18 80 lw $3, -32744($3)
# EL-NEXT: 20020: 70 8f beqz16 $6, -32
More information about the llvm-commits
mailing list