This is an archive of the discontinued LLVM Phabricator instance.

[LLD][COFF] Support GNU style == aliases
ClosedPublic

Authored by aykevl on Nov 7 2021, 7:58 AM.

Details

Summary

D46245 added support for this in llvm-libtool, but while lld-link can also create .lib files from .def files it didn't support aliases.

I compared the Inputs/library.def test against the output from llvm-libtool and it matches, except for the fact that lld-link reorders functions for some reason.

I have also verified that this fixes a bug I was running into while trying to compile .def files to .lib files in MinGW-w64 (using lld-link instead of llvm-libtool).

Diff Detail

Event Timeline

aykevl created this revision.Nov 7 2021, 7:58 AM
aykevl requested review of this revision.Nov 7 2021, 7:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 7 2021, 7:58 AM
mstorsjo accepted this revision.Nov 8 2021, 11:58 AM

This looks ok to me, but there's a couple unclear cases:

  • While this works for creating an import library out of a def file only, analoguously to llvm-dlltool, one can't create similar aliases while actually linking (doing that requires a couple more tweaks in a couple places, at least).
  • While this can replace some use cases of llvm-dlltool, for i386, there's nothing (yet) here that corresponds to dlltool's flag -k. (This is used for mingw-w64's system def files for i386, it's vital for producing the right kind of import library for stdcall functions.)
This revision is now accepted and ready to land.Nov 8 2021, 11:58 AM
aykevl added a comment.EditedNov 10 2021, 7:57 AM
  • While this works for creating an import library out of a def file only, analoguously to llvm-dlltool, one can't create similar aliases while actually linking (doing that requires a couple more tweaks in a couple places, at least).

Can you elaborate? With this fix I was able to link Windows binaries that referenced these aliases (using the MinWG lld driver). The linker was able to resolve them to the correct, non-weak versions.

  • While this can replace some use cases of llvm-dlltool, for i386, there's nothing (yet) here that corresponds to dlltool's flag -k. (This is used for mingw-w64's system def files for i386, it's vital for producing the right kind of import library for stdcall functions.)

Thanks, good to know! Right now I'm not targeting i386 so that's not a problem for me.

  • While this works for creating an import library out of a def file only, analoguously to llvm-dlltool, one can't create similar aliases while actually linking (doing that requires a couple more tweaks in a couple places, at least).

Can you elaborate? With this fix I was able to link Windows binaries that referenced these aliases (using the MinWG lld driver). The linker was able to resolve them to the correct, non-weak versions.

I’m not talking about linking against the created import library, I’m talking about linking the actual dll that the import library is for.

Example:

$ cat mylib.c 
void func1(void) {}
$ cat mylib.def 
EXPORTS
func1
aliasname == func1
$ clang -c mylib.c
$ lld-link mylib.o -out:mylib.dll -dll -noentry -def:mylib.def -implib:mylib.lib
lld-link: error: <root>: undefined symbol: aliasname
$ lld-link -def:mylib.def -implib:mylib.lib -machine:x64 

Thus, the def with an alias works when you create an implib from the def file only, but you can't use the same def file when you actually produce your DLL.

This revision was landed with ongoing or failed builds.Jan 19 2022, 5:22 AM
This revision was automatically updated to reflect the committed changes.