[PATCH] D19718: [mips] Correct the ordering of HI/LO pairs in the relocation table.There seems to have been a misunderstanding as to the meaning of 'offset' inthe rules laid down by our ABI. The previous code believed that 'offset' meantthe offset within the...

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 03:16:57 PDT 2016


dsanders created this revision.
dsanders added a reviewer: sdardis.
dsanders added subscribers: llvm-commits, rafael.
dsanders added a dependency: D19716: [mips] Use MipsMCExpr instead of MCSymbolRefExpr for all relocations..
Herald added subscribers: sdardis, dsanders.

...section that the relocation is applied to. However, it
should have meant the offset from the symbol used in the relocation expression.

This patch adds two fields to ELFRelocationEntry and uses them to correct the
order of relocations for MIPS. These fields contain:
* The original symbol before shouldRelocateWithSymbol() is considered. This
  ensures that R_MIPS_GOT16 is able to correctly distinguish between local and
  external symbols, allowing us to tell whether %got() requires a matching
  %lo() or not (local symbols require one, external symbols don't). It also
  prevents confusing cases where the fuzzy matching rules cause things like
  %hi(foo)/%lo(foo+3) and %hi(bar)/%lo(bar+1) to swap their %lo()'s.
* The original offset before shouldRelocateWithSymbol() is considered. The
  existing Addend field is always zero when the object uses in place addends
  (because it's already moved it to the encoding) but MIPS needs to use the
  original offset to ensure that the linker correctly calculates the carry-in
  bit for %hi() and %got().

IAS ensures that unmatchable %hi()/%got() relocations are placed at the end of
the table to ensure that the linker rejects the table (we're unable to report
such errors directly). The alternatives to this risk accidental matching
against inappropriate relocations which may silently compute incorrect values
due to an incorrect carry bit between the %lo() and %hi()/%got().

Depends on D19716 and fixes the bug revealed by D19016.

http://reviews.llvm.org/D19718

Files:
  include/llvm/MC/MCELFObjectWriter.h
  lib/MC/ELFObjectWriter.cpp
  lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
  test/MC/Mips/sort-relocation-table.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19718.55560.patch
Type: text/x-patch
Size: 42236 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160429/ff36c6bf/attachment.bin>


More information about the llvm-commits mailing list