32-bit powerpc system-clang based builds of devel/llvm40 and devel/llvm50: fails via "Host compiler appears to require libatomic, but cannot find it"

Mark Millard markmi at dsl-only.net
Tue Dec 5 23:23:26 UTC 2017


On 2017-Dec-5, at 12:39 PM, Roman Divacky <rdivacky at vlakno.cz> wrote:

> The cmake test just tries to compile:
> 
> #include <atomic>
> std::atomic<int> x;
> int main() {
>  return x;
> }
> 
> What happens if you try to compile this small code with your host compiler?
> 
> Roman

[I later show that it seems to be testing
with: std::atomic<uint64_t> x (0) instead
and is also using a line the example does
not have (devel/llvm50 example):

  uint64_t i = x.load(std::memory_order_relaxed);
.]

# uname -apKU
FreeBSD FBSDG4S 12.0-CURRENT FreeBSD 12.0-CURRENT  r326192M  powerpc powerpc 1200054 1200054

# more cpp_atomic.cpp 
#include <atomic>
std::atomic<int> x;
int main() {
 return x;
}

# clang++ -v cpp_atomic.cpp
FreeBSD clang version 5.0.0 (tags/RELEASE_500/final 312559) (based on LLVM 5.0.0svn)
Target: powerpc-unknown-freebsd12.0
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/clang++" -cc1 -triple powerpc-unknown-freebsd12.0 -emit-obj -mrelax-all -disable-free -main-file-name cpp_atomic.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu ppc -mfloat-abi hard -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/lib/clang/5.0.0 -internal-isystem /usr/include/c++/v1 -fdeprecated-macro -fdebug-compilation-dir /root/c_tests -ferror-limit 19 -fmessage-length 200 -fno-signed-char -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/cpp_atomic-3b1ae2.o -x c++ cpp_atomic.cpp
clang -cc1 version 5.0.0 based upon LLVM 5.0.0svn default target powerpc-unknown-freebsd12.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/v1
 /usr/lib/clang/5.0.0/include
 /usr/include
End of search list.
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --enable-new-dtags -m elf32ppc_fbsd -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/cpp_atomic-3b1ae2.o -lc++ -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o

# ./a.out
#

So, the example works fine.

Nothing about that example program would seem to
match the note:

-- Looking for __atomic_load_8 in atomic

I would guess that the __atomic_load_8 test
is somewhat different. . .

Looking at an expansion of a wrkdirs' .tbz that
poudriere produced, CheckAtomic.cmake has . . .

. . .
# Check for 64 bit atomic operations.
if(MSVC)
  set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True)
else()
  check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
endif()

# If not, check if the library exists, and atomics work with it.
if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
  check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
  if(HAVE_CXX_LIBATOMICS64)
    list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
    check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
    if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
      message(FATAL_ERROR "Host compiler must support std::atomic!")
    endif()
  else()
    message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
  endif()
endif()
. . .

From this I get:

A) check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
   set: NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB

B) check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
   set: NOT HAVE_CXX_LIBATOMICS64

For (A), looking at the test code (found by
name-text matching):

function(check_working_cxx_atomics64 varname)
  set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}")
  CHECK_CXX_SOURCE_COMPILES("
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x (0);
int main() {
  uint64_t i = x.load(std::memory_order_relaxed);
  return 0;
}
" ${varname})
  set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction(check_working_cxx_atomics64)

I see:

#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x (0);
int main() {
  uint64_t i = x.load(std::memory_order_relaxed);
  return 0;
}

Trying that example I see:

/tmp/cpp_atomic_64_test-1fa999.o: In function `main':
cpp_atomic_64_test.cpp:(.text+0xa8): undefined reference to `__atomic_load_8'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Details:

# more cpp_atomic_64_test.cpp 
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x (0);
int main() {
  uint64_t i = x.load(std::memory_order_relaxed);
  return 0;
}

# clang++ -v cpp_atomic_64_test.cpp 
FreeBSD clang version 5.0.0 (tags/RELEASE_500/final 312559) (based on LLVM 5.0.0svn)
Target: powerpc-unknown-freebsd12.0
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/clang++" -cc1 -triple powerpc-unknown-freebsd12.0 -emit-obj -mrelax-all -disable-free -main-file-name cpp_atomic_64_test.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu ppc -mfloat-abi hard -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/lib/clang/5.0.0 -internal-isystem /usr/include/c++/v1 -fdeprecated-macro -fdebug-compilation-dir /root/c_tests -ferror-limit 19 -fmessage-length 200 -fno-signed-char -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/cpp_atomic_64_test-1fa999.o -x c++ cpp_atomic_64_test.cpp
clang -cc1 version 5.0.0 based upon LLVM 5.0.0svn default target powerpc-unknown-freebsd12.0
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/v1
 /usr/lib/clang/5.0.0/include
 /usr/include
End of search list.
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --enable-new-dtags -m elf32ppc_fbsd -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/lib /tmp/cpp_atomic_64_test-1fa999.o -lc++ -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o
/tmp/cpp_atomic_64_test-1fa999.o: In function `main':
cpp_atomic_64_test.cpp:(.text+0xa8): undefined reference to `__atomic_load_8'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)



> On Tue, Dec 05, 2017 at 10:42:49AM -0800, Mark Millard wrote:
>> [I experiment with system-clang based
>> buildworld and/or buildkernel based
>> TARGET_ARCH=powerpc64 and
>> TARGET_ARCH=powerpc environments.]
>> 
>> For TARGET_ARCH=powerpc devel/llvm40 and
>> devel/llvm50 get failure reports like:
>> 
>> -- Looking for __atomic_load_8 in atomic - not found
>> CMake Error at cmake/modules/CheckAtomic.cmake:74 (message):
>>  Host compiler appears to require libatomic, but cannot find it.
>> Call Stack (most recent call first):
>>  cmake/config-ix.cmake:307 (include)
>>  CMakeLists.txt:582 (include)
>> 
>> 
>> I had tried to avoid any need for 8-Byte atomics
>> (among other things) by avoiding LIT, LLD, and LLDB:
>> 
>> # more /usr/local/etc/poudriere.d/options/devel_llvm50/options
>> # This file is auto-generated by 'make config'.
>> # Options for llvm50-5.0.0_1
>> _OPTIONS_READ=llvm50-5.0.0_1
>> _FILE_COMPLETE_OPTIONS_LIST=CLANG DOCS EXTRAS LIT LLD LLDB
>> OPTIONS_FILE_SET+=CLANG
>> OPTIONS_FILE_SET+=DOCS
>> OPTIONS_FILE_SET+=EXTRAS
>> OPTIONS_FILE_UNSET+=LIT
>> OPTIONS_FILE_UNSET+=LLD
>> OPTIONS_FILE_UNSET+=LLDB
>> 
>> # more /usr/local/etc/poudriere.d/options/devel_llvm40/options
>> # This file is auto-generated by 'make config'.
>> # Options for llvm40-4.0.1_1
>> _OPTIONS_READ=llvm40-4.0.1_1
>> _FILE_COMPLETE_OPTIONS_LIST=CLANG DOCS EXTRAS LIT LLD LLDB
>> OPTIONS_FILE_SET+=CLANG
>> OPTIONS_FILE_SET+=DOCS
>> OPTIONS_FILE_SET+=EXTRAS
>> OPTIONS_FILE_UNSET+=LIT
>> OPTIONS_FILE_UNSET+=LLD
>> OPTIONS_FILE_UNSET+=LLDB
>> 
>> For clang-based buildworld avoiding such things
>> prevents running into the 8-Byte atomics based
>> build failures:
>> 
>> WITH_LIBCPLUSPLUS=
>> WITH_BINUTILS_BOOTSTRAP=
>> WITH_ELFTOOLCHAIN_BOOTSTRAP=
>> #WITH_CLANG_BOOTSTRAP=
>> WITH_CLANG=
>> WITH_CLANG_IS_CC=
>> WITH_CLANG_FULL=
>> WITH_CLANG_EXTRAS=
>> WITH_LLD=
>> # lldb requires missing atomic 8-byte operations for powerpc (non-64)
>> WITHOUT_LLDB=
>> #
>> WITH_BOOT=
>> 
>> (Note: buildkernel currently fails.)
>> 
>> # clang++ --version
>> FreeBSD clang version 5.0.0 (tags/RELEASE_500/final 312559) (based on LLVM 5.0.0svn)
>> Target: powerpc-unknown-freebsd12.0
>> Thread model: posix
>> InstalledDir: /usr/bin
>> 
>> # uname -apKU
>> FreeBSD FBSDG4S 12.0-CURRENT FreeBSD 12.0-CURRENT  r326192M  powerpc powerpc 1200054 1200054
>> 
>> # svnlite info /usr/ports/ | grep "Re[plv]"
>> Relative URL: ^/head
>> Repository Root: https://svn.freebsd.org/ports
>> Repository UUID: 35697150-7ecd-e111-bb59-0022644237b5
>> Revision: 455204
>> Last Changed Rev: 455204
> 


Side note: I see that you have been working on the
powerpc/powerpc64 problem for generating libraries
to handle thrown C++ exceptions, even making the
problem description better/more-detailed/specific
for the llvm bugzilla entry, now:

__builtin_eh_return is not implemented for PPC nor PPC64

and referencing a start at changes for this:

I have a WIP patch at http://vlakno.cz/~rdivacky/ppc64.eh_return.patch
if anyone wants to take a look and finish it.



Cool --and thanks!


===
Mark Millard
markmi at dsl-only.net



More information about the freebsd-ports mailing list