[llvm] r354196 - llvm-nm: Observe -no-llvm-bc for archive members

Dave Lee via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 15 22:59:49 PST 2019


Author: kastiglione
Date: Fri Feb 15 22:59:49 2019
New Revision: 354196

URL: http://llvm.org/viewvc/llvm-project?rev=354196&view=rev
Log:
llvm-nm: Observe -no-llvm-bc for archive members

Summary:
This change fixes the `-no-llvm-bc` flag to work with object files within
archives. Currently the `-no-llvm-bc` flag works for regular object files, but
not static libraries, where it continues to show bitcode symbol info.

Original support was added in D4371.

Reviewers: compnerd, smeenai, pcc

Reviewed By: compnerd

Subscribers: rupprecht, keith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D48798

Added:
    llvm/trunk/test/tools/llvm-nm/X86/archive-no-llvm-bc.test
Modified:
    llvm/trunk/tools/llvm-nm/llvm-nm.cpp

Added: llvm/trunk/test/tools/llvm-nm/X86/archive-no-llvm-bc.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-nm/X86/archive-no-llvm-bc.test?rev=354196&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-nm/X86/archive-no-llvm-bc.test (added)
+++ llvm/trunk/test/tools/llvm-nm/X86/archive-no-llvm-bc.test Fri Feb 15 22:59:49 2019
@@ -0,0 +1,15 @@
+; RUN: rm -rf %t && mkdir -p %t
+; RUN: grep -v "module asm" %s | llvm-as -o %t/embedded.bc
+; RUN: llc -I=%t -filetype=obj -o %t/obj.o %s
+; RUN: llvm-ar crs %t/lib.a %t/obj.o
+; RUN: llvm-nm -m -no-llvm-bc %t/lib.a | FileCheck %s
+
+target triple = "x86_64-apple-macosx10.11"
+
+ at q = global i32 1, align 4
+; CHECK-NOT: {{-+}} (LTO,DATA) external _q
+; CHECK: {{[[:xdigit:]]+}} (__DATA,__data) external _q
+
+module asm ".section __LLVM,__bitcode"
+module asm ".incbin \22embedded.bc\22"
+

Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=354196&r1=354195&r2=354196&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Fri Feb 15 22:59:49 2019
@@ -1737,8 +1737,9 @@ static void dumpSymbolNamesFromFile(std:
     return;
 
   LLVMContext Context;
-  Expected<std::unique_ptr<Binary>> BinaryOrErr = createBinary(
-      BufferOrErr.get()->getMemBufferRef(), NoLLVMBitcode ? nullptr : &Context);
+  LLVMContext *ContextPtr = NoLLVMBitcode ? nullptr : &Context;
+  Expected<std::unique_ptr<Binary>> BinaryOrErr =
+      createBinary(BufferOrErr.get()->getMemBufferRef(), ContextPtr);
   if (!BinaryOrErr) {
     error(BinaryOrErr.takeError(), Filename);
     return;
@@ -1772,7 +1773,8 @@ static void dumpSymbolNamesFromFile(std:
     {
       Error Err = Error::success();
       for (auto &C : A->children(Err)) {
-        Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary(&Context);
+        Expected<std::unique_ptr<Binary>> ChildOrErr =
+            C.getAsBinary(ContextPtr);
         if (!ChildOrErr) {
           if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
             error(std::move(E), Filename, C);
@@ -1843,7 +1845,7 @@ static void dumpSymbolNamesFromFile(std:
               Error Err = Error::success();
               for (auto &C : A->children(Err)) {
                 Expected<std::unique_ptr<Binary>> ChildOrErr =
-                    C.getAsBinary(&Context);
+                    C.getAsBinary(ContextPtr);
                 if (!ChildOrErr) {
                   if (auto E = isNotObjectErrorInvalidFileType(
                                        ChildOrErr.takeError())) {
@@ -1914,7 +1916,7 @@ static void dumpSymbolNamesFromFile(std:
             Error Err = Error::success();
             for (auto &C : A->children(Err)) {
               Expected<std::unique_ptr<Binary>> ChildOrErr =
-                  C.getAsBinary(&Context);
+                  C.getAsBinary(ContextPtr);
               if (!ChildOrErr) {
                 if (auto E = isNotObjectErrorInvalidFileType(
                                      ChildOrErr.takeError()))
@@ -1981,7 +1983,7 @@ static void dumpSymbolNamesFromFile(std:
         Error Err = Error::success();
         for (auto &C : A->children(Err)) {
           Expected<std::unique_ptr<Binary>> ChildOrErr =
-            C.getAsBinary(&Context);
+            C.getAsBinary(ContextPtr);
           if (!ChildOrErr) {
             if (auto E = isNotObjectErrorInvalidFileType(
                                  ChildOrErr.takeError()))




More information about the llvm-commits mailing list