llvm-mingw icon indicating copy to clipboard operation
llvm-mingw copied to clipboard

lld: --export-dynamic disappeared in 16?

Open jcelerier opened this issue 2 years ago • 1 comments

I was using it with great success before this (e.g. it used to work for my purposes in ~https://github.com/mstorsjo/llvm-mingw/releases/tag/20220906~ a previous tag I have to find, where cmake's set_target_properties(the_program PROPERTIES ENABLE_EXPORTS 1) would do the right thing) but since 15/16, it seems that ld.lld -E or ld.lld --export-dynamic does not work anymore:

$ ld.lld --export-dynamic
lld: error: unknown argument: --export-dynamic

Is there a deep reason for this change? I tried to dig into the lld code but could not easily find where this is handled and which commits have changed things...

jcelerier avatar Jun 13 '23 23:06 jcelerier

Hmm, lld never supported this option for mingw targets, but it does support it for ELF targets.

On what build of llvm-mingw did you do ld.lld --export-dynamic where it works? On a unix-based build of llvm-mingw, invoking ld.lld without any extra arguments will be running lld in ELF mode, and I get the following output:

$ ld.lld --export-dynamic
ld.lld: error: no input files

In a Windows build of llvm-mingw, what ld.lld without extra arguments does has varied a bit.

Previously, before 51abc9117f7c7087a8519e38d71da411a8ffe3da, ld.lld without any arguments on Windows would also default to ELF mode - which in most cases probably isn't what you would have wanted anyway. When Clang invokes it, it does so with e.g. -m i386pep which switches it to mingw mode, where --export-dynamic isn't supported. Also if you'd invoke it via the <arch>-w64-mingw32-ld shell script wrappers, that also invokes ld.lld with the right -m option that switches it to mingw mode.

After 51abc9117f7c7087a8519e38d71da411a8ffe3da, in Windows builds of llvm-mingw, ld.lld defaults to mingw mode, so that e.g. ld.lld --help gives the right help listing - this was requested in #331.

So --export-dynamic should be just as supported now as it was before, i.e. only in ELF mode but not for mingw mode. If you really want to run lld in ELF mode in a Windows build of llvm-mingw, you need to pass it another -m parameter that switches it back to ELF mode, e.g. -m elf_x86_64.

mstorsjo avatar Jun 14 '23 06:06 mstorsjo