The situation when undefined symbol is not used often takes place, when compiler flags -ffunction-sections -fdata-sections are used in conjunction with linker flag --gc-sections.
In such case we can have undefined symbol which is used by some function collected by linker GC. Both gold and ld add undefined symbol to symtab without reporting any error or warning. This patch makes lld to emit warning instead of error in such cases.
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
ELF/Relocations.cpp | ||
---|---|---|
560 ↗ | (On Diff #73488) | I don't think you need to record whether a symbol is used or not here to use the information later. Instead, you could print out a warning message directly from this context. |
ELF/Writer.cpp | ||
320 ↗ | (On Diff #73488) | Instead of adding a new bit to the symbol, I'd do this here. // Ignore symbols in garbage-collected sections. // We could report them, but we don't because GNU linkers don't. if (Sym->symbol()->includeInDynsym()) if (auto *D = dyn_cast<DefinedRegular<ELFT>(Sym)) if (!D->Section.Live) return; |
320 ↗ | (On Diff #73488) | Ignore this comment -- I deleted it before sending a message but it wasn't removed for some reason. |
ELF/Relocations.cpp | ||
---|---|---|
560 ↗ | (On Diff #73488) | Can you please elaborate? If symbol is not a target of any reloc then I won't see it here, will I? |
ELF/Relocations.cpp | ||
---|---|---|
560 ↗ | (On Diff #73488) | If Body is an undefined symbol we want to warn/error here, no? Then undefined and unreferenced symbols will be ignored completely. |
ELF/Relocations.cpp | ||
---|---|---|
560 ↗ | (On Diff #73488) | Do you want to call reportUndefined() here like this: if (Body.isUndefined()) reportUndefined(&Body); I'll check if this works. |
Comment Actions
LGTM
ELF/Relocations.cpp | ||
---|---|---|
523 ↗ | (On Diff #73623) | Change the type from SymbolBody * to SymbolBody &. |