[PATCH] D44373: Fix reading objects created with -fembed-bitcode-marker.

Nicholas Allegra via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 11 16:30:44 PDT 2018


comex created this revision.
comex added a reviewer: pcc.

Currently, this fails with many tools, e.g.

$ clang -fembed-bitcode-marker -c -o test.o test.c
$ nm test.o
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: test.o The file was not recognized as a valid object file

-fembed-bitcode-marker creates a __LLVM,__bitcode section consisting of a single byte.  When reading the object file, IRObjectFile::findBitcodeInObject succeeds, causing SymbolicFile::createSymbolicFile to try to read the "bitcode" rather than using the outer Mach-O data - when then fails.

Fix this by making findBitcodeInObject return an error if the section size <= 1.


Repository:
  rL LLVM

https://reviews.llvm.org/D44373

Files:
  lib/Object/IRObjectFile.cpp
  test/Object/Inputs/macho-bitcode-marker-x86_64.o
  test/Object/Inputs/macho-bitcode-x86_64.o
  test/Object/nm-bitcode.test


Index: test/Object/nm-bitcode.test
===================================================================
--- /dev/null
+++ test/Object/nm-bitcode.test
@@ -0,0 +1,12 @@
+# Inputs generated with:
+# echo 'int hello() { return 5; }' > test.c
+# clang -O -fembed-bitcode -c -o macho-bitcode-x86_64.o test.c
+# clang -O -fembed-bitcode-marker -c -o macho-bitcode-marker-x86_64.o test.c
+
+RUN: llvm-nm -a %p/Inputs/macho-bitcode-x86_64.o \
+RUN:         | FileCheck %s
+
+RUN: llvm-nm -a %p/Inputs/macho-bitcode-marker-x86_64.o \
+RUN:         | FileCheck %s
+
+CHECK: T _hello
Index: lib/Object/IRObjectFile.cpp
===================================================================
--- lib/Object/IRObjectFile.cpp
+++ lib/Object/IRObjectFile.cpp
@@ -79,6 +79,8 @@
       StringRef SecContents;
       if (std::error_code EC = Sec.getContents(SecContents))
         return errorCodeToError(EC);
+      if (SecContents.size() <= 1)
+        return errorCodeToError(object_error::bitcode_section_not_found);
       return MemoryBufferRef(SecContents, Obj.getFileName());
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44373.137959.patch
Type: text/x-patch
Size: 1072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180311/f709faec/attachment.bin>


More information about the llvm-commits mailing list