[PATCH] D66552: [mips] Do not include offset into `%got` expression for global symbols

Simon Atanasyan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 21 13:41:09 PDT 2019


atanasyan created this revision.
Herald added subscribers: jrtc27, hiraditya, arichardson, sdardis.
Herald added a project: LLVM.
atanasyan edited the summary of this revision.

Now pseudo instruction `la $6, symbol+8($6)` is expanding into the following chain of commands:

  lw    $1, %got(symbol+8)($gp)
  addiu $1, $1, 8
  addu  $6, $1, $6

This is incorrect. When a linker handles the `R_MIPS_GOT16` relocation, it does not expect to get any addend and breaks on assertion. Otherwise it has to create new GOT entry for each unique "sym + offset" pair. Offset for a global symbol should be added to result of loading GOT entry by a separate `add` command.

The patch fixes the problem by stripping off an offset from the expression passed to the `%got`. That's interesting that even current code inserts a separate `add` command.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66552

Files:
  llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
  llvm/test/MC/Mips/macro-la-pic.s
  llvm/test/MC/Mips/mips-expansions.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66552.216463.patch
Type: text/x-patch
Size: 9069 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190821/7a7b973b/attachment-0001.bin>


More information about the llvm-commits mailing list