[llvm] c4c01e4 - [llvm-nm] Always use opaque pointers (PR55506)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed May 18 00:46:24 PDT 2022
Author: Nikita Popov
Date: 2022-05-18T09:46:14+02:00
New Revision: c4c01e4e4e388a1e3cefc9e3982ac15fb94d4f40
URL: https://github.com/llvm/llvm-project/commit/c4c01e4e4e388a1e3cefc9e3982ac15fb94d4f40
DIFF: https://github.com/llvm/llvm-project/commit/c4c01e4e4e388a1e3cefc9e3982ac15fb94d4f40.diff
LOG: [llvm-nm] Always use opaque pointers (PR55506)
Always enable opaque pointers in llvm-nm, because the tool doesn't
actually care, and this allows us to read both typed pointer and
opaque pointer bitcode files in one archive. Previously this
depended on the order inside the archive (it would work with an
opaque pointer bitcode file first, but fail with a typed pointer
bitcode file first).
Fixes https://github.com/llvm/llvm-project/issues/55506.
Differential Revision: https://reviews.llvm.org/D125751
Added:
llvm/test/tools/llvm-nm/opaque-pointers.ll
Modified:
llvm/tools/llvm-nm/llvm-nm.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-nm/opaque-pointers.ll b/llvm/test/tools/llvm-nm/opaque-pointers.ll
new file mode 100644
index 0000000000000..0bda500f991f6
--- /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
index 0f39333be0284..f0def8b74e608 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -2254,7 +2254,11 @@ static std::vector<NMSymbol> dumpSymbolNamesFromFile(StringRef Filename) {
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<std::unique_ptr<Binary>> BinaryOrErr =
createBinary(BufferOrErr.get()->getMemBufferRef(), ContextPtr);
More information about the llvm-commits
mailing list