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. Index: include/llvm/Object/ObjectFile.h =================================================================== --- include/llvm/Object/ObjectFile.h +++ include/llvm/Object/ObjectFile.h @@ -296,6 +296,9 @@ static ErrorOr> createMachOObjectFile(MemoryBufferRef Object); + + static const char* getSectionNameForBitcode(const ObjectFile &Obj); + }; // Inline function definitions. Index: lib/Object/FunctionIndexObjectFile.cpp =================================================================== --- lib/Object/FunctionIndexObjectFile.cpp +++ lib/Object/FunctionIndexObjectFile.cpp @@ -34,11 +34,12 @@ ErrorOr 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: lib/Object/IRObjectFile.cpp =================================================================== --- lib/Object/IRObjectFile.cpp +++ lib/Object/IRObjectFile.cpp @@ -264,11 +264,12 @@ } ErrorOr 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/ObjectFile.cpp =================================================================== --- lib/Object/ObjectFile.cpp +++ lib/Object/ObjectFile.cpp @@ -114,3 +114,10 @@ return OwningBinary(std::move(Obj), std::move(Buffer)); } + +const char* ObjectFile::getSectionNameForBitcode(const ObjectFile &Obj) { + if (Obj.isMachO()) + return "__bitcode"; + else + return ".llvmbc"; +} 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"