[lld] r210142 - [mach-o] Make anonymous atom out of section content before any symbol
Nick Kledzik
kledzik at apple.com
Tue Jun 3 17:34:28 PDT 2014
Author: kledzik
Date: Tue Jun 3 19:34:27 2014
New Revision: 210142
URL: http://llvm.org/viewvc/llvm-project?rev=210142&view=rev
Log:
[mach-o] Make anonymous atom out of section content before any symbol
In sections that are broken into atoms at symbols, if the first symbol in the
section is not at the start of the section, then make an anonymous atom for
the section content that is before the first symbol.
Modified:
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
lld/trunk/test/mach-o/parse-function.yaml
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=210142&r1=210141&r2=210142&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Tue Jun 3 19:34:27 2014
@@ -209,31 +209,29 @@ void appendSymbolsInSection(const std::v
}
void atomFromSymbol(DefinedAtom::ContentType atomType, const Section §ion,
- MachOFile &file, const Symbol &symbol,
+ MachOFile &file, uint64_t symbolAddr, StringRef symbolName,
+ bool symbolWeakDef, Atom::Scope symbolScope,
uint64_t nextSymbolAddr, bool copyRefs) {
// Mach-O symbol table does have size in it. Instead the size is the
// difference between this and the next symbol.
- uint64_t size = nextSymbolAddr - symbol.value;
+ uint64_t size = nextSymbolAddr - symbolAddr;
if (section.type == llvm::MachO::S_ZEROFILL) {
- file.addZeroFillDefinedAtom(symbol.name, atomScope(symbol.scope),
- size, copyRefs);
+ file.addZeroFillDefinedAtom(symbolName, symbolScope, size, copyRefs);
} else {
- uint64_t offset = symbol.value - section.address;
+ uint64_t offset = symbolAddr - section.address;
ArrayRef<uint8_t> atomContent = section.content.slice(offset, size);
- DefinedAtom::Merge merge = DefinedAtom::mergeNo;
- if (symbol.desc & N_WEAK_DEF)
- merge = DefinedAtom::mergeAsWeak;
+ DefinedAtom::Merge merge = symbolWeakDef
+ ? DefinedAtom::mergeAsWeak : DefinedAtom::mergeNo;
if (atomType == DefinedAtom::typeUnknown) {
// Mach-O needs a segment and section name. Concatentate those two
// with a / seperator (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(symbol.name, atomScope(symbol.scope),
- atomType, merge, atomContent,
- segSectName, true);
+ file.addDefinedAtomInCustomSection(symbolName, symbolScope, atomType,
+ merge, atomContent, segSectName, true);
} else {
- file.addDefinedAtom(symbol.name, atomScope(symbol.scope), atomType, merge,
+ file.addDefinedAtom(symbolName, symbolScope, atomType, merge,
atomContent, copyRefs);
}
}
@@ -270,20 +268,26 @@ error_code processSymboledSection(Define
if (symbols.empty() && section.content.empty())
return error_code();
- if (symbols.front()->value != section.address) {
+ const uint64_t firstSymbolAddr = symbols.front()->value;
+ if (firstSymbolAddr != section.address) {
// Section has anonymous content before first symbol.
- // FIXME
+ atomFromSymbol(atomType, section, file, section.address, StringRef(),
+ false, Atom::scopeTranslationUnit, firstSymbolAddr, copyRefs);
}
const Symbol *lastSym = nullptr;
+ bool lastSymIsWeakDef;
for (const Symbol *sym : symbols) {
if (lastSym != nullptr) {
- atomFromSymbol(atomType, section, file, *lastSym, sym->value, copyRefs);
+ atomFromSymbol(atomType, section, file, lastSym->value, lastSym->name,
+ lastSymIsWeakDef, atomScope(lastSym->scope), sym->value, copyRefs);
}
lastSym = sym;
+ lastSymIsWeakDef = (lastSym->desc & N_WEAK_DEF);
}
if (lastSym != nullptr) {
- atomFromSymbol(atomType, section, file, *lastSym,
+ atomFromSymbol(atomType, section, file, lastSym->value, lastSym->name,
+ lastSymIsWeakDef, atomScope(lastSym->scope),
section.address + section.content.size(), copyRefs);
}
return error_code();
Modified: lld/trunk/test/mach-o/parse-function.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/parse-function.yaml?rev=210142&r1=210141&r2=210142&view=diff
==============================================================================
--- lld/trunk/test/mach-o/parse-function.yaml (original)
+++ lld/trunk/test/mach-o/parse-function.yaml Tue Jun 3 19:34:27 2014
@@ -16,51 +16,60 @@ sections:
attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ]
alignment: 4
address: 0x0000000000000000
- content: [ 0xC3, 0xC3, 0xC3, 0xC3, 0xC3 ]
+ content: [ 0xCC, 0xC3, 0x90, 0xC3, 0x90, 0x90, 0xC3, 0x90,
+ 0x90, 0x90, 0xC3, 0x90, 0x90, 0x90, 0x90, 0xC3 ]
local-symbols:
- name: _myStatic
type: N_SECT
sect: 1
- value: 0x0000000000000004
+ value: 0x000000000000000B
global-symbols:
- name: _myGlobal
type: N_SECT
scope: [ N_EXT ]
sect: 1
- value: 0x0000000000000000
+ value: 0x0000000000000001
- name: _myGlobalWeak
type: N_SECT
scope: [ N_EXT ]
sect: 1
desc: [ N_WEAK_DEF ]
- value: 0x0000000000000001
+ value: 0x0000000000000002
- name: _myHidden
type: N_SECT
scope: [ N_EXT, N_PEXT ]
sect: 1
- value: 0x0000000000000002
+ value: 0x0000000000000004
- name: _myHiddenWeak
type: N_SECT
scope: [ N_EXT, N_PEXT ]
sect: 1
desc: [ N_WEAK_DEF ]
- value: 0x0000000000000003
+ value: 0x0000000000000007
...
+# CHECK-NOT: name:
+# CHECK: content: [ CC ]
+
# CHECK: name: _myGlobal
# CHECK: scope: global
+# CHECK: content: [ C3 ]
# CHECK: name: _myGlobalWeak
# CHECK: scope: global
+# CHECK: content: [ 90, C3 ]
# CHECK: merge: as-weak
# CHECK: name: _myHidden
# CHECK: scope: hidden
+# CHECK: content: [ 90, 90, C3 ]
# CHECK: name: _myHiddenWeak
# CHECK: scope: hidden
+# CHECK: content: [ 90, 90, 90, C3 ]
# CHECK: merge: as-weak
# CHECK: name: _myStatic
# CHECK-NOT: scope: global
# CHECK-NOT: scope: hidden
+# CHECK: content: [ 90, 90, 90, 90, C3 ]
More information about the llvm-commits
mailing list