summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
diff options
context:
space:
mode:
authorNick Kledzik <kledzik@apple.com>2014-10-02 17:27:20 +0000
committerNick Kledzik <kledzik@apple.com>2014-10-02 17:27:20 +0000
commit7efd054479b0df398af773c415f5f8aa5052f8cf (patch)
treea3681456d6c41ae62a4c7a987f332aa9004dbd7b /lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
parent32d0d09bf888c09f469d3239f9f3344c55055e45 (diff)
downloadbcm5719-llvm-7efd054479b0df398af773c415f5f8aa5052f8cf.tar.gz
bcm5719-llvm-7efd054479b0df398af773c415f5f8aa5052f8cf.zip
[mach-o] preserve custom section names on coalesable strings
llvm-svn: 218894
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp')
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
index 7a5c3c31235..8f83672cc35 100644
--- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
@@ -88,8 +88,10 @@ const MachORelocatableSectionToAtomType sectsToAtomType[] = {
/// Figures out ContentType of a mach-o section.
-DefinedAtom::ContentType atomTypeFromSection(const Section &section) {
+DefinedAtom::ContentType atomTypeFromSection(const Section &section,
+ bool &customSectionName) {
// First look for match of name and type. Empty names in table are wildcards.
+ customSectionName = false;
for (const MachORelocatableSectionToAtomType *p = sectsToAtomType ;
p->atomType != DefinedAtom::typeUnknown; ++p) {
if (p->sectionType != section.type)
@@ -98,6 +100,7 @@ DefinedAtom::ContentType atomTypeFromSection(const Section &section) {
continue;
if (!p->sectionName.equals(section.sectionName) && !p->sectionName.empty())
continue;
+ customSectionName = p->segmentName.empty() && p->sectionName.empty();
return p->atomType;
}
// Look for code denoted by section attributes
@@ -343,6 +346,7 @@ std::error_code processSymboledSection(DefinedAtom::ContentType atomType,
std::error_code processSection(DefinedAtom::ContentType atomType,
const Section &section,
+ bool customSectionName,
const NormalizedFile &normalizedFile,
MachOFile &file, bool copyRefs) {
const bool is64 = MachOLinkingContext::is64Bit(normalizedFile.arch);
@@ -432,8 +436,19 @@ std::error_code processSection(DefinedAtom::ContentType atomType,
+ " is malformed. The last atom is "
"not zero terminated.");
}
- file.addDefinedAtom(StringRef(), scope, atomType, merge, offset, size,
- false, false, copyRefs, &section);
+ if (customSectionName) {
+ // Mach-O needs a segment and section name. Concatentate those two
+ // with a / separator (e.g. "seg/sect") to fit into the lld model
+ // of just a section name.
+ std::string segSectName = section.segmentName.str()
+ + "/" + section.sectionName.str();
+ file.addDefinedAtomInCustomSection(StringRef(), scope, atomType,
+ merge, false, false, offset,
+ size, segSectName, true, &section);
+ } else {
+ file.addDefinedAtom(StringRef(), scope, atomType, merge, offset, size,
+ false, false, copyRefs, &section);
+ }
offset += size;
}
}
@@ -599,9 +614,12 @@ normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path,
for (auto &sect : normalizedFile.sections) {
if (isDebugInfoSection(sect))
continue;
- DefinedAtom::ContentType atomType = atomTypeFromSection(sect);
+ bool customSectionName;
+ DefinedAtom::ContentType atomType = atomTypeFromSection(sect,
+ customSectionName);
if (std::error_code ec =
- processSection(atomType, sect, normalizedFile, *file, copyRefs))
+ processSection(atomType, sect, customSectionName, normalizedFile,
+ *file, copyRefs))
return ec;
}
// Create atoms from undefined symbols.
OpenPOWER on IntegriCloud