diff --git a/llvm/test/tools/llvm-nm/opaque-pointers.ll b/llvm/test/tools/llvm-nm/opaque-pointers.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-nm/opaque-pointers.ll @@ -0,0 +1,13 @@ +; RUN: llvm-as -opaque-pointers=0 < %s > %t.typed.bc +; RUN: llvm-as -opaque-pointers=1 < %s > %t.opaque.bc +; RUN: llvm-ar cr %t.a %t.typed.bc %t.opaque.bc +; RUN: llvm-nm --just-symbol-name %t.a | FileCheck %s + +; CHECK-LABEL: typed.bc: +; CHECK: test +; CHECK-LABEL: opaque.bc: +; CHECK: test + +define void @test() { + ret void +} diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -2254,7 +2254,11 @@ if (error(BufferOrErr.getError(), Filename)) return SymbolList; + // Always enable opaque pointers, to handle archives with mixed typed and + // opaque pointer bitcode files gracefully. As we're only reading symbols, + // the used pointer types don't matter. LLVMContext Context; + Context.setOpaquePointers(true); LLVMContext *ContextPtr = NoLLVMBitcode ? nullptr : &Context; Expected> BinaryOrErr = createBinary(BufferOrErr.get()->getMemBufferRef(), ContextPtr);