This is an archive of the discontinued LLVM Phabricator instance.

[lld] [CMake] Link liblldCOFF against libatomic when necessary
ClosedPublic

Authored by thesamesam on Oct 19 2022, 12:11 PM.

Details

Summary

Also simplify code for liblldCommon using the new LLVM_ATOMIC_LIB variable.

Depends on D136280.

Bug: https://bugs.gentoo.org/832675
Thanks-to: Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Tested-by: erhard_f@mailbox.org <erhard_f@mailbox.org>

Diff Detail

Event Timeline

thesamesam created this revision.Oct 19 2022, 12:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 12:11 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
thesamesam requested review of this revision.Oct 19 2022, 12:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 12:11 PM

std::atomic seems to be used in ELF and MachO libs as well; though maybe libatomic isn't needed for these types?

std::atomic seems to be used in ELF and MachO libs as well; though maybe libatomic isn't needed for these types?

lld-15.0.2:20221005-094634.log (from https://bugs.gentoo.org/832675) says that this is the place where linking is needed:

/usr/lib/gcc/powerpc-unknown-linux-gnu/11.3.1/../../../../powerpc-unknown-linux-gnu/bin/ld: COFF/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+0x250): undefined reference to `__atomic_load_8'
/usr/lib/gcc/powerpc-unknown-linux-gnu/11.3.1/../../../../powerpc-unknown-linux-gnu/bin/ld: DebugTypes.cpp:(.text._ZN4llvm12function_refIFvjEE11callback_fnIZN3lld4coff10TypeMerger19mergeTypesWithGHashEvEUljE1_EEvij+0x284): undefined reference to `__atomic_compare_exchange_8'
/usr/lib/gcc/powerpc-unknown-linux-gnu/11.3.1/../../../../powerpc-unknown-linux-gnu/bin/ld: DebugTypes.cpp:(.text._ZN4llvm12function_refIFvjEE11callback_fnIZN3lld4coff10TypeMerger19mergeTypesWithGHashEvEUljE1_EEvij+0x364): undefined reference to `__atomic_compare_exchange_8'
collect2: error: ld returned 1 exit status

After fixing of liblldCOFF, there were no other errors during building of LLD.

mgorny accepted this revision.Oct 20 2022, 6:08 AM

I suppose this makes sense. Worst case, we can add it elsewhere later.

This revision is now accepted and ready to land.Oct 20 2022, 6:08 AM
This revision was automatically updated to reflect the committed changes.

I don't think 32-bit PPC has 64-bit atomics at all, so calling libatomic is expected. (Compare with D123872, where we were using libatomic when it shouldn't have been necessary.)

If the performance is important, we might want to look at changing the code to avoid 64-bit atomics. I see 64-bit std::atomic types in lld/COFF/DebugTypes.cpp, lld/MachO/ICF.cpp, and lld/include/lld/Common/Timer.h .