Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -103,11 +103,7 @@ # FIXME: Don't write the "local:" line on OpenBSD. # in the export file, also add a linker script to version LLVM symbols (form: LLVM_N.M) add_custom_command(OUTPUT ${native_export_file} - COMMAND echo "LLVM_${LLVM_VERSION_MAJOR} {" > ${native_export_file} - COMMAND grep -q "[[:alnum:]]" ${export_file} && echo " global:" >> ${native_export_file} || : - COMMAND sed -e "s/$/;/" -e "s/^/ /" < ${export_file} >> ${native_export_file} - COMMAND echo " local: *;" >> ${native_export_file} - COMMAND echo "};" >> ${native_export_file} + COMMAND "${Python3_EXECUTABLE}" ${LLVM_MAIN_SRC_DIR}/utils/add_llvm_symbol_exports.py ${LLVM_VERSION_MAJOR} ${export_file} ${native_export_file} DEPENDS ${export_file} VERBATIM COMMENT "Creating export file for ${target_name}") Index: llvm/utils/add_llvm_symbol_exports.py =================================================================== --- /dev/null +++ llvm/utils/add_llvm_symbol_exports.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 + +import os +import sys + +if(len(sys.argv) != 4): + print('usage: ' + sys.argv[0] + ' ') + sys.exit(1) + +with open(sys.argv[3], 'w') as out_fd: + out_fd.write('LLVM_' + sys.argv[1] + ' {\n') + if os.stat(sys.argv[2]).st_size > 0: + out_fd.write(' global:\n') + with open(sys.argv[2], 'r') as in_fd: + for e in in_fd.readlines(): + out_fd.write(' ' + e.rstrip() + ';\n') + out_fd.write(' local: *;\n};\n') + +sys.exit(0)