This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Handle -u before input files
ClosedPublic

Authored by MaskRay on Jun 2 2020, 8:51 PM.

Details

Summary

If both a.a and b.so define foo

ld.bfd -u foo a.a b.so  # foo is defined
ld.bfd a.a b.so -u foo  # foo is defined
ld.bfd -u foo b.so a.a  # foo is undefined (provided at runtime by b.so)
ld.bfd b.so a.a -u foo  # foo is undefined (provided at runtime by b.so)

In all cases we make foo undefined in the output. I tend to think the
GNU ld behavior makes more sense.

  • In their model, they have to treat -u as a fake object file with an undefined symbol before all input files, otherwise the first archive would not be fetched.
  • Following their behavior allows us to drop a --warn-backrefs special case.

Diff Detail

Event Timeline

MaskRay created this revision.Jun 2 2020, 8:51 PM
MaskRay edited the summary of this revision. (Show Details)Jun 2 2020, 8:52 PM
MaskRay updated this revision to Diff 268050.Jun 2 2020, 9:23 PM

Don't move a isUsedInRegularObj block

Harbormaster completed remote builds in B58850: Diff 268048.
psmith added a comment.Jun 3 2020, 8:07 AM

Looks sensible to me. A couple of comment suggestions only.

lld/ELF/Driver.cpp
1473

We now no longer use this function for -u, will be worth updating comment.

1885–1888

IIUC this is to prevent LTO from removing definitions. May be worth saying

// Prevent LTO from removing any definition referenced by an undefined.
MaskRay updated this revision to Diff 268215.Jun 3 2020, 8:30 AM
MaskRay marked 3 inline comments as done.

Address comments

MaskRay marked an inline comment as done.Jun 3 2020, 8:31 AM
MaskRay added inline comments.
lld/ELF/Driver.cpp
1473

All handleUndefined call sites may use addUndefined instead. I'll experiment. Two --wrap uses of addUndefined should probably be addUnusedUndefined instead (to fix https://bugs.llvm.org/show_bug.cgi?id=46169 )

1885–1888

Thanks for the suggestion!

The logic was introduced in D38348 .

We seem to consider a bitcode file a variant of an archive (its symbol table does not translate to .symtab in the output, but -u can force it).

psmith accepted this revision.Jun 5 2020, 1:09 AM

Thanks for the update. I don't have any more comments. Looks good to me.

This revision is now accepted and ready to land.Jun 5 2020, 1:09 AM
This revision was automatically updated to reflect the committed changes.
troyj added a subscriber: troyj.Oct 6 2020, 6:45 PM

In all cases we make foo undefined in the output.

Why? We're having trouble with this downstream for the case of:

-u foo a.o b.a

where foo is weak in a.o and provided by b.a. The result is that foo is undefined in the output, whereas the previous behavior was for foo to be defined.

In all cases we make foo undefined in the output.

Why?

Undefined weak is difficult. You can check out D63974 D64136 D65584 D66992 is you want to learn more.

We're having trouble with this downstream for the case of:

-u foo a.o b.a

where foo is weak in a.o and provided by b.a. The result is that foo is undefined in the output, whereas the previous behavior was for foo to be defined.

Sent D88945