[PATCH] D41113: [LLVMgold] Don't set resolutions for undefined symbols to 'Prevailing'

Eugene Leviant via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 01:17:53 PST 2017


evgeny777 added a comment.

Thanks for sharing this! Here are results of my brief investigation:

IR symbol loading (through IRSymtab) happens absolutely identically in case of gold plugin and lld. In both cases undefined asm counterpart of 'foo' gets FB_used bit (so isUsed() returns true).
The difference, however, shows up when we process symbol resolutions in lto::addModuleToGlobalRes. The irsymtab::storage::Symbol has two name fields, used for different purposes

- Name. This is mangled name used to map GlobalResolution to specific IR symbol (see lto::addModuleToGlobalRes)
- IRName. This is unmangled name used to compute GUID (hash). For asm undefined symbols IRName is an empty string as they aren't IR symbols. This is being done in irsymtab::Builder::addSymbol

Now to your question (why is the handling added in https://reviews.llvm.org/D32544 not covering this?):

The lto::addModuleToGlobalRes relies on correct setting of 'Prevailing' in SymbolResolution. The logic behind it assumes that prevailing symbol always has valid IRName, so there are following lines of code:

  if (Res.Prevailing)
    GlobalRes.IRName = Sym.getIRName();

When we see asm undefined symbol with Prevailing == true (gold plugin) we set GlobalRes.IRName to an empty string. After that we are unable to correctly compute hash and set its IR counterpart as
GC root. This in turn causes incorrect symbol internalization/DCE.


https://reviews.llvm.org/D41113





More information about the llvm-commits mailing list