This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Fix getRelocTargetVA formulae of R_TLS and R_NEG_TLS
ClosedPublic

Authored by MaskRay on May 18 2019, 2:28 AM.

Details

Summary

For R_TLS:

  1. Delete Sym.isTls() . The assembler ensures the symbol is STT_TLS. If not (the input is broken), we would crash (dereferencing null Out::TlsPhdr).
  2. Change Sym.isUndefWeak() to Sym.isUndefined(), otherwise with --noinhibit-exec we would still evaluate the symbol and crash.
  3. Return A if the symbol is undefined. This is PR40570. The case is probably unrealistic but returning A matches R_ABS and the behavior of several dynamic loaders.

R_NEG_TLS is obsoleted Sun TLS we don't fully support, but R_RELAX_TLS_GD_TO_LE_NEG is still used by GD->LE relaxation (subl $var@tpoff,%eax).
They should add the addend. Unfortunately I can't test it as compilers don't seem to generate non-zero implicit addends.
Prevent crash by adding Sym.isUndefined().

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

MaskRay created this revision.May 18 2019, 2:28 AM
MaskRay updated this revision to Diff 200140.May 18 2019, 2:42 AM
MaskRay edited the summary of this revision. (Show Details)

Reword

ruiu accepted this revision.May 20 2019, 3:39 AM

LGTM

ELF/InputSection.cpp
752

nit: -Sym.getVA(0) - getTlsTpOffset() + A

This revision is now accepted and ready to land.May 20 2019, 3:39 AM
MaskRay updated this revision to Diff 200254.May 20 2019, 4:41 AM
MaskRay edited the summary of this revision. (Show Details)

Update description

MaskRay marked an inline comment as done.May 20 2019, 4:43 AM
This revision was automatically updated to reflect the committed changes.