[llvm-dev] lld link error building llvm-shlib for mingw-w64

Jonathan Smith via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 28 10:49:48 PDT 2018


Hi, everyone.

I ran into an issue building an LLVM toolchain for Windows via
mingw-w64. My bootstrap LLVM version is 6.0.0 -- I'm using clang, lld,
and ninja. For the most part, everything builds fine until I get to
llvm-shlib, at which point lld fails with the following:

    lld: error: unknown argument: --version-script

Upon further inspection, the CMakeLists.txt for llvm-shlib has this
snippet in it:

    # GNU ld doesn't resolve symbols in the version script.
    set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
    if (NOT LLVM_LINKER_IS_SOLARISLD)
      # Solaris ld does not accept global: *; so there is no way to
version *all* global symbols
      set(LIB_NAMES
-Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map
${LIB_NAMES})
    endif()

The problem appears to be this: my -target is x86_64-w64-mingw32 and
clang appears to add "-m i386pep" to the link flags because of this.
In turn, this causes lld to interpret the target as being COFF
(correctly) and forwards the arguments to the COFF driver. The COFF
driver doesn't accept (nor does it ignore) the '--version-script'
argument. Prior to 6.0.0, the MinGW LLD driver didn't exist, so the
ELF driver was used which *does* accept the --version-script argument.

If I add " AND (NOT MINGW)" to the CMakeLists.txt if statement,
everything builds and runs properly.

Is this an actual bug or am I doing something horrible I should not be doing?

Thanks and respect,
Jon


More information about the llvm-dev mailing list