diff options
| author | Martin Storsjö <martin@martin.st> | 2023-11-04 23:49:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-04 23:49:38 +0200 |
| commit | 3ab6209a3f93bdbeec8e9b9fcc00a9a4980915ff (patch) | |
| tree | ff5b4be7f39e4f5f354203c3d72255899333323c /lld/COFF/InputFiles.cpp | |
| parent | 97c9c9429cb72d230ecd31d45ae83e0ca3470ca1 (diff) | |
| download | llvm-3ab6209a3f93bdbeec8e9b9fcc00a9a4980915ff.tar.gz llvm-3ab6209a3f93bdbeec8e9b9fcc00a9a4980915ff.tar.bz2 llvm-3ab6209a3f93bdbeec8e9b9fcc00a9a4980915ff.zip | |
[LLD] [COFF] Handle manually defined __imp_ pointers in LTO (#70777)
Such pointers are often used by the core parts of mingw-w64, to locally
define a function that might have been referred to with dllimport.
(MSVC style linkers can automatically provide such pointers, if there
are undefined references to `__imp_<func>` left but a definition of
`<func>` is available - although this prints the warning LNK4217. GNU ld
doesn't do this, so in mingw-w64, such things are generally handled by
manually providing the relevant `__imp_` pointers.)
Make sure that a full LTO build, that does LTO of both the `__imp_`
pointer and the object file referencing it, successfully resolves such
symbols.
This solution admittedly probably reduces the effect of the LTO
compilation if there would happen to be `__imp_` prefixed symbols
included, in LTO objects, that aren't actually used. Such symbols are
mostly used in the base toolchain, not often in user code, and usually
only the relevant object files are linked in anyway.
This fixes https://github.com/llvm/llvm-project/issues/57982.
Diffstat (limited to 'lld/COFF/InputFiles.cpp')
| -rw-r--r-- | lld/COFF/InputFiles.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index 38ce29e6ab68..3ae05f42ac5f 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -1061,6 +1061,12 @@ void BitcodeFile::parse() { } else { sym = ctx.symtab.addRegular(this, symName, nullptr, fakeSC, 0, objSym.isWeak()); + // Model all symbols with the __imp_ prefix as having external + // references. If one LTO object defines a __imp_<foo> symbol, and + // another LTO object refers to <foo> with dllimport, make sure the + // __imp_ symbol is kept. + if (symName.starts_with("__imp_")) + sym->isUsedInRegularObj = true; } symbols.push_back(sym); if (objSym.isUsed()) |
