Factor the symbol handling in normalizedToAtoms into a separate function.

No functionality change.

llvm-svn: 199066
This commit is contained in:
Joey Gouly 2014-01-12 22:55:49 +00:00
parent 1995b9fead
commit 9c826c100a
1 changed files with 12 additions and 7 deletions

View File

@ -53,19 +53,24 @@ static uint64_t nextSymbolAddress(const NormalizedFile &normalizedFile,
return closestAddr; return closestAddr;
} }
static ErrorOr<std::unique_ptr<lld::File>> static void processSymbol(const NormalizedFile &normalizedFile, MachOFile &file,
normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path, const Symbol &sym, bool copyRefs) {
bool copyRefs) {
std::unique_ptr<MachOFile> file(new MachOFile(path));
for (const Symbol &sym : normalizedFile.globalSymbols) {
// Mach-O symbol table does have size in it, so need to scan ahead // Mach-O symbol table does have size in it, so need to scan ahead
// to find symbol with next highest address. // to find symbol with next highest address.
const Section &section = normalizedFile.sections[sym.sect - 1]; const Section &section = normalizedFile.sections[sym.sect - 1];
uint64_t offset = sym.value - section.address; uint64_t offset = sym.value - section.address;
uint64_t size = nextSymbolAddress(normalizedFile, sym) - sym.value; uint64_t size = nextSymbolAddress(normalizedFile, sym) - sym.value;
ArrayRef<uint8_t> atomContent = section.content.slice(offset, size); ArrayRef<uint8_t> atomContent = section.content.slice(offset, size);
file->addDefinedAtom(sym.name, atomContent, copyRefs); file.addDefinedAtom(sym.name, atomContent, copyRefs);
}
static ErrorOr<std::unique_ptr<lld::File>>
normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path,
bool copyRefs) {
std::unique_ptr<MachOFile> file(new MachOFile(path));
for (const Symbol &sym : normalizedFile.globalSymbols) {
processSymbol(normalizedFile, *file, sym, copyRefs);
} }
assert(normalizedFile.localSymbols.empty() && assert(normalizedFile.localSymbols.empty() &&