diff --git a/compiler-rt/lib/sanitizer_common/symbolizer/scripts/ar_to_bc.sh b/compiler-rt/lib/sanitizer_common/symbolizer/scripts/ar_to_bc.sh deleted file mode 100755 --- a/compiler-rt/lib/sanitizer_common/symbolizer/scripts/ar_to_bc.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -function usage() { - echo "Usage: $0 INPUT... OUTPUT" - exit 1 -} - -if [ "$#" -le 1 ]; then - usage -fi - -[[ $AR == /* ]] || AR=$PWD/$AR -[[ $LINK == /* ]] || LINK=$PWD/$LINK - -INPUTS= -OUTPUT= -for ARG in $@; do - INPUTS="$INPUTS $OUTPUT" - OUTPUT=$(readlink -f $ARG) -done - -echo Inputs: $INPUTS -echo Output: $OUTPUT - -SCRATCH_DIR=$(mktemp -d) -ln -s $INPUTS $SCRATCH_DIR/ - -pushd $SCRATCH_DIR - -for INPUT in *; do - for OBJ in $($AR t $INPUT); do - $AR x $INPUT $OBJ - if [[ $(file $OBJ) =~ 'LLVM IR bitcode' ]]; then - mv -f $OBJ $(basename $INPUT).$OBJ - else - # Skip $OBJ which may come from an assembly file (e.g. Support/BLAKE3/*.S). - rm -f $OBJ - fi - done -done - -$LINK *.o -o $OUTPUT - -rm -rf $SCRATCH_DIR diff --git a/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh b/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh --- a/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh +++ b/compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh @@ -69,8 +69,8 @@ CXX=$CLANG_DIR/clang++ TBLGEN=$CLANG_DIR/llvm-tblgen OPT=$CLANG_DIR/opt -export AR=$CLANG_DIR/llvm-ar -export LINK=$CLANG_DIR/llvm-link +AR=$CLANG_DIR/llvm-ar +LINK=$CLANG_DIR/llvm-link TARGET_TRIPLE=$($CC -print-target-triple) for F in $CC $CXX $TBLGEN $LINK $OPT $AR; do @@ -165,23 +165,23 @@ LIBCXX_ARCHIVE_DIR=$(dirname $(find $LIBCXX_BUILD -name libc++.a | head -n1)) # Merge all the object files together and copy the resulting library back. -$SCRIPT_DIR/ar_to_bc.sh $LIBCXX_ARCHIVE_DIR/libc++.a \ - $LIBCXX_ARCHIVE_DIR/libc++abi.a \ - $LLVM_BUILD/lib/libLLVMSymbolize.a \ - $LLVM_BUILD/lib/libLLVMObject.a \ - $LLVM_BUILD/lib/libLLVMBinaryFormat.a \ - $LLVM_BUILD/lib/libLLVMDebugInfoDWARF.a \ - $LLVM_BUILD/lib/libLLVMSupport.a \ - $LLVM_BUILD/lib/libLLVMDebugInfoPDB.a \ - $LLVM_BUILD/lib/libLLVMDebugInfoMSF.a \ - $LLVM_BUILD/lib/libLLVMDebugInfoCodeView.a \ - $LLVM_BUILD/lib/libLLVMDebuginfod.a \ - $LLVM_BUILD/lib/libLLVMDemangle.a \ - $LLVM_BUILD/lib/libLLVMMC.a \ - $LLVM_BUILD/lib/libLLVMTextAPI.a \ - $ZLIB_BUILD/libz.a \ - symbolizer.a \ - all.bc +$LINK $LIBCXX_ARCHIVE_DIR/libc++.a \ + $LIBCXX_ARCHIVE_DIR/libc++abi.a \ + $LLVM_BUILD/lib/libLLVMSymbolize.a \ + $LLVM_BUILD/lib/libLLVMObject.a \ + $LLVM_BUILD/lib/libLLVMBinaryFormat.a \ + $LLVM_BUILD/lib/libLLVMDebugInfoDWARF.a \ + $LLVM_BUILD/lib/libLLVMSupport.a \ + $LLVM_BUILD/lib/libLLVMDebugInfoPDB.a \ + $LLVM_BUILD/lib/libLLVMDebugInfoMSF.a \ + $LLVM_BUILD/lib/libLLVMDebugInfoCodeView.a \ + $LLVM_BUILD/lib/libLLVMDebuginfod.a \ + $LLVM_BUILD/lib/libLLVMDemangle.a \ + $LLVM_BUILD/lib/libLLVMMC.a \ + $LLVM_BUILD/lib/libLLVMTextAPI.a \ + $ZLIB_BUILD/libz.a \ + symbolizer.a \ + -ignore-non-bitcode -o all.bc echo "Optimizing..." $OPT -internalize -internalize-public-api-list=${SYMBOLIZER_API_LIST} all.bc -o opt.bc diff --git a/llvm/test/tools/llvm-link/archive-non-bitcode.ll b/llvm/test/tools/llvm-link/archive-non-bitcode.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-link/archive-non-bitcode.ll @@ -0,0 +1,10 @@ +# RUN: llvm-as %S/Inputs/f.ll -o %t.f.bc +# RUN: llvm-as %S/Inputs/g.ll -o %t.g.bc +# RUN: echo "This is not a bitcode file" > %t.not_bitcode.txt +# RUN: llvm-ar cr %t.a %t.f.bc %t.not_bitcode.txt %t.g.bc +# RUN: llvm-ar cr --format=gnu %t.empty.lib +# RUN: llvm-link -ignore-non-bitcode %t.a %t.empty.lib -o %t.linked.bc 2>&1 | FileCheck --check-prefix CHECK_IGNORE_NON_BITCODE %s +# RUN: not llvm-link %t.a %t.empty.lib -o %t.linked2.bc 2>&1 | FileCheck --check-prefix CHECK_ERROR_BITCODE %s + +# CHECK_ERROR_BITCODE: error: member of archive is not a bitcode file +# CHECK_IGNORE_NON_BITCODE-NOT: is not a bitcode file diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp --- a/llvm/tools/llvm-link/llvm-link.cpp +++ b/llvm/tools/llvm-link/llvm-link.cpp @@ -124,6 +124,11 @@ cl::desc("Do not run the verifier"), cl::Hidden, cl::cat(LinkCategory)); +static cl::opt IgnoreNonBitcode( + "ignore-non-bitcode", + cl::desc("Do not report an error for non-bitcode files in archives"), + cl::Hidden); + static ExitOnError ExitOnErr; // Read the specified bitcode file in and return it. This routine searches the @@ -199,6 +204,8 @@ MemBuf.get().getBufferStart()), reinterpret_cast( MemBuf.get().getBufferEnd()))) { + if (IgnoreNonBitcode) + continue; errs() << Argv0 << ": "; WithColor::error() << " member of archive is not a bitcode file: '" << ChildName << "'\n";