[PATCH] D72197: [MC][ELF] Emit a relocation if target is defined in the same section and is non-local

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 3 23:29:52 PST 2020


MaskRay created this revision.
MaskRay added reviewers: jhenderson, jyknight, peter.smith, skan.
Herald added subscribers: llvm-commits, luismarques, s.egerton, lenary, PkmX, simoncook, hiraditya, kristof.beyls, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

For a target symbol defined in the same section, currently we don't emit a
relocation (with few exceptions like RISC-V relaxation), while GNU as emits
one. This can break symbol interposition if the assembly is used by a shared
object.

  .globl foo
  foo:
    call foo   # on various targets, may be b foo, etc

ARM/thumb2-beq-fixup.s: we now emit a relocation to global_thumb_fn as GNU as does.
X86/Inputs/align-branch-64-2.s: we now emit R_X86_64_PLT32 to foo as GNU does.

ELF/relax.s: we emitted 3 relocations while GNU as emits 0. With this
patch, we emit one, thus we are mostly compatible with GNU as, except
that GNU as does not create a relocation to `global`. Rewrite the test
as target-in-same-section.s


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72197

Files:
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/test/MC/ARM/thumb2-beq-fixup.s
  llvm/test/MC/ELF/relax.s
  llvm/test/MC/ELF/target-in-same-section.s
  llvm/test/MC/X86/align-branch-64-2a.s
  llvm/test/MC/X86/align-branch-64-2b.s
  llvm/test/MC/X86/align-branch-64-2c.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72197.236166.patch
Type: text/x-patch
Size: 5903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200104/00e9bc46/attachment.bin>


More information about the llvm-commits mailing list