This is an archive of the discontinued LLVM Phabricator instance.

fix: Link `atomic` into LLVMOrcJIT on platforms without hardware support for atomics
ClosedPublic

Authored by 414owen on Apr 10 2023, 6:32 AM.

Details

Summary

When linking LLVMOrcJit on ARMv6, I get an error about a missing reference to __atomic_fetch_add_8.

This seems to be because on platforms without hardware support, we need to link in atomic.

The full error is below:

[ 66%] Linking CXX shared library ../../libLLVMOrcJIT.so
/usr/bin/ld: CMakeFiles/LLVMOrcJIT.dir/ObjectLinkingLayer.cpp.o: in function `llvm::orc::ObjectLinkingLayer::add(llvm::IntrusiveRefCntPtr<llvm::orc::ResourceTracker>, std::unique_ptr<llvm::jitlink::LinkGraph, std::default_delete<llvm::jitlink::LinkGraph> >)':
ObjectLinkingLayer.cpp:(.text._ZN4llvm3orc18ObjectLinkingLayer3addENS_18IntrusiveRefCntPtrINS0_15ResourceTrackerEEESt10unique_ptrINS_7jitlink9LinkGraphESt14default_deleteIS7_EE+0x3e0): undefined reference to `__atomic_fetch_add_8'
collect2: error: ld returned 1 exit status
gmake[2]: *** [lib/ExecutionEngine/Orc/CMakeFiles/LLVMOrcJIT.dir/build.make:659: lib/libLLVMOrcJIT.so.14] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:13868: lib/ExecutionEngine/Orc/CMakeFiles/LLVMOrcJIT.dir/all] Error 2
gmake: *** [Makefile:171: all] Error 2

Diff Detail

Event Timeline

414owen created this revision.Apr 10 2023, 6:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 6:32 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
414owen updated this revision to Diff 512136.Apr 10 2023, 6:46 AM

Added better git commit description

414owen retitled this revision from fix: Link atomic in ORC on platforms that need it to fix: Link `atomic` into LLVMOrcJIT on platforms without hardware support for atomics.Apr 10 2023, 6:49 AM
414owen edited the summary of this revision. (Show Details)
414owen published this revision for review.Apr 10 2023, 6:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 6:52 AM
lhames accepted this revision.Apr 10 2023, 11:31 AM

Thanks very much @414owen!

Do you have commit access? If not then please just let me know what name and email you'd like me to use for attribution and I can commit on your behalf.

This revision is now accepted and ready to land.Apr 10 2023, 11:31 AM

Hi @lhames,
No, I don't have commit access (I created an account just to post this diff really).
You can use "Owen Shepherd <owen@owen.cafe>" for the attribution.

I let the build run for a bit and got another similar error, but I'm not sure which cmake file to add the fix to in the next case:

[ 70%] Linking CXX shared library ../../../lib/liblldCOFF.so
/usr/bin/ld: CMakeFiles/lldCOFF.dir/DebugTypes.cpp.o: in function `void llvm::function_ref<void (unsigned int)>::callback_fn<lld::coff::TypeMerger::mergeTypesWithGHash()::{lambda(unsigned int)#3}>(int, unsigned int)':
DebugTypes.cpp:(.text._ZN4llvm12function_refIFvjEE11callback_fnIZN3lld4coff10TypeMerger19mergeTypesWithGHashEvEUljE1_EEvij+0x11c): undefined reference to `__atomic_load_8'
/usr/bin/ld: DebugTypes.cpp:(.text._ZN4llvm12function_refIFvjEE11callback_fnIZN3lld4coff10TypeMerger19mergeTypesWithGHashEvEUljE1_EEvij+0x1e4): undefined reference to `__atomic_compare_exchange_8'
collect2: error: ld returned 1 exit status
gmake[2]: *** [tools/lld/COFF/CMakeFiles/lldCOFF.dir/build.make:380: lib/liblldCOFF.so.14] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:17562: tools/lld/COFF/CMakeFiles/lldCOFF.dir/all] Error 2
gmake: *** [Makefile:171: all] Error 2

Any pointers?

My first guess would be llvm-project/lld/COFF/CMakeLists.txt, but it's worth double-checking that with an LLD reviewer.

I'm just rebuilding to test this locally now and hope to have it committed shortly.

You should be able to use the mechanism from https://github.com/llvm/llvm-project/commit/fa981b541365190ae646d2dce575706cd0626cf7 instead for both the original change here and any future changes?