This is an archive of the discontinued LLVM Phabricator instance.

[COFF] Warn for locally imported symbols
ClosedPublic

Authored by smeenai on Dec 14 2017, 6:52 PM.

Details

Summary

Locally imported symbols are a very surprising linker feature. link.exe
warns for them, and we should warn too.

Diff Detail

Repository
rLLD LLVM Linker

Event Timeline

smeenai created this revision.Dec 14 2017, 6:52 PM
ruiu added inline comments.Dec 14 2017, 6:55 PM
COFF/SymbolTable.cpp
102

Can you just call warn() here?

test/COFF/locally-imported.test
6

I wouldn't repeat the filename twice in the same line.

smeenai added inline comments.Dec 14 2017, 7:01 PM
COFF/SymbolTable.cpp
102

I definitely want to report the object file which is importing the symbol (link.exe does even better and reports the function that's doing the import, but I believe reporting the object file is the best we can do). As far as I can tell, the only way to figure out the object file(s) that are doing the import is to loop through the symbols in Config->GCRoot and every object file, as is done below (in the loops I've modified). I could duplicate those loops here to inline the warning, but it seemed better to avoid the duplication and reuse the existing loops.

test/COFF/locally-imported.test
6

The file in which the symbol is defined and the file in which it's imported would normally be different.

If you want, I can change the test so that the symbol is defined and imported in different object files (or perhaps add a different test case which does that), to demonstrate the different filenames.

ruiu added inline comments.Dec 14 2017, 7:51 PM
COFF/SymbolTable.cpp
66

I'd name this LocalImports.

102

I see. But the way you are using the map is not correct. Sym and D are always the same pointer value. You can use a set instead of map.

smeenai added inline comments.Dec 14 2017, 7:56 PM
COFF/SymbolTable.cpp
102

I thought Sym would be the original (undefined) symbol, and D would be the corresponding defined local symbol. The pointer values are definitely different in my testing, and e.g. Sym->getFile() is NULL even after the replaceSymbol call.

ruiu added a comment.Dec 14 2017, 8:03 PM

I think I'm fine with this patch.

COFF/SymbolTable.cpp
102

Ah, my bad. They are different symbols indeed.

131

I'd name this Imp instead of LI (which is an unfamiliar name in lld.)

smeenai updated this revision to Diff 127063.Dec 14 2017, 8:36 PM

Rui's comments; add test for multiple input files

ruiu added inline comments.Dec 14 2017, 8:44 PM
COFF/SymbolTable.cpp
102

Why don't you do LocalImports[Sym] = D?

smeenai updated this revision to Diff 127065.Dec 14 2017, 8:49 PM

Use [] for dictionary insertion

smeenai added inline comments.Dec 14 2017, 8:49 PM
COFF/SymbolTable.cpp
102

I forgot about that form. Updated.

ruiu accepted this revision.Dec 14 2017, 8:51 PM

LGTM

This revision is now accepted and ready to land.Dec 14 2017, 8:51 PM
This revision was automatically updated to reflect the committed changes.