[PATCH] D17388: Rename embedded bitcode section in MachO

Steven Wu via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 18 09:32:28 PST 2016


steven_wu created this revision.
steven_wu added a reviewer: rafael.
steven_wu added a subscriber: llvm-commits.
Herald added a subscriber: joker.eph.

Rename the section embeds bitcode from ".llvmbc,.llvmbc" to "__LLVM,__bitcode".
The new name matches MachO section naming convention.

http://reviews.llvm.org/D17388

Files:
  docs/BitCodeFormat.rst
  include/llvm/Object/ObjectFile.h
  lib/Object/FunctionIndexObjectFile.cpp
  lib/Object/IRObjectFile.cpp
  lib/Object/ObjectFile.cpp
  test/LTO/X86/Inputs/bcsection.macho.s

Index: test/LTO/X86/Inputs/bcsection.macho.s
===================================================================
--- test/LTO/X86/Inputs/bcsection.macho.s
+++ test/LTO/X86/Inputs/bcsection.macho.s
@@ -1,2 +1,2 @@
-.section .llvmbc,.llvmbc
+.section __LLVM,__bitcode
 .incbin "bcsection.bc"
Index: lib/Object/ObjectFile.cpp
===================================================================
--- lib/Object/ObjectFile.cpp
+++ lib/Object/ObjectFile.cpp
@@ -114,3 +114,10 @@
 
   return OwningBinary<ObjectFile>(std::move(Obj), std::move(Buffer));
 }
+
+const char* ObjectFile::getSectionNameForBitcode(const ObjectFile &Obj) {
+  if (Obj.isMachO())
+    return "__bitcode";
+  else
+    return ".llvmbc";
+}
Index: lib/Object/IRObjectFile.cpp
===================================================================
--- lib/Object/IRObjectFile.cpp
+++ lib/Object/IRObjectFile.cpp
@@ -264,11 +264,12 @@
 }
 
 ErrorOr<MemoryBufferRef> IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
+  const char* BitcodeSectName = ObjectFile::getSectionNameForBitcode(Obj);
   for (const SectionRef &Sec : Obj.sections()) {
     StringRef SecName;
     if (std::error_code EC = Sec.getName(SecName))
       return EC;
-    if (SecName == ".llvmbc") {
+    if (SecName == BitcodeSectName) {
       StringRef SecContents;
       if (std::error_code EC = Sec.getContents(SecContents))
         return EC;
Index: lib/Object/FunctionIndexObjectFile.cpp
===================================================================
--- lib/Object/FunctionIndexObjectFile.cpp
+++ lib/Object/FunctionIndexObjectFile.cpp
@@ -34,11 +34,12 @@
 
 ErrorOr<MemoryBufferRef>
 FunctionIndexObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
+  const char* BitcodeSectName = ObjectFile::getSectionNameForBitcode(Obj);
   for (const SectionRef &Sec : Obj.sections()) {
     StringRef SecName;
     if (std::error_code EC = Sec.getName(SecName))
       return EC;
-    if (SecName == ".llvmbc") {
+    if (SecName == BitcodeSectName) {
       StringRef SecContents;
       if (std::error_code EC = Sec.getContents(SecContents))
         return EC;
Index: include/llvm/Object/ObjectFile.h
===================================================================
--- include/llvm/Object/ObjectFile.h
+++ include/llvm/Object/ObjectFile.h
@@ -296,6 +296,9 @@
 
   static ErrorOr<std::unique_ptr<MachOObjectFile>>
   createMachOObjectFile(MemoryBufferRef Object);
+
+  static const char* getSectionNameForBitcode(const ObjectFile &Obj);
+
 };
 
 // Inline function definitions.
Index: docs/BitCodeFormat.rst
===================================================================
--- docs/BitCodeFormat.rst
+++ docs/BitCodeFormat.rst
@@ -467,10 +467,11 @@
 =================================
 
 Bitcode files for LLVM IR may also be wrapped in a native object file
-(i.e. ELF, COFF, Mach-O).  The bitcode must be stored in a section of the
-object file named ``.llvmbc``.  This wrapper format is useful for accommodating
-LTO in compilation pipelines where intermediate objects must be native object
-files which contain metadata in other sections.
+(i.e. ELF, COFF, Mach-O).  The bitcode must be stored in a section of the object
+file named ``__LLVM,__bitcode`` for MachO and ``.llvmbc`` for the other object
+formats.  This wrapper format is useful for accommodating LTO in compilation
+pipelines where intermediate objects must be native object files which contain
+metadata in other sections.
 
 Not all tools support this format.
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17388.48343.patch
Type: text/x-patch
Size: 3487 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160218/3fa859db/attachment-0001.bin>


More information about the llvm-commits mailing list