This is an archive of the discontinued LLVM Phabricator instance.

[llvm-dlltool] Make sure to strip decorations from ExtName for renamed exports
ClosedPublic

Authored by mstorsjo on Aug 22 2019, 1:26 PM.

Details

Summary

ExtName should not be decorated, just like Name.

This avoids double decoration on symbols in import libraries that use = for renaming functions. (Weak aliases, which use ==, worked fine with respect to decoration.)

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Aug 22 2019, 1:26 PM
ruiu accepted this revision.Aug 22 2019, 10:55 PM

LGTM

This revision is now accepted and ready to land.Aug 22 2019, 10:55 PM
This revision was automatically updated to reflect the committed changes.
mstorsjo added a subscriber: hans.Aug 23 2019, 4:20 AM

@hans - This is a pretty well isolated fix that might be mergeworthy if you still have the gates open, it shouldn't have any risk of regressions outside of its own scope at least :-)

jacek added a comment.Aug 23 2019, 7:42 AM

It looks like decoration is killed too aggressively now. If aliasee symbol has no decoration, aliased symbol is stripped. For example:

LIBRARY test.dll

EXPORTS
TestForward@4=TestFunc

will result with _TestForward symbol instead of _TestForward@4

It looks like decoration is killed too aggressively now. If aliasee symbol has no decoration, aliased symbol is stripped.

Ah, crap. @hans - no point in backporting this, as it's a bigger mess than it seemed first.

@jacek - the issue stems from how these work in msvc land. You can have /export:foo=bar where the decoration from the actual bar symbol gets transplanted on foo, see https://github.com/llvm/llvm-project/blob/master/llvm/lib/Object/COFFImportFile.cpp#L604. In this case, the original symbol has no decoration to transplant on the stripped ExtName.

jacek added a comment.Aug 23 2019, 9:16 AM

Oh, I see. FWIW, it shouldn't be too hard to work around the problem in Wine. .def file is generated automatically, so we could just skip aliases for .def file used for importlibs. It seems like it would help a hypethetical Wine MSCV port anyway and it might be better for LLVM to be MSVC compatible in this case. I will experiment with it.

jacek added a comment.Aug 23 2019, 9:27 AM

I can confirm that with a simple Wine change, its importlibs work fine.

Oh, I see. FWIW, it shouldn't be too hard to work around the problem in Wine. .def file is generated automatically, so we could just skip aliases for .def file used for importlibs.

That sounds good

and it might be better for LLVM to be MSVC compatible in this case

Well, when invoked as llvm-dlltool (or lld in mingw mode), it should definitely behave as the gnu equivalents. (Whether each bug is worth spending time on is ofc a different matter... And gnu dlltool has got an awful lot of different flags affecting how the symbol decorations are mangled.)