2 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
3 # file Copyright.txt or https://cmake.org/licensing for details.
5 # This script is internal to CMake and meant only to be
6 # invoked by CMake-generated build systems on AIX.
8 usage='usage: ExportImportList -o <out-file> -c <compiler> [-l <lib>] [-n] [--] <objects>...'
11 echo "$@" 1>&2; exit 1
14 # Process command-line arguments.
19 while test "$#" != 0; do
21 -l) shift; lib="$1" ;;
22 -o) shift; out="$1" ;;
24 -c) shift; compiler="$1" ;;
31 test -n "$out" || die "$usage"
32 # We need the compiler executable to resolve where the ibm-llvm-nm executable is
33 test -n "$compiler" || die "$usage"
35 # Build a temporary file that atomically replaces the output later.
37 trap 'rm -f "$out_tmp"' EXIT INT TERM
40 # If IPA was enabled and a compiler from the IBMClang family is used, then
41 # the object files contain LLVM bitcode[0] rather than XCOFF objects and so
42 # need to be handled differently.
44 # [0]: https://www.ibm.com/docs/en/openxl-c-and-cpp-aix/17.1.0?topic=compatibility-link-time-optimization-lto
45 NM="$(dirname "$compiler")/../libexec/ibm-llvm-nm"
48 # N4 = first 4 bytes, -tx = output in hexadecimal, -An = don't display offset
49 # cut: trim off the preceding whitespace where the offset would be
50 # 4243code is the hexadecimal magic number for LLVM bitcode
51 [ "$(od -N4 -tx -An $1 | cut -d ' ' -f 2)" == "4243c0de" ];
54 # Collect symbols exported from all object files.
55 if test -z "$no_objects"; then
57 if IsBitcode "$f"; then
58 "$NM" "$f" --defined-only --extern-only --just-symbol-name 2>/dev/null
60 dump -tov -X 32_64 "$f" |
63 V["EXPORTED"]=" export"
64 V["PROTECTED"]=" protected"
66 /^\[[0-9]+\]\tm +[^ ]+ +\.(text|data|bss) +[^ ]+ +(extern|weak) +(EXPORTED|PROTECTED| ) / {
67 if (!match($NF,/^(\.|__sinit|__sterm|__[0-9]+__)/)) {
76 # Generate the export/import file.
78 if test -n "$lib"; then