[PATCH] D158577: [MC,AArch64] Suppress local symbol to STT_SECTION conversion for GOT relocations

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 22 20:20:40 PDT 2023


MaskRay created this revision.
MaskRay added reviewers: peter.smith, stuij, jrtc27.
Herald added subscribers: sstefan1, luke, sunshaoce, frasercrmck, luismarques, apazos, sameer.abuasal, steven.zhang, pengfei, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, atanasyan, edward-jones, zzheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, fedor.sergeev, kbarton, hiraditya, kristof.beyls, arichardson, nemanjai, sdardis, jyknight.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, bd1976llvm.
Herald added a project: LLVM.

Assemblers change certain relocations referencing a local symbol to
reference the section symbol instead. This conversion is disabled for
many conditions (`shouldRelocateWithSymbol`), e.g. TLS symbol, for most
targets (including AArch32, x86, PowerPC, and RISC-V) GOT-generating
relocations.

However, AArch64 encodes the GOT-generating intent in MCValue::RefKind
instead of MCSymbolRef::Kind (see commit
0999cbd0b9ed8aa893cce10d681dec6d54b200ad (2014)), therefore not affected
by the code `case MCSymbolRefExpr::VK_GOT:`. Therefore, GOT relocations
referencing two local symbols may share the same GOT entry after linking
(GNU ld, ld.lld), which is not expected:

  ldr     x1, [x1, :got_lo12:x]  // converted to .data+0
  ldr     x1, [x1, :got_lo12:y]  // converted to .data+4
  
  .data
  // .globl x, y  would suppress STT_SECTION conversion
  x:
  .zero 4
  y:
  .long 42

This patch changes AArch64 to suppress local symbol to STT_SECTION
conversion for GOT relocations, matching most other targets. x and y
will use different GOT entries, which IMO is the most sensable behavior.

With this change, the ABI decision on https://github.com/ARM-software/abi-aa/issues/217
will only affect relocations explicitly referencing STT_SECTION symbols, e.g.

  ldr     x1, [x1, :got_lo12:(.data+0)]
  ldr     x1, [x1, :got_lo12:(.data+4)]
  // I consider this unreasonable uses

IMO all reasonable use cases are unaffected.

Link: https://github.com/llvm/llvm-project/issues/63418


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158577

Files:
  llvm/include/llvm/MC/MCELFObjectWriter.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/MC/MCELFObjectTargetWriter.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
  llvm/lib/Target/Lanai/MCTargetDesc/LanaiELFObjectWriter.cpp
  llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
  llvm/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp
  llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp
  llvm/lib/Target/VE/MCTargetDesc/VEELFObjectWriter.cpp
  llvm/lib/Target/Xtensa/MCTargetDesc/XtensaELFObjectWriter.cpp
  llvm/test/MC/AArch64/arm64-elf-relocs.s
  llvm/test/MC/AArch64/elf-reloc-got-local.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158577.552584.patch
Type: text/x-patch
Size: 14804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230823/9f7fe78e/attachment.bin>


More information about the llvm-commits mailing list