This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Only import for non-prevailing interposable global variables
ClosedPublic

Authored by smeenai on Mar 25 2023, 9:26 AM.

Details

Summary

This logic was added in https://reviews.llvm.org/D95943 specifically to
handle an issue for non-prevailing global variables. It turns out that
it adds a new issue for prevailing glboal variables, since those could
be replaced by an available_externally definition and hence incorrectly
omitted from the output object file. Limit the import to non-prevailing
global variables to fix this, as suggested by @tejohnson.

The bulk of the diff is mechanical changes to thread isPrevailing
through to where it's needed and ensure it's available before the
relevant calls; the actual logic change itself is straightforward.

Fixes https://github.com/llvm/llvm-project/issues/61677

Diff Detail

Event Timeline

smeenai created this revision.Mar 25 2023, 9:26 AM
smeenai requested review of this revision.Mar 25 2023, 9:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2023, 9:26 AM
smeenai updated this revision to Diff 508318.Mar 25 2023, 9:30 AM

Fix dummy isPrevailing to always return true instead of false

tejohnson accepted this revision.Mar 25 2023, 11:04 AM

lgtm with one minor test suggestion

llvm/test/ThinLTO/X86/prevailing_weak_globals_import.ll
16

I think this will also match against the def of the longer "ret_av_ext_def" symbol. Is there a way to make it a bit tighter, e.g. something like:
; NM: W def

This revision is now accepted and ready to land.Mar 25 2023, 11:04 AM
smeenai added inline comments.Mar 25 2023, 9:05 PM
llvm/test/ThinLTO/X86/prevailing_weak_globals_import.ll
16

I'm using --match-full-lines in the FileCheck call to avoid that, and I verified that this particular check fails without my patch. I can add regex start and end line anchors if you'd prefer being more explicit.

tejohnson added inline comments.Mar 25 2023, 9:18 PM
llvm/test/ThinLTO/X86/prevailing_weak_globals_import.ll
16

Ah, missed that. Nevermind then, this is fine.

Thank you for the quick review! This is my first change in this area, and I really appreciate your insight and responsiveness :)

fhahn added a subscriber: fhahn.Mar 29 2023, 2:06 AM
fhahn added inline comments.
llvm/include/llvm/Transforms/IPO/FunctionImport.h
161

nit: The naming here is inconsistent with the other arguments; it should probably be IsPrevailing.

smeenai added inline comments.Mar 29 2023, 2:07 AM
llvm/include/llvm/Transforms/IPO/FunctionImport.h
161

I thought about that, but for this particular variable, every other place always uses isPrevailing. IIRC there was discussion at some point around changing the style guide to lowerCamelCase function-like variables; I guess they were preemptively following that?

fhahn added inline comments.Mar 29 2023, 2:11 AM
llvm/include/llvm/Transforms/IPO/FunctionImport.h
161

It would also be helpful to document the argument.

smeenai added inline comments.Mar 29 2023, 3:28 AM
llvm/include/llvm/Transforms/IPO/FunctionImport.h
161

Thanks, I put up D147133.