[PATCH] D66798: [ELF][RISCV] Assign st_shndx of __global_pointer$ to 1 if .sdata does not exist

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 04:39:09 PDT 2019


MaskRay created this revision.
MaskRay added reviewers: asb, jrtc27, lenary, ruiu.
Herald added subscribers: llvm-commits, pzheng, s.egerton, Jim, benna, psnobl, jocewei, PkmX, rkruppe, the_o, brucehoult, MartinMosbeck, rogfer01, atanasyan, edward-jones, zzheng, shiva0217, kito-cheng, niosHD, sabuasal, apazos, simoncook, johnrusso, rbar, krytarowski, arichardson, sdardis, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

This essentially reverts the code change of D63132 <https://reviews.llvm.org/D63132> and switches to a simpler approach.

In an executable/shared object, st_shndx of a symbol can be:

1. SHN_UNDEF: undefined symbol (or canonical PLT)
2. SHN_ABS: absolute symbol
3. any other value (usually a regular section index) represents a relative symbol. The actual value does not matter.

Many ld.so (musl, all archs except MIPS of FreeBSD rtld-elf) even treat

2. and 3) the same. If .sdata does not exist, it does not matter what

value/section __global_pointer$ has, as long as it is relative
(otherwise there will be a pedantic lld error. See D63132 <https://reviews.llvm.org/D63132>).
Just set the st_shndx arbitrarily to 1.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D66798

Files:
  ELF/SyntheticSections.cpp
  ELF/SyntheticSections.h
  ELF/Writer.cpp
  test/ELF/riscv-gp-dummy-sdata.s
  test/ELF/riscv-gp-no-sdata.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66798.217366.patch
Type: text/x-patch
Size: 5560 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190827/c2ec008c/attachment-0001.bin>


More information about the llvm-commits mailing list