This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by MaskRay on Aug 27 2019, 4:37 AM.

Details

Summary

This essentially reverts the code change of 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). Just set the st_shndx arbitrarily to 1.

Dummy st_shndx=1 may be used by __rela_iplt_start, linker-script-defined symbols outside a section, __dso_handle, etc.

Diff Detail

Repository
rL LLVM

Event Timeline

MaskRay created this revision.Aug 27 2019, 4:37 AM
MaskRay updated this revision to Diff 217368.Aug 27 2019, 4:43 AM
MaskRay edited the summary of this revision. (Show Details)

This is used by rela_iplt_start, dso_handle, etc

PkmX added a comment.Aug 27 2019, 12:08 PM

This should be fine since lld doesn't support linker relaxation, so we just need to fabricate a dummy value for __global_pointer$ that allows it to link.

ruiu accepted this revision.Aug 28 2019, 1:08 AM

I think that PkmX is OK with this patch, so LGTM

This revision is now accepted and ready to land.Aug 28 2019, 1:08 AM
MaskRay updated this revision to Diff 217585.Aug 28 2019, 1:58 AM
MaskRay edited the summary of this revision. (Show Details)

Try fixing markdown in the description

Fix the comment in the test

MaskRay edited the summary of this revision. (Show Details)Aug 28 2019, 1:59 AM
This revision was automatically updated to reflect the committed changes.
lld/trunk/ELF/Writer.cpp