[lld] [LLD][COFF] Fix handling of weak aliases referencing lazy symbols (PR #112243)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 15 05:19:08 PDT 2024
================
@@ -340,7 +340,10 @@ class Undefined : public Symbol {
// If this symbol is external weak, try to resolve it to a defined
// symbol by searching the chain of fallback symbols. Returns the symbol if
// successful, otherwise returns null.
- Defined *getWeakAlias();
+ Symbol *getWeakAlias();
----------------
cjacek wrote:
The remaining callers use `getWeakAlias` to check if a symbol can be resolved. After the `run()` call, all such symbols should be replaced with a `Defined` symbol (assuming valid input, though a malformed archive index could disrupt this). This means that for many callers, `getWeakAlias` isn’t expected to handle lazy symbols, making it functionally equivalent to `getDefinedWeakAlias`. They only differ if new weak aliases are defined between `run()` calls.
In the test example from this PR, using `getDefinedWeakAlias` in `findMangle` would mostly work as well, but it's a bit more fragile. Processing `-export:func` would create a weak alias to `_func at 0`, but `-export:func2=func` would still consider it unresolvable and attempt to mangle it again. On the other hand, `getWeakAlias` returns the lazy symbol, so we know it will be resolvable and can skip the unnecessary mangling attempt.
https://github.com/llvm/llvm-project/pull/112243
More information about the llvm-commits
mailing list