conda-forge / llvmdev-feedstock

A conda-smithy repository for llvmdev.
BSD 3-Clause "New" or "Revised" License
8 stars 41 forks source link

Fix for missing LLJIT symbols #243

Closed bluescarni closed 11 months ago

bluescarni commented 1 year ago

Checklist

bluescarni commented 1 year ago

@conda-forge/llvmdev @h-vetinari

After updating LLVM from 16 to 17, I started experiencing error messages from the LLJIT subsystem about missing symbols in one of my libraries. The problem arises when compiling statically against LLVM AND removing all LLVM symbols via the -Wl,--exclude-libs,ALL linker flag. This is an approach commonly used to pre-emptively prevent symbol collisions when one mixes multiple versions of the LLVM library in a single binary (as suggested by @isuruf who I believe uses this technique in symengine).

I started asking on the LLVM discord channel and LLVM maintainer @lhames mentioned this is a known issue solved in the following LLVM commit:

https://github.com/llvm/llvm-project/commit/122ebe3b500190b1f408e2e6db753853e297ba28

I downloaded the patch and added it to the recipe, after verifying on a local build that indeed it does resolve the issue.

conda-forge-webservices[bot] commented 1 year ago

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

bluescarni commented 1 year ago

Also this is currently failing on osx with some missing symbols (it's also possible that this is due to the switch to clang 16; though I'd be surprised).

[3032/3456] Linking CXX executable bin/lli-child-target
FAILED: bin/lli-child-target 
: && $BUILD_PREFIX/bin/x86_64-apple-darwin13.4.0-clang++ -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden -fmessage-length=0 -isystem $PREFIX/include -fdebug-prefix-map=$SRC_DIR=/usr/local/src/conda/llvm-package-17.0.2 -fdebug-prefix-map=$PREFIX=/usr/local/src/conda-prefix -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -O3 -DNDEBUG -isysroot /Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -mmacosx-version-min=10.9 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,$PREFIX/lib -L$PREFIX/lib     -Wl,-dead_strip -rdynamic tools/lli/ChildTarget/CMakeFiles/lli-child-target.dir/ChildTarget.cpp.o -o bin/lli-child-target  -Wl,-rpath,@loader_path/../lib  lib/libLLVMOrcJIT.a  lib/libLLVMOrcShared.a  lib/libLLVMOrcTargetProcess.a  lib/libLLVMSupport.a  lib/libLLVMPasses.a  lib/libLLVMCodeGen.a  lib/libLLVMCodeGenTypes.a  lib/libLLVMCoroutines.a  lib/libLLVMipo.a  lib/libLLVMBitWriter.a  lib/libLLVMFrontendOpenMP.a  lib/libLLVMLinker.a  lib/libLLVMIRPrinter.a  lib/libLLVMObjCARCOpts.a  lib/libLLVMScalarOpts.a  lib/libLLVMAggressiveInstCombine.a  lib/libLLVMInstCombine.a  lib/libLLVMVectorize.a  lib/libLLVMInstrumentation.a  lib/libLLVMExecutionEngine.a  lib/libLLVMJITLink.a  lib/libLLVMOrcTargetProcess.a  lib/libLLVMOrcShared.a  lib/libLLVMWindowsDriver.a  lib/libLLVMOption.a  lib/libLLVMRuntimeDyld.a  lib/libLLVMTarget.a  lib/libLLVMTransformUtils.a  lib/libLLVMAnalysis.a  lib/libLLVMProfileData.a  lib/libLLVMSymbolize.a  lib/libLLVMDebugInfoPDB.a  lib/libLLVMDebugInfoMSF.a  lib/libLLVMDebugInfoBTF.a  lib/libLLVMDebugInfoDWARF.a  lib/libLLVMObject.a  lib/libLLVMIRReader.a  lib/libLLVMBitReader.a  lib/libLLVMAsmParser.a  lib/libLLVMMCParser.a  lib/libLLVMMC.a  lib/libLLVMDebugInfoCodeView.a  lib/libLLVMTextAPI.a  lib/libLLVMCore.a  lib/libLLVMBinaryFormat.a  lib/libLLVMRemarks.a  lib/libLLVMBitstreamReader.a  lib/libLLVMTargetParser.a  lib/libLLVMSupport.a  -lm  $PREFIX/lib/libz.dylib  $PREFIX/lib/libzstd.dylib  lib/libLLVMDemangle.a && :
Undefined symbols for architecture x86_64:
  "___isPlatformVersionAtLeast", referenced from:
      llvm::sys::fs::copy_file(llvm::Twine const&, llvm::Twine const&) in libLLVMSupport.a(Path.cpp.o)
      llvm::set_thread_priority(llvm::ThreadPriority) in libLLVMSupport.a(Threading.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

I have a vague recollection of seeing such error messages in the past when linking to the LLVM libraries on OSX, but my memory is hazy...

I do not believe these undefined symbols are related to the patch however, as I see no mention of ___isPlatformVersionAtLeast, copy_file or set_thread_priority in the diff. But how do we find out?

bluescarni commented 1 year ago

I have a vague recollection of seeing such error messages in the past when linking to the LLVM libraries on OSX, but my memory is hazy...

I do not believe these undefined symbols are related to the patch however, as I see no mention of ___isPlatformVersionAtLeast, copy_file or set_thread_priority in the diff. But how do we find out?

Yep here we go:

https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=798869&view=logs&j=533df66e-ef32-57fb-9d39-e038b84a7cf7&t=ea951586-cf51-5164-3bc8-fc7485541e22

h-vetinari commented 1 year ago

Yep here we go:

https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=798869&view=logs&j=533df66e-ef32-57fb-9d39-e038b84a7cf7&t=ea951586-cf51-5164-3bc8-fc7485541e22

Azure deleted those logs, unfortunately. Better to copy relevant things to the PR... 😅

bluescarni commented 12 months ago

Azure deleted those logs, unfortunately. Better to copy relevant things to the PR... 😅

Yikes, so soon? :(

The PR was a new build of my package https://github.com/conda-forge/heyoka-feedstock, which uses LLVM. As part of the rerender, the compiler version on OSX x64 was bumped from 15 -> 16, which resulted in the build failing with the same linker error as in this PR (Undefined symbols for architecture x86_64, blah blah).

I manually downgraded the compiler version from 16 to 15 and the build succeeded.

h-vetinari commented 12 months ago

Yikes, so soon? :(

Azure only keeps logs for CI runs that run to completion - if 19/20 jobs are done, but one got a slow agent and now there's a new push to the PR, everything will be deleted (it's very annoying...)

Thanks for the info. In that case, you can try the following in conda_build_config.yaml and then rerender.

# <explanatory comment>
c_compiler_version:     # [osx]
  - 15                  # [osx]
cxx_compiler_version:   # [osx]
  - 15                  # [osx]
bluescarni commented 12 months ago

Thanks for the info. In that case, you can try the following in conda_build_config.yaml and then rerender.

# <explanatory comment>
c_compiler_version:     # [osx]
  - 15                  # [osx]
cxx_compiler_version:   # [osx]
  - 15                  # [osx]

I tried that but I think that the rerender got confused, and instead of changing the compiler versions from 16 to 15, what happened was that this

MACOSX_SDK_VERSION:
- '10.12'

became this

MACOSX_SDK_VERSION:
- '10.12'
- '15'

That is, the 15 got somehow added to the MACOSX_SDK_VERSION section of the yaml instead of the cxx_compiler_version section. I have no idea why, my speculation is that that the rerender process is confused by the presence of these sections in my conda_build_config.yaml file:

llvmdev:
  - 13
  - 14
  - 15
  - 16
llvm:
  - 13
  - 14
  - 15
  - 16
zip_keys:
  - llvmdev
  - llvm

I would point to the logs but alas...

h-vetinari commented 12 months ago

I tried that but I think that the rerender got confused,

I'm talking about the failures in this PR. You should add that conda_build_config.yaml here.

bluescarni commented 12 months ago

I'm talking about the failures in this PR. You should add that conda_build_config.yaml here.

slaps forehead

xhochy commented 12 months ago

The linkage issue seems like a wide-spread problem, I have opened https://github.com/conda-forge/llvmdev-feedstock/issues/244 to track it.

h-vetinari commented 11 months ago

I incorporated the fix into #245; if you need a backport to 16.x, please open a PR! :)

bluescarni commented 11 months ago

@h-vetinari cheers! I do not think the LLJIT symbols issue is present in LLVM 16.x (if that is what you are referring to).