[llvm] r262245 - Rename embedded bitcode section in MachO
Steven Wu via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 29 11:40:11 PST 2016
Author: steven_wu
Date: Mon Feb 29 13:40:10 2016
New Revision: 262245
URL: http://llvm.org/viewvc/llvm-project?rev=262245&view=rev
Log:
Rename embedded bitcode section in MachO
Summary:
Rename the section embeds bitcode from ".llvmbc,.llvmbc" to "__LLVM,__bitcode".
The new name matches MachO section naming convention.
Reviewers: rafael, pcc
Subscribers: davide, llvm-commits, joker.eph
Differential Revision: http://reviews.llvm.org/D17388
Modified:
llvm/trunk/docs/BitCodeFormat.rst
llvm/trunk/include/llvm/Object/MachO.h
llvm/trunk/include/llvm/Object/ObjectFile.h
llvm/trunk/lib/Object/FunctionIndexObjectFile.cpp
llvm/trunk/lib/Object/IRObjectFile.cpp
llvm/trunk/lib/Object/MachOObjectFile.cpp
llvm/trunk/lib/Object/ObjectFile.cpp
llvm/trunk/test/LTO/X86/Inputs/bcsection.macho.s
Modified: llvm/trunk/docs/BitCodeFormat.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/BitCodeFormat.rst?rev=262245&r1=262244&r2=262245&view=diff
==============================================================================
--- llvm/trunk/docs/BitCodeFormat.rst (original)
+++ llvm/trunk/docs/BitCodeFormat.rst Mon Feb 29 13:40:10 2016
@@ -467,10 +467,11 @@ Native Object File Wrapper Format
=================================
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.
Modified: llvm/trunk/include/llvm/Object/MachO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachO.h?rev=262245&r1=262244&r2=262245&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachO.h (original)
+++ llvm/trunk/include/llvm/Object/MachO.h Mon Feb 29 13:40:10 2016
@@ -226,6 +226,7 @@ public:
bool isSectionData(DataRefImpl Sec) const override;
bool isSectionBSS(DataRefImpl Sec) const override;
bool isSectionVirtual(DataRefImpl Sec) const override;
+ bool isSectionBitcode(DataRefImpl Sec) const override;
relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
relocation_iterator section_rel_end(DataRefImpl Sec) const override;
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=262245&r1=262244&r2=262245&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Mon Feb 29 13:40:10 2016
@@ -94,6 +94,7 @@ public:
bool isData() const;
bool isBSS() const;
bool isVirtual() const;
+ bool isBitcode() const;
bool containsSymbol(SymbolRef S) const;
@@ -219,6 +220,7 @@ protected:
virtual bool isSectionBSS(DataRefImpl Sec) const = 0;
// A section is 'virtual' if its contents aren't present in the object image.
virtual bool isSectionVirtual(DataRefImpl Sec) const = 0;
+ virtual bool isSectionBitcode(DataRefImpl Sec) const;
virtual relocation_iterator section_rel_begin(DataRefImpl Sec) const = 0;
virtual relocation_iterator section_rel_end(DataRefImpl Sec) const = 0;
virtual section_iterator getRelocatedSection(DataRefImpl Sec) const;
@@ -296,6 +298,7 @@ public:
static ErrorOr<std::unique_ptr<MachOObjectFile>>
createMachOObjectFile(MemoryBufferRef Object);
+
};
// Inline function definitions.
@@ -394,6 +397,10 @@ inline bool SectionRef::isVirtual() cons
return OwningObject->isSectionVirtual(SectionPimpl);
}
+inline bool SectionRef::isBitcode() const {
+ return OwningObject->isSectionBitcode(SectionPimpl);
+}
+
inline relocation_iterator SectionRef::relocation_begin() const {
return OwningObject->section_rel_begin(SectionPimpl);
}
Modified: llvm/trunk/lib/Object/FunctionIndexObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/FunctionIndexObjectFile.cpp?rev=262245&r1=262244&r2=262245&view=diff
==============================================================================
--- llvm/trunk/lib/Object/FunctionIndexObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/FunctionIndexObjectFile.cpp Mon Feb 29 13:40:10 2016
@@ -35,10 +35,7 @@ std::unique_ptr<FunctionInfoIndex> Funct
ErrorOr<MemoryBufferRef>
FunctionIndexObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
for (const SectionRef &Sec : Obj.sections()) {
- StringRef SecName;
- if (std::error_code EC = Sec.getName(SecName))
- return EC;
- if (SecName == ".llvmbc") {
+ if (Sec.isBitcode()) {
StringRef SecContents;
if (std::error_code EC = Sec.getContents(SecContents))
return EC;
Modified: llvm/trunk/lib/Object/IRObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRObjectFile.cpp?rev=262245&r1=262244&r2=262245&view=diff
==============================================================================
--- llvm/trunk/lib/Object/IRObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/IRObjectFile.cpp Mon Feb 29 13:40:10 2016
@@ -266,10 +266,7 @@ basic_symbol_iterator IRObjectFile::symb
ErrorOr<MemoryBufferRef> IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
for (const SectionRef &Sec : Obj.sections()) {
- StringRef SecName;
- if (std::error_code EC = Sec.getName(SecName))
- return EC;
- if (SecName == ".llvmbc") {
+ if (Sec.isBitcode()) {
StringRef SecContents;
if (std::error_code EC = Sec.getContents(SecContents))
return EC;
Modified: llvm/trunk/lib/Object/MachOObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/MachOObjectFile.cpp?rev=262245&r1=262244&r2=262245&view=diff
==============================================================================
--- llvm/trunk/lib/Object/MachOObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/MachOObjectFile.cpp Mon Feb 29 13:40:10 2016
@@ -630,6 +630,14 @@ bool MachOObjectFile::isSectionVirtual(D
return false;
}
+bool MachOObjectFile::isSectionBitcode(DataRefImpl Sec) const {
+ StringRef SegmentName = getSectionFinalSegmentName(Sec);
+ StringRef SectName;
+ if (!getSectionName(Sec, SectName))
+ return (SegmentName == "__LLVM" && SectName == "__bitcode");
+ return false;
+}
+
relocation_iterator MachOObjectFile::section_rel_begin(DataRefImpl Sec) const {
DataRefImpl Ret;
Ret.d.a = Sec.d.a;
Modified: llvm/trunk/lib/Object/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=262245&r1=262244&r2=262245&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ObjectFile.cpp Mon Feb 29 13:40:10 2016
@@ -55,6 +55,13 @@ std::error_code ObjectFile::printSymbolN
uint32_t ObjectFile::getSymbolAlignment(DataRefImpl DRI) const { return 0; }
+bool ObjectFile::isSectionBitcode(DataRefImpl Sec) const {
+ StringRef SectName;
+ if (!getSectionName(Sec, SectName))
+ return SectName == ".llvmbc";
+ return false;
+}
+
section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const {
return section_iterator(SectionRef(Sec, this));
}
Modified: llvm/trunk/test/LTO/X86/Inputs/bcsection.macho.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/X86/Inputs/bcsection.macho.s?rev=262245&r1=262244&r2=262245&view=diff
==============================================================================
--- llvm/trunk/test/LTO/X86/Inputs/bcsection.macho.s (original)
+++ llvm/trunk/test/LTO/X86/Inputs/bcsection.macho.s Mon Feb 29 13:40:10 2016
@@ -1,2 +1,5 @@
-.section .llvmbc,.llvmbc
+.section __FOO,__bitcode
+.asciz "Wrong Section"
+
+.section __LLVM,__bitcode
.incbin "bcsection.bc"
More information about the llvm-commits
mailing list