public:
typedef const std::map<std::string, std::string> StringMap;
- FileCOFF(std::unique_ptr<MemoryBuffer> mb, StringMap &altNames,
- error_code &ec);
+ FileCOFF(std::unique_ptr<MemoryBuffer> mb, error_code &ec);
+
+ error_code parse(StringMap &altNames);
+ StringRef getLinkerDirectives() const { return _directives; }
virtual const atom_collection<DefinedAtom> &defined() const {
return _definedAtoms;
return _absoluteAtoms;
}
- StringRef getLinkerDirectives() const { return _directives; }
-
private:
error_code readSymbolTable(vector<const coff_symbol *> &result);
error_code addRelocationReferenceToAtoms();
error_code findSection(StringRef name, const coff_section *&result);
StringRef ArrayRefToString(ArrayRef<uint8_t> array);
- error_code maybeReadLinkerDirectives();
std::unique_ptr<const llvm::object::COFFObjectFile> _obj;
atom_collection_vector<DefinedAtom> _definedAtoms;
}
}
-FileCOFF::FileCOFF(std::unique_ptr<MemoryBuffer> mb, StringMap &altNames,
- error_code &ec)
+FileCOFF::FileCOFF(std::unique_ptr<MemoryBuffer> mb, error_code &ec)
: File(mb->getBufferIdentifier(), kindObject), _ordinal(0) {
OwningPtr<llvm::object::Binary> bin;
ec = llvm::object::createBinary(mb.release(), bin);
}
bin.take();
+ // Read .drectve section if exists.
+ const coff_section *section = nullptr;
+ if ((ec = findSection(".drectve", section)))
+ return;
+ if (section != nullptr) {
+ ArrayRef<uint8_t> contents;
+ if ((ec = _obj->getSectionContents(section, contents)))
+ return;
+ _directives = ArrayRefToString(contents);
+ }
+}
+
+error_code FileCOFF::parse(StringMap &altNames) {
// Read the symbol table and atomize them if possible. Defined atoms
// cannot be atomized in one pass, so they will be not be atomized but
// added to symbolToAtom.
SymbolVectorT symbols;
- if ((ec = readSymbolTable(symbols)))
- return;
+ if (error_code ec = readSymbolTable(symbols))
+ return ec;
createAbsoluteAtoms(symbols, _absoluteAtoms._atoms);
- if ((ec = createUndefinedAtoms(symbols, _undefinedAtoms._atoms)))
- return;
- if ((ec = createDefinedSymbols(symbols, altNames, _definedAtoms._atoms)))
- return;
-
- if ((ec = addRelocationReferenceToAtoms()))
- return;
-
- // Read .drectve section if exists.
- ec = maybeReadLinkerDirectives();
+ if (error_code ec = createUndefinedAtoms(symbols, _undefinedAtoms._atoms))
+ return ec;
+ if (error_code ec = createDefinedSymbols(symbols, altNames, _definedAtoms._atoms))
+ return ec;
+ if (error_code ec = addRelocationReferenceToAtoms())
+ return ec;
+ return error_code::success();
}
/// Iterate over the symbol table to retrieve all symbols.
return StringRef(*contents).trim();
}
-// Read .drectve section contents if exists, and store it to _directives.
-error_code FileCOFF::maybeReadLinkerDirectives() {
- const coff_section *section = nullptr;
- if (error_code ec = findSection(".drectve", section))
- return ec;
- if (section != nullptr) {
- ArrayRef<uint8_t> contents;
- if (error_code ec = _obj->getSectionContents(section, contents))
- return ec;
- _directives = ArrayRefToString(contents);
- }
- return error_code::success();
-}
-
// Convert .res file to .coff file and then parse it. Resource file is a file
// containing various types of data, such as icons, translation texts,
// etc. "cvtres.exe" command reads an RC file to create a COFF file which
return ec;
std::unique_ptr<MemoryBuffer> newmb(opmb.take());
error_code ec;
- FileCOFF::StringMap emptyMap;
- std::unique_ptr<FileCOFF> file(
- new FileCOFF(std::move(newmb), emptyMap, ec));
+ std::unique_ptr<FileCOFF> file(new FileCOFF(std::move(newmb), ec));
if (ec)
return ec;
+ FileCOFF::StringMap emptyMap;
+ if (error_code ec = file->parse(emptyMap))
+ return ec;
result.push_back(std::move(file));
return error_code::success();
}
std::vector<std::unique_ptr<File>> &result) const {
// Parse the memory buffer as PECOFF file.
error_code ec;
- std::unique_ptr<FileCOFF> file(
- new FileCOFF(std::move(mb), _context.alternateNames(), ec));
+ std::unique_ptr<FileCOFF> file(new FileCOFF(std::move(mb), ec));
if (ec)
return ec;
// Interpret .drectve section if the section has contents.
StringRef directives = file->getLinkerDirectives();
if (!directives.empty())
- if (error_code ec2 = handleDirectiveSection(registry, directives))
- return ec2;
+ if (error_code ec = handleDirectiveSection(registry, directives))
+ return ec;
+ if (error_code ec = file->parse(_context.alternateNames()))
+ return ec;
result.push_back(std::move(file));
return error_code::success();
}