Skip to content

link errors when building LLVM as a Windows DLL with polly project included #152328

@andrurogerz

Description

@andrurogerz

Overview

When configured to build as a Windows DLL, LLVM does not build successfully when the polly project is included.

bugpoint.cpp.obj : error LNK2019: unresolved external symbol "struct llvm::PassPluginLibraryInfo __cdecl getPollyPluginInfo(void)" (?getPollyPluginInfo@@YA?AUPassPluginLibraryInfo@llvm@@XZ) referenced in function main
bin\bugpoint.exe : fatal error LNK1120: 1 unresolved externals

Fixing this error does not appear to be a simple matter of adding an LLVM_ABI annotation to the getPollyPluginInfo symbol. It needs further investigation.

Repro

On Windows 11:

git checkout 25d1285eecbab731eaf418c8aab44e4eb5f9e538

cmake -B build -S llvm -G Ninja -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;llvm;polly" -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_BUILD_TESTS=ON -DLLVM_BUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCLANG_LINK_CLANG_DYLIB=OFF -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_BUILD_LLVM_DYLIB_VIS=ON -DLLVM_LINK_LLVM_DYLIB=ON

ninja -C build

Observe build errors.

[1773/2053] Linking CXX executable bin\bugpoint.exe
FAILED: bin/bugpoint.exe
C:\WINDOWS\system32\cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=tools\bugpoint\CMakeFiles\bugpoint.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\HostX64\x64\link.exe /nologo tools\bugpoint\CMakeFiles\bugpoint.dir\BugDriver.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\CrashDebugger.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\ExecutionDriver.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\ExtractFunction.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\FindBugs.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\Miscompilation.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\OptimizerDriver.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\ToolRunner.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\bugpoint.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\__\__\resources\windows_version_resource.rc.res  /out:bin\bugpoint.exe /implib:lib\bugpoint.lib /pdb:bin\bugpoint.pdb /version:0.0 /machine:x64 /STACK:10000000 /INCREMENTAL:NO /subsystem:console  lib\LLVM-22git.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\HostX64\x64\link.exe /nologo tools\bugpoint\CMakeFiles\bugpoint.dir\BugDriver.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\CrashDebugger.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\ExecutionDriver.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\ExtractFunction.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\FindBugs.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\Miscompilation.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\OptimizerDriver.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\ToolRunner.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\bugpoint.cpp.obj tools\bugpoint\CMakeFiles\bugpoint.dir\__\__\resources\windows_version_resource.rc.res /out:bin\bugpoint.exe /implib:lib\bugpoint.lib /pdb:bin\bugpoint.pdb /version:0.0 /machine:x64 /STACK:10000000 /INCREMENTAL:NO /subsystem:console lib\LLVM-22git.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST:EMBED,ID=1" failed (exit code 1120) with the following output:
bugpoint.cpp.obj : error LNK2019: unresolved external symbol "struct llvm::PassPluginLibraryInfo __cdecl getPollyPluginInfo(void)" (?getPollyPluginInfo@@YA?AUPassPluginLibraryInfo@llvm@@XZ) referenced in function main
bin\bugpoint.exe : fatal error LNK1120: 1 unresolved externals
FAILED: bin/clang-cpp.dll lib/clang-cpp.lib
C:\WINDOWS\system32\cmd.exe /C "cd . && "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_dll --intdir=tools\clang\tools\clang-shlib\CMakeFiles\clang-cpp.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\HostX64\x64\link.exe /nologo @CMakeFiles\clang-cpp.rsp  /out:bin\clang-cpp.dll /implib:lib\clang-cpp.lib /pdb:bin\clang-cpp.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO  -Bsymbolic-functions && cd ."
LINK: command "C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1439~1.335\bin\HostX64\x64\link.exe /nologo @CMakeFiles\clang-cpp.rsp /out:bin\clang-cpp.dll /implib:lib\clang-cpp.lib /pdb:bin\clang-cpp.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO -Bsymbolic-functions /MANIFEST:EMBED,ID=2" failed (exit code 1120) with the following output:
LINK : warning LNK4044: unrecognized option '/Bsymbolic-functions'; ignored
   Creating library lib\clang-cpp.lib and object lib\clang-cpp.exp
BackendUtil.cpp.obj : error LNK2019: unresolved external symbol "struct llvm::PassPluginLibraryInfo __cdecl getPollyPluginInfo(void)" (?getPollyPluginInfo@@YA?AUPassPluginLibraryInfo@llvm@@XZ) referenced in function "private: void __cdecl `anonymous namespace'::EmitAssemblyHelper::RunOptimizationPipeline(enum clang::BackendAction,class std::unique_ptr<class llvm::raw_pwrite_stream,struct std::default_delete<class llvm::raw_pwrite_stream> > &,class std::unique_ptr<class llvm::ToolOutputFile,struct std::default_delete<class llvm::ToolOutputFile> > &,class clang::BackendConsumer *)" (?RunOptimizationPipeline@EmitAssemblyHelper@?A0xc4eeb055@@AEAAXW4BackendAction@clang@@AEAV?$unique_ptr@Vraw_pwrite_stream@llvm@@U?$default_delete@Vraw_pwrite_stream@llvm@@@std@@@std@@AEAV?$unique_ptr@VToolOutputFile@llvm@@U?$default_delete@VToolOutputFile@llvm@@@std@@@6@PEAVBackendConsumer@4@@Z)
bin\clang-cpp.dll : fatal error LNK1120: 1 unresolved externals

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions