summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2014-05-27 23:20:52 +0000
committerNick Kledzik <kledzik@apple.com>2014-05-27 23:20:52 +0000
commita4a08d31cf041a889535e23b878cb7a50feaebbb (patch)
tree894bed2795efce613d846ce60d04aa0cf01648df /lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
parent329912f54cde2ef09901a84a1a36844e279c2bd1 (diff)
downloadbcm5719-llvm-a4a08d31cf041a889535e23b878cb7a50feaebbb.tar.gz
bcm5719-llvm-a4a08d31cf041a889535e23b878cb7a50feaebbb.zip
[mach-o] Add support for initializers and terminators in object files
llvm-svn: 209700
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp')
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
index 69ff193202e..2b87c238090 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
@@ -109,8 +109,9 @@ static void processUndefindeSymbol(MachOFile &file, const Symbol &sym,
}
static error_code processSection(MachOFile &file, const Section &section,
- bool copyRefs) {
+ bool is64, bool copyRefs) {
unsigned offset = 0;
+ const unsigned pointerSize = (is64 ? 8 : 4);
switch (section.type) {
case llvm::MachO::S_REGULAR:
if (section.segmentName.equals("__TEXT") &&
@@ -142,6 +143,40 @@ static error_code processSection(MachOFile &file, const Section &section,
case llvm::MachO::S_ZEROFILL:
// These sections are broken in to atoms based on symbols.
break;
+ case S_MOD_INIT_FUNC_POINTERS:
+ if ((section.content.size() % pointerSize) != 0) {
+ return make_dynamic_error_code(Twine("Section ") + section.segmentName
+ + "/" + section.sectionName
+ + " has type S_MOD_INIT_FUNC_POINTERS but "
+ "its size ("
+ + Twine(section.content.size())
+ + ") is not a multiple of "
+ + Twine(pointerSize));
+ }
+ for (size_t i = 0, e = section.content.size(); i != e; i += pointerSize) {
+ ArrayRef<uint8_t> bytes = section.content.slice(offset, pointerSize);
+ file.addDefinedAtom(StringRef(), DefinedAtom::scopeTranslationUnit,
+ DefinedAtom::typeInitializerPtr, bytes, copyRefs);
+ offset += pointerSize;
+ }
+ break;
+ case S_MOD_TERM_FUNC_POINTERS:
+ if ((section.content.size() % pointerSize) != 0) {
+ return make_dynamic_error_code(Twine("Section ") + section.segmentName
+ + "/" + section.sectionName
+ + " has type S_MOD_TERM_FUNC_POINTERS but "
+ "its size ("
+ + Twine(section.content.size())
+ + ") is not a multiple of "
+ + Twine(pointerSize));
+ }
+ for (size_t i = 0, e = section.content.size(); i != e; i += pointerSize) {
+ ArrayRef<uint8_t> bytes = section.content.slice(offset, pointerSize);
+ file.addDefinedAtom(StringRef(), DefinedAtom::scopeTranslationUnit,
+ DefinedAtom::typeTerminatorPtr, bytes, copyRefs);
+ offset += pointerSize;
+ }
+ break;
case llvm::MachO::S_CSTRING_LITERALS:
for (size_t i = 0, e = section.content.size(); i != e; ++i) {
if (section.content[i] == 0) {
@@ -227,8 +262,9 @@ normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path,
processUndefindeSymbol(*file, sym, copyRefs);
}
// Create atoms from sections that don't have symbols.
+ bool is64 = MachOLinkingContext::is64Bit(normalizedFile.arch);
for (auto &sect : normalizedFile.sections) {
- if (error_code ec = processSection(*file, sect, copyRefs))
+ if (error_code ec = processSection(*file, sect, is64, copyRefs))
return ec;
}
OpenPOWER on IntegriCloud