This is an archive of the discontinued LLVM Phabricator instance.

[COFF] Adjust how we flag weak externals
ClosedPublic

Authored by mstorsjo on Mar 10 2018, 4:26 PM.

Details

Summary

This fixes PR36096.

Originally based on a patch by Martell Malone.

Diff Detail

Repository
rL LLVM

Event Timeline

martell created this revision.Mar 10 2018, 4:26 PM
martell edited the summary of this revision. (Show Details)Mar 11 2018, 2:47 PM
martell added reviewers: mstorsjo, pcc.
martell removed subscribers: mstorsjo, pcc.

@alexcrichton can you confirm this works as a replacement for your partial revert here https://github.com/rust-lang/llvm/commit/9eb9267 ?

Thanks! This looks like it would do the trick yeah. I think we've since removed the C++ code that caused the error on our end (for entirely unrelated reasons) so we're unlikely to hit this any more (and can probably revert the patch I had), but this'd be good to get into the next version of LLVM!

pcc added a comment.Mar 15 2018, 6:51 PM

Probably the ideal test would be an object file with three weak externals with each of the possible characteristics. Then test that the archive symbol table contains only an entry for the symbol with characteristics IMAGE_WEAK_EXTERN_SEARCH_ALIAS.

lib/Object/COFFImportFile.cpp
549 ↗(On Diff #137931)

Please commit this part as a separate cleanup.

lib/Object/COFFObjectFile.cpp
235 ↗(On Diff #137931)

I don't think that getCharacteristics does what you are expecting it to do here. It looks like it retrieves the characteristics from the COFF header, and not the symbol: http://llvm-cs.pcc.me.uk/include/llvm/Object/COFF.h#821

Also, I think you will want to compare the characteristics to IMAGE_WEAK_EXTERN_SEARCH_ALIAS with !=, not use it as a bitmask.

mstorsjo commandeered this revision.Jul 19 2018, 11:36 AM
mstorsjo edited reviewers, added: martell; removed: mstorsjo.

It'd be nice to have this regression fixed before 7.0 branches; I'll post an updated version of the patch, taking the previous feedback into account.

mstorsjo updated this revision to Diff 156331.Jul 19 2018, 11:37 AM
mstorsjo retitled this revision from COFF: Adjust how we detect weak externals to [COFF] Adjust how we flag weak externals.
mstorsjo edited the summary of this revision. (Show Details)
pcc added inline comments.Jul 20 2018, 1:04 PM
lib/Object/COFFObjectFile.cpp
235 ↗(On Diff #156331)

I'd replace this with isUndefined and move the logic for whether to give a weak external the undefined bit to the isWeakExternal block.

mstorsjo added inline comments.Jul 20 2018, 1:26 PM
lib/Object/COFFObjectFile.cpp
235 ↗(On Diff #156331)

Right, that makes it much cleaner, thanks!

mstorsjo updated this revision to Diff 156588.Jul 20 2018, 1:27 PM

Applied @pcc's suggestion.

pcc added inline comments.Jul 20 2018, 1:31 PM
lib/Object/COFFObjectFile.cpp
223 ↗(On Diff #156588)

There should always be an auxiliary record for weak externals so you could replace the outer if with if (const coff_aux_weak_external *awe = Symb.getWeakExternal()) and simplify the check here.

mstorsjo updated this revision to Diff 156598.Jul 20 2018, 1:37 PM

Applied the following simplification suggested by @pcc.

pcc accepted this revision.Jul 20 2018, 1:43 PM

LGTM

lib/Object/COFFObjectFile.cpp
220 ↗(On Diff #156598)

nit: s/awe/AWE/g

This revision is now accepted and ready to land.Jul 20 2018, 1:43 PM
This revision was automatically updated to reflect the committed changes.