[PATCH] D101773: [MC][ELF] Work around R_MIPS_LO16 relocation handling problem

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 3 13:03:19 PDT 2021


MaskRay added a comment.

> This fixes PR49821, and avoids "ld.lld: error: test.o:(.rodata.str1.1): offset is outside the section" errors when linking certain MIPS objects

... with negative R_MIPS_LO16 implicit addends.

> A root of the problem is in the R_MIPS_LO16 relocation handling. Both R_MIPS_HI16 and R_MIPS_LO16 are considered as absolute relocations (the ...

Rephrase, with something like: ld.lld handles R_MIPS_HI16/R_MIPS_LO16 separately, not as a whole, so it doesn't know that an R_MIPS_HI16 with implicit addend 1 and an R_MIPS_LO16 with implicit addend -32768 represents 32768, which is in range of a MergeInputSection. We could introduce a new `RelExpr` member (like R_RISCV_PC_INDIRECT for R_RISCV_PCREL_HI20 / R_RISCV_PCREL_LO12) but the complexity is unnecessary given that GNU as keeps the original symbol for this case as well.



================
Comment at: llvm/test/MC/Mips/mips_lo16.s:4
+# RUN: llvm-mc %s -triple mips-unknown-unknown -filetype=obj | \
+# RUN:	 llvm-objdump -d -r - | FileCheck %s
+
----------------
Remove hex bytes with  --no-show-raw-insn


================
Comment at: llvm/test/MC/Mips/mips_lo16.s:5
+# RUN:	 llvm-objdump -d -r - | FileCheck %s
+
+	.text
----------------
Add mips64 for RELA test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101773/new/

https://reviews.llvm.org/D101773



More information about the llvm-commits mailing list