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

Dave Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 29 23:22:56 PDT 2018


kastiglione created this revision.
kastiglione added reviewers: compnerd, smeenai.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D48798

Files:
  test/tools/llvm-nm/X86/archive-no-llvm-bc.test
  tools/llvm-nm/llvm-nm.cpp


Index: tools/llvm-nm/llvm-nm.cpp
===================================================================
--- tools/llvm-nm/llvm-nm.cpp
+++ tools/llvm-nm/llvm-nm.cpp
@@ -1721,8 +1721,9 @@
     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;
@@ -1754,7 +1755,8 @@
     {
       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);
@@ -1825,7 +1827,7 @@
               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())) {
@@ -1896,7 +1898,7 @@
             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()))
@@ -1963,7 +1965,7 @@
         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()))
Index: test/tools/llvm-nm/X86/archive-no-llvm-bc.test
===================================================================
--- /dev/null
+++ test/tools/llvm-nm/X86/archive-no-llvm-bc.test
@@ -0,0 +1,20 @@
+# RUN: llvm-mc -triple x86_64-apple-macosx10.11 -filetype=obj -o %t.o %s
+# RUN: llvm-ar crs %t.a %t.o
+# RUN: llvm-nm -m -no-llvm-bc %t.a | FileCheck -match-full-lines %s
+
+.section	__DATA,__data
+.globl	_q
+.p2align	2
+_q:
+.long	1
+# CHECK-NOT: ---------------- (LTO,DATA) external _q
+# CHECK: 0000000000000000 (__DATA,__data) external _q
+
+.section	__LLVM,__bitcode
+.p2align	4
+.asciz	"\336\300\027\013\000\000\000\000\024\000\000\000\344\004\000\000\007\000\000\001BC\300\3365\024\000\000\007\000\000\000b\f0$\224\226\246\245\367\327\177O\333>\355\337\275o\377\264\020\005\310\024\000\000\000\000!\f\000\000\000\001\000\000\013\002!\000\002\000\000\000\023\000\000\000\007\201#\221A\310\004I\006\02029\222\001\204\f%\005\b\031\036\004\213b\200\bE\002B\222\013BD\0202\0248\b\030K\n2\"\210H\220\024 CF\210\245\000\0312B\344H\016\220\021!\304PAQ\201\214\341\203\345\212\004\021F\006\211 \000\000\n\000\000\0002\"\210\b d\205\004\023!\244\204\004\023!\343\204\241\220\024\022L\204\214\013\204DL\020\fs\004`@\f\004\000\000\000\000\0234|\300\003;\370\005;\240\2036\b\007x\200\007v(\2076h\207p\030\207w\230\007|\210\0038p\2038\210\0037\200\203\reP\016m\320\016z\360\016m\220\016v@\007z`\007t\320\006\346\200\007p\240\007q \007x\320\006\356\200\007z\020\007v\240\007s \007z`\007t\320\006\263\020\007r\200\007J\017\b\021\022@\206\214\024\021\0014B\230\234\006-\002\004\b\002Xb\203@\341\203\000\000\200,\020\000\006\000\000\0002\036\230\f\031\021L\220\214\t&G\306\004C\242\004\n\241\034\212\000\000\000\261\030\000\000m\000\000\0003\b\200\034\304\341\034f\024\001=\210C8\204\303\214B\200\007yx\007s\230q\f\346\000\017\355\020\016\364\200\0163\fB\036\302\301\035\316\241\034f0\005=\210C8\204\203\033\314\003=\310C=\214\003=\314x\214tp\007{\b\007yH\207pp\007zp\003vx\207p \207\031\314\021\016\354\220\016\3410\017n0\017\343\360\016\360P\0163\020\304\035\336!\034\330!\035\302a\036f0\211;\274\203;\320C9\264\003<\274\203<\204\003;\314\360\024v`\007{h\0077h\207rh\0077\200\207p\220\207p`\007v(\007v\370\005vx\207w\200\207_\b\207q\030\207r\230\207y\230\201,\356\360\016\356\340\016\365\300\016\3540\003b\310\241\034\344\241\034\314\241\034\344\241\034\334a\034\312!\034\304\201\035\312a\006\326\220C9\310C9\230C9\310C9\270\3038\224C8\210\003;\224\303/\274\203<\374\202;\324\003;\260\303\f\307i\207pX\207rp\203th\007x`\207t\030\207t\240\207\031\316S\017\356\000\017\362P\016\344\220\016\343@\017\341 \016\354P\0163 (\035\334\301\036\302A\036\322!\034\334\201\036\334\340\034\344\341\035\352\001\036f\030Q8\260C:\234\203;\314P$v`\007{h\0077`\207wx\007x\230QL\364\220\017\360P\0163\036j\036\312a\034\350!\035\336\301\035~\001\036\344\241\034\314!\035\360a\006T\205\2038\314\303;\260C=\320C9\374\302<\344C;\210\303;\260\303\214\305\n\207y\230\207w\030\207t\b\007z(\007r\000\000\000\000y \000\000+\000\000\000b\036H C\210\f\0319\031$\220\221@\306\310\310h\"P\b\0242\236\030\031!G\310\220Q\034\bQ\000\000J\262\006\000wchar_sizePIC LevelApple LLVM version 9.1.0 (clang-902.0.39.2)\000\000#\b at 0\202\000\b#\b\3000\202\000\0203\fDP\3140\030\3021C0\310H`\2022bc\263ksi{#\253c+s1c\013;\233\033E8\220T\330\330\354\332\\\322\310\312\334\350F\t\022\000\000\000\251\030\000\000\013\000\000\000\013\nr(\207w\200\007zXp\230C=\270\3038\260C9\320\303\202\346\034\306\241\r\350A\036\302\301\035\346!\035\350!\035\336\301\035\000\321\020\000\000\006\000\000\000\007\314<\244\203;\234\003;\224\003=\240\203<\224C8\220\303\001\000\000\000q \000\000\002\000\000\0002\016\020\"\004\000\000\000\000\000\000\000e\f\000\000\035\000\000\000\022\003\224\350\000\000\000\000\000\000\000\000\001\000\000\000\005\000\000\000D\000\000\000\001\000\000\000P\000\000\000\000\000\000\000P\000\000\000\001\000\000\000h\000\000\000\000\000\000\000\006\000\000\000\032\000\000\000 \000\000\000\001\000\000\000#\000\000\000\000\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000!\000\000\000\002\000\000\000\000\000\000\000\001\000\000\000\377\377\377\377\000\004\000\000\000\000\000\000]\f\000\000\f\000\000\000\022\003\224c\000\000\000\000q9.1.0x86_64-apple-macosx10.11.0-_q\000\000\000\000\000\000\000\000\000\000\000\000"
+
+.section	__LLVM,__cmdline
+.p2align	4
+.asciz	"-triple\000x86_64-apple-macosx10.11.0\000-S\000-disable-llvm-passes"
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48798.153614.patch
Type: text/x-patch
Size: 6749 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180630/b61174d5/attachment.bin>


More information about the llvm-commits mailing list