diff --git a/compiler-rt/cmake/caches/AIX.cmake b/compiler-rt/cmake/caches/AIX.cmake new file mode 100644 --- /dev/null +++ b/compiler-rt/cmake/caches/AIX.cmake @@ -0,0 +1,9 @@ +set(CMAKE_BUILD_TYPE Release CACHE STRING "") +set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "") +set(CMAKE_SHARED_LINKER_FLAGS + "-Wl,-H512 -Wl,-D0 -Wl,-T512 -Wl,-bhalt:4 -Wl,-bernotok -Wl,-bnoentry \ + -Wl,-bexport:${AIX_LIBATOMIC_EXPORT_LIST} \ + -Wl,bmodetype:SRE -Wl,-lc" + CACHE STRING "") + +set(COMPILER_RT_BUILD_LIBATOMIC ON CACHE BOOL "") diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -747,4 +747,12 @@ endforeach () endif () +if (COMPILER_RT_BUILD_LIBATOMIC) + add_compiler_rt_runtime(clang_rt.atomic + SHARED + ARCHS ${BUILTIN_SUPPORTED_ARCH} + SOURCES atomic.c + PARENT_TARGET builtins) +endif() + add_dependencies(compiler-rt builtins) diff --git a/compiler-rt/utils/aix-install-libatomic.sh b/compiler-rt/utils/aix-install-libatomic.sh new file mode 100755 --- /dev/null +++ b/compiler-rt/utils/aix-install-libatomic.sh @@ -0,0 +1,169 @@ +#!/usr/bin/env bash +#===----------------------------------------------------------------------===## +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +#===----------------------------------------------------------------------===## + +set -e + +PROGNAME="$(basename "${0}")" + +function error() { printf "error: %s\n" "$*"; exit 1; } + +function usage() { +cat < Path to the root of the LLVM monorepo. Only the compiler-rt + directory is required. + +--build-dir Path to the directory to use for building. This will + contain intermediate build products. + +--install-dir Path to the directory to install the library to. + +--cache The CMake cache to use to control how the library gets built. +EOF +} + +while [[ $# -gt 0 ]]; do + case ${1} in + -h|--help) + usage + exit 0 + ;; + --llvm-root) + llvm_root="${2}" + shift; shift + ;; + --build-dir) + build_dir="${2}" + shift; shift + ;; + --install-dir) + install_dir="${2}" + shift; shift + ;; + --cache) + cache="${2}" + shift; shift + ;; + *) + error "Unknown argument '${1}'" + ;; + esac +done + +for arg in llvm_root build_dir install_dir cache; do + if [ -z ${!arg+x} ]; then + error "Missing required argument '--${arg//_/-}'" + elif [ "${!arg}" == "" ]; then + error "Argument to --${arg//_/-} must not be empty" + fi +done + +# Allow using relative paths +function realpath() { + if [[ $1 = /* ]]; then echo "$1"; else echo "$(pwd)/${1#./}"; fi +} + +for arg in llvm_root build_dir install_dir cache; do + path="$(realpath "${!arg}")" + eval "${arg}=\"${path}\"" +done + +function step() { + separator="$(printf "%0.s-" $(seq 1 ${#1}))" + echo + echo "${separator}" + echo "${1}" + echo "${separator}" +} + +step "Generating export list" +exported_routines=$(cat < "${export_list}" + +cmake_path=/xl_le/gsa/tlbgsa/projects/x/xlcmpbld/bld_env/aix/cmake-3.15.7/bin/cmake +step "Building libclang_rt.atomic-.so" +(cd ${build_dir} && \ + ${cmake_path} "${llvm_root}/llvm" \ + -DAIX_LIBATOMIC_EXPORT_LIST="${export_list}" \ + -C "${cache}" \ + -GNinja \ + -DLLVM_ENABLE_RUNTIMES="compiler-rt" \ + -DLLVM_INSTALL_PREFIX="${install_dir}" +) && \ +${cmake_path} --build "${build_dir}" --target install-builtins + +step "Archive built libclang_rt.atomic-.so into single libatomic.a" +# FIXME: Clang's version is undetermined, use wildcard to match. +atomic_32=$(find \ + ${install_dir}/lib/clang/*/lib/aix/ \ + -name libclang_rt.atomic-powerpc.so) +if [[ -s "${atomic_32}" ]] +then + cp "${atomic_32}" "${build_dir}/libatomic.so.1" + ar -X32 r "$(dirname "${atomic_32}")/libatomic.a" "${build_dir}/libatomic.so.1" +fi + +atomic_64=$(find \ + ${install_dir}/lib/clang/*/lib/aix/ \ + -name libclang_rt.atomic-powerpc64.so) +if [[ -s "${atomic_64}" ]] +then + cp "${atomic_64}" "${build_dir}/libatomic.so.1" + ar -X64 r "$(dirname "${atomic_64}")/libatomic.a" "${build_dir}/libatomic.so.1" +fi + +rm -f "${build_dir}/libatomic.so.1"