This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Move (copy relocation/canonical PLT) before error checking
ClosedPublic

Authored by MaskRay on Aug 9 2019, 4:54 AM.

Details

Summary

In processRelocAux(), we handle errors before copy relocation/canonical PLT.
This makes error checking a bit complex because we have to check for
conditions that will be allowed by copy relocation/canonical PLT.

Instead, move copy relocation/canonical PLT before error checking. This
simplifies the previous clumsy error checking code

config->shared || (config->pie && expr == R_ABS && type != target->symbolicRel)

to the simple config->isPic. Some diagnostics can be reported in
different ways. The code motion changes diagnostics for some contrived
test cases:

  • copy-rel-pie-error.s -> copy-rel-pie2.s: It was rejected before but accepted now. ld.bfd also accepts the case.
  • copy-errors.s: "cannot preempt symbol" changes to "symbol 'bar' has no type"
  • got32{,x}-i386.s: the suggestion changes from "-fPIC or -Wl,-z,notext" to "-fPIE"
  • x86-64-dyn-rel-error5.s: one diagnostic changes for -pie case

Diff Detail

Repository
rL LLVM

Event Timeline

MaskRay created this revision.Aug 9 2019, 4:54 AM
MaskRay updated this revision to Diff 214369.Aug 9 2019, 5:49 AM

simplify the code

MaskRay updated this revision to Diff 214371.Aug 9 2019, 6:20 AM

further simplification

Not got a strong opinion here, happy to go with the consensus.

ELF/Relocations.cpp
1004 ↗(On Diff #214356)

Could this trigger if !(sym.isFunc() || sym.isObject())? as this code path could exist in the previous version, but not with this one. This could be fixed by removing the (sym.isFunc() || sym.isObject()) from the initial if and reinstating if (sym.isFunc()) later.

1076 ↗(On Diff #214356)

Maybe able to simplify as Config->isPic is true in both error messages.

if (config->isPic) {
  if (!canWrite && !isRel(expr)) {
    error("can't create dynamic relocation");
  } else {
    errorOrWarn("relocation" + toString(type) + " cannot be used against " + ...);
  }
  return;
}
MaskRay updated this revision to Diff 214494.Aug 9 2019, 6:56 PM
MaskRay marked 2 inline comments as done.
MaskRay edited the summary of this revision. (Show Details)

Address review comments

Thanks for the update, I've no more comments.

% factor 66007 # ping
66007: 149 443
peter.smith accepted this revision.Aug 19 2019, 6:30 AM

I'm happy with the changes. Looks good to me.

This revision is now accepted and ready to land.Aug 19 2019, 6:30 AM
This revision was automatically updated to reflect the committed changes.
lld/trunk/test/ELF/copy-errors.s