forked from OSchip/llvm-project
[mach-o] preserve custom section names on coalesable strings
llvm-svn: 218894
This commit is contained in:
parent
32d0d09bf8
commit
7efd054479
|
@ -88,8 +88,10 @@ const MachORelocatableSectionToAtomType sectsToAtomType[] = {
|
|||
|
||||
|
||||
/// Figures out ContentType of a mach-o section.
|
||||
DefinedAtom::ContentType atomTypeFromSection(const Section §ion) {
|
||||
DefinedAtom::ContentType atomTypeFromSection(const Section §ion,
|
||||
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 §ion) {
|
|||
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 §ion,
|
||||
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, §ion);
|
||||
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, §ion);
|
||||
} else {
|
||||
file.addDefinedAtom(StringRef(), scope, atomType, merge, offset, size,
|
||||
false, false, copyRefs, §ion);
|
||||
}
|
||||
offset += size;
|
||||
}
|
||||
}
|
||||
|
@ -599,9 +614,12 @@ normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path,
|
|||
for (auto § : 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.
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t -print_atoms | FileCheck %s
|
||||
#
|
||||
# Test -keep_private_externs in -r mode.
|
||||
#
|
||||
|
||||
--- !mach-o
|
||||
arch: x86_64
|
||||
file-type: MH_OBJECT
|
||||
flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ]
|
||||
sections:
|
||||
- segment: __TEXT
|
||||
section: __objc_methname
|
||||
type: S_CSTRING_LITERALS
|
||||
attributes: [ ]
|
||||
address: 0x0000000000000000
|
||||
content: [ 0x61, 0x62, 0x63, 0x00, 0x64, 0x65, 0x66, 0x00 ]
|
||||
- segment: __TEXT
|
||||
section: __objc_classname
|
||||
type: S_CSTRING_LITERALS
|
||||
attributes: [ ]
|
||||
address: 0x0000000000000006
|
||||
content: [ 0x61, 0x62, 0x63, 0x00, 0x67, 0x68, 0x69, 0x00 ]
|
||||
- segment: __TEXT
|
||||
section: __cstring
|
||||
type: S_CSTRING_LITERALS
|
||||
attributes: [ ]
|
||||
address: 0x000000000000000A
|
||||
content: [ 0x61, 0x62, 0x63, 0x00, 0x6A, 0x6B, 0x6C, 0x00 ]
|
||||
|
||||
--- !mach-o
|
||||
arch: x86_64
|
||||
file-type: MH_OBJECT
|
||||
flags: [ MH_SUBSECTIONS_VIA_SYMBOLS ]
|
||||
has-UUID: false
|
||||
OS: unknown
|
||||
sections:
|
||||
- segment: __TEXT
|
||||
section: __objc_methname
|
||||
type: S_CSTRING_LITERALS
|
||||
attributes: [ ]
|
||||
address: 0x0000000000000000
|
||||
content: [ 0x61, 0x62, 0x63, 0x00 ]
|
||||
- segment: __TEXT
|
||||
section: __objc_classname
|
||||
type: S_CSTRING_LITERALS
|
||||
attributes: [ ]
|
||||
address: 0x0000000000000006
|
||||
content: [ 0x61, 0x62, 0x63, 0x00 ]
|
||||
- segment: __TEXT
|
||||
section: __cstring
|
||||
type: S_CSTRING_LITERALS
|
||||
attributes: [ ]
|
||||
address: 0x000000000000000A
|
||||
content: [ 0x61, 0x62, 0x63, 0x00 ]
|
||||
|
||||
|
||||
...
|
||||
|
||||
# CHECK: defined-atoms:
|
||||
# CHECK: - scope: hidden
|
||||
# CHECK: type: c-string
|
||||
# CHECK: content: [ 61, 62, 63, 00 ]
|
||||
# CHECK: merge: by-content
|
||||
# CHECK: section-choice: custom-required
|
||||
# CHECK: section-name: __TEXT/__objc_methname
|
||||
# CHECK: - scope: hidden
|
||||
# CHECK: type: c-string
|
||||
# CHECK: content: [ 64, 65, 66, 00 ]
|
||||
# CHECK: merge: by-content
|
||||
# CHECK: section-choice: custom-required
|
||||
# CHECK: section-name: __TEXT/__objc_methname
|
||||
# CHECK: - scope: hidden
|
||||
# CHECK: type: c-string
|
||||
# CHECK: content: [ 61, 62, 63, 00 ]
|
||||
# CHECK: merge: by-content
|
||||
# CHECK: section-choice: custom-required
|
||||
# CHECK: section-name: __TEXT/__objc_classname
|
||||
# CHECK: - scope: hidden
|
||||
# CHECK: type: c-string
|
||||
# CHECK: content: [ 67, 68, 69, 00 ]
|
||||
# CHECK: merge: by-content
|
||||
# CHECK: section-choice: custom-required
|
||||
# CHECK: section-name: __TEXT/__objc_classname
|
||||
# CHECK: - scope: hidden
|
||||
# CHECK: type: c-string
|
||||
# CHECK: content: [ 61, 62, 63, 00 ]
|
||||
# CHECK: merge: by-content
|
||||
# CHECK: - scope: hidden
|
||||
# CHECK: type: c-string
|
||||
# CHECK: content: [ 6A, 6B, 6C, 00 ]
|
||||
# CHECK: merge: by-content
|
Loading…
Reference in New Issue