This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Local hidden should be global syms
Needs ReviewPublic

Authored by rafauler on Aug 25 2023, 4:29 PM.

Details

Reviewers
Amir
maksfb
Group Reviewers
Restricted Project
Summary

Register all hidden local symbols as globals, since they are
still unique in the context of the input binary BOLT is
processing. This is used to fetch a single definition of
_GLOBAL_OFFSET_TABLE_.

Diff Detail

Event Timeline

rafauler created this revision.Aug 25 2023, 4:29 PM
Herald added a reviewer: maksfb. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
rafauler requested review of this revision.Aug 25 2023, 4:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2023, 4:29 PM
yota9 added inline comments.Aug 26 2023, 5:12 AM
bolt/lib/Rewrite/RewriteInstance.cpp
769

Maybe something like isSymbolDSOUnique? The global is a bit frustrating for me, e.g. only means SymbolRef::SF_Global.

770

BTW the WEAK symbols are visible outside the component, shoudn't we add check here too?

774

As I know the global hidden symbols are usually transformed to local default. If they are not transformed we would just return from the if global condition above. If the symbols stays local hidden for some reason (I think it is totally possible and does not contradicts anything, but I'm unable to generate it right now with my compilers and linkers) - is there any guaranties that the symbol was not generated by compiler like local (e.g. static symbol) and hidden due to fvisibility=hidden flag for example? I mean if the symbol is marked local I don't think we have guarantees that it is unique in DSO, are we?

Thanks for the review!

bolt/lib/Rewrite/RewriteInstance.cpp
774

That's fair. Another option is to hardcode and promote only _GLOBAL_OFFSET_TABLE_ if it is local hidden, and leave other symbols alone.

yota9 added inline comments.Aug 28 2023, 2:06 PM
bolt/lib/Rewrite/RewriteInstance.cpp
774

IMO It is better solution :) Please also consider to stay with this lambda and checking for WEAK symbols as I mentioned before, I think their handling might be missed before :)

maksfb added inline comments.Aug 29 2023, 1:31 PM
bolt/lib/Rewrite/RewriteInstance.cpp
774

If the change is just for the lookup of _GLOBAL_OFFSET_TABLE_, then it's better to encapsulate the lookup and maybe check for the global version first and then the local, or fix the naming just for that symbol as yota9 suggests.

Changing the internal naming may have an unintended consequence of missing/mismatching hidden functions in existing profiles.