This is an archive of the discontinued LLVM Phabricator instance.

Replace std::call_once with llvm:call_once
ClosedPublic

Authored by krytarowski on May 24 2017, 10:55 AM.

Details

Summary

This is required on some platforms, as GNU libstdc++ std::call_once is known to be buggy.

This fixes operation of LLD on at least NetBSD and perhaps OpenBSD and Linux PowerPC.

The same change has been introduced to LLVM and LLDB.

Diff Detail

Repository
rL LLVM

Event Timeline

krytarowski created this revision.May 24 2017, 10:55 AM
chieftec$ lldb -c ./lld.core /usr/pkg/bin/lld 
(lldb) target create "/usr/pkg/bin/lld" --core "./lld.core"
Core file '/tmp/./lld.core' (x86_64) was loaded.
(lldb) bt
* thread #1, stop reason = signal SIGSEGV
  * frame #0: 0x0000000000000000
    frame #1: 0x00007555e8806b6e libpthread.so.1`pthread_once(once_control=0x00007555e8796210, routine=(libstdc++.so.7`std::__once_proxy() at mutex.cc:78)) at pthread_once.c:63
    frame #2: 0x0000000000575f75 ld.lld`::__gthread_once(__once=0x00007555e8796210, __func=(libstdc++.so.7`std::__once_proxy() at mutex.cc:78))()) at gthr-default.h:699
    frame #3: 0x000000000057d6d4 ld.lld`std::call_once<lld::elf::MergeInputSection::getOffset(__uint64_t) const::<lambda()> >(__once=0x00007555e8796210, __f=0x00007555e4ffaa30)> &&const) at mutex:738
    frame #4: 0x0000000000578790 ld.lld`lld::elf::MergeInputSection::getOffset(this=0x00007555e8796130, Offset=32) const at InputSection.cpp:873
    frame #5: 0x0000000000576cd5 ld.lld`lld::elf::SectionBase::getOffset(this=0x00007555e8796130, Offset=32) const at InputSection.cpp:142
    frame #6: 0x00000000005f5772 ld.lld`::getSymVA(Body=0x00007555e879f318, Addend=0x00007555e4ffaba0) at Symbols.cpp:91
    frame #7: 0x00000000005f5ba9 ld.lld`lld::elf::SymbolBody::getVA(this=0x00007555e879f318, Addend=-4) const at Symbols.cpp:162
    frame #8: 0x0000000000577889 ld.lld`::getRelocTargetVA(Type=2, A=-4, P=4195950, Body=0x00007555e879f318, Expr=R_PC) at InputSection.cpp:488
    frame #9: 0x0000000000577d2f ld.lld`lld::elf::InputSectionBase::relocateAlloc(this=0x00007555e8795000, Buf="H\x83��H\x83H\x89�H\x89�H\x89��", BufEnd="\x80=\x88\x19") at InputSection.cpp:623
    frame #10: 0x00000000005800ad ld.lld`void lld::elf::InputSectionBase::relocate<llvm::object::ELFType<(llvm::support::endianness)1, true> >(this=0x00007555e8795000, Buf="H\x83��H\x83H\x89�H\x89�H\x89��", BufEnd="\x80=\x88\x19") at InputSection.cpp:595
    frame #11: 0x000000000057c352 ld.lld`void lld::elf::InputSection::writeTo<llvm::object::ELFType<(llvm::support::endianness)1, true> >(this=0x00007555e8795000, Buf="H\x83��H\x83H\x89�H\x89�H\x89��") at InputSection.cpp:685
    frame #12: 0x00000000005b3c2b ld.lld`void lld::elf::OutputSection::writeTo<llvm::object::ELFType<(llvm::support::endianness)1, true> >(__closure=0x00007555e7f483e0, I=0)::'lambda'(unsigned long)::operator()(unsigned long) const at OutputSections.cpp:302
    frame #13: 0x00000000005b565b ld.lld`std::_Function_handler<void (unsigned long), void lld::elf::OutputSection::writeTo<llvm::object::ELFType<(llvm::support::endianness)1, true> >(unsigned char*)::'lambda'(unsigned long)>::_M_invoke(__functor=0x00007f7fffe44440, __args#0=0x00007555e4ffadc0) at functional:1871
    frame #14: 0x000000000052604b ld.lld`std::function<void (unsigned long)>::operator(this=0x00007f7fffe44440, __args#0=0)(unsigned long) const at functional:2267
    frame #15: 0x0000000000525e4d ld.lld`void llvm::parallel::detail::parallel_for_each_n<unsigned long, std::function<void (unsigned long)> >(__closure=0x00007555e4103060)>)::'lambda'()::operator()() const at Parallel.h:179
    frame #16: 0x0000000000529756 ld.lld`std::_Function_handler<void (), void llvm::parallel::detail::parallel_for_each_n<unsigned long, std::function<void (unsigned long)> >(unsigned long, unsigned long, std::function<void (unsigned long)>)::'lambda'()>::_M_invoke(__functor=0x00007555e4101050) at functional:1871
    frame #17: 0x000000000048c1ae ld.lld`std::function<void ()>::operator(this=0x00007555e4101050)() const at functional:2267
    frame #18: 0x0000000001f62c76 ld.lld`operator(__closure=0x00007555e4101050) at Parallel.cpp:134
    frame #19: 0x0000000001f63886 ld.lld`std::_Function_handler<void(), llvm::parallel::detail::TaskGroup::spawn(std::function<void()>)::<lambda()> >::_M_invoke(__functor=0x00007555e4ffaed0) at functional:1871
    frame #20: 0x000000000048c1ae ld.lld`std::function<void ()>::operator(this=0x00007555e4ffaed0)() const at functional:2267
    frame #21: 0x0000000001f62bb1 ld.lld`(anonymous namespace)::ThreadPoolExecutor::work(this=0x000000000301c320) const at Parallel.cpp:111
    frame #22: 0x0000000001f62809 ld.lld`operator(__closure=0x00007555e7b01178) at Parallel.cpp:80
    frame #23: 0x0000000001f66a74 ld.lld`std::_Bind_simple<(anonymous namespace)::ThreadPoolExecutor::ThreadPoolExecutor(unsigned int)::<lambda()>::<lambda()>()>::_M_invoke<>(this=0x00007555e7b01178, (null)=_Index_tuple<> @ 0x00007555e4ffaf60) const at functional:1531
    frame #24: 0x0000000001f6697f ld.lld`std::_Bind_simple<(anonymous namespace)::ThreadPoolExecutor::ThreadPoolExecutor(unsigned int)::<lambda()>::<lambda()>()>::operator(this=0x00007555e7b01178)() const at functional:1520
    frame #25: 0x0000000001f668d2 ld.lld`std::thread::_Impl<std::_Bind_simple<(anonymous namespace)::ThreadPoolExecutor::ThreadPoolExecutor(unsigned int)::<lambda()>::<lambda()>()> >::_M_run(this=0x00007555e7b01160) const at thread:115
    frame #26: 0x00007555e74a6d4b libstdc++.so.7`std::execute_native_thread_routine(__p=<unavailable>) at thread.cc:84
    frame #27: 0x00007555e880b6e1 libpthread.so.1`pthread__create_tramp(cookie=0x00007555e7b0b000) at pthread.c:576
    frame #28: 0x00007555e6887d80 libc.so.12
ruiu accepted this revision.May 24 2017, 10:59 AM

LGTM

ELF/InputSection.cpp
26

You don't need this, do you?

This revision is now accepted and ready to land.May 24 2017, 10:59 AM
krytarowski added inline comments.May 24 2017, 11:00 AM
ELF/InputSection.cpp
26

I was trying to follow include-what-you-see. I can drop it on request.

ruiu added inline comments.May 24 2017, 11:01 AM
ELF/InputSection.cpp
26

I have no strong preference. You can keep it.

krytarowski closed this revision.May 24 2017, 11:31 AM