forked from OSchip/llvm-project
[Layout] Assign ordinals in Resolution order.
llvm-svn: 192277
This commit is contained in:
parent
15a4774345
commit
1d3c48f1fc
|
@ -73,12 +73,11 @@ public:
|
|||
return _ordinal;
|
||||
}
|
||||
|
||||
/// Sets the command line order of the file. The parameter must
|
||||
/// also be incremented to the next available ordinal number.
|
||||
virtual void setOrdinalAndIncrement(uint64_t &ordinal) const {
|
||||
_ordinal = ordinal;
|
||||
++ordinal;
|
||||
}
|
||||
/// Returns true/false depending on whether an ordinal has been set.
|
||||
bool hasOrdinal() const { return (_ordinal != UINT64_MAX); }
|
||||
|
||||
/// Sets the command line order of the file.
|
||||
void setOrdinal(uint64_t ordinal) const { _ordinal = ordinal; }
|
||||
|
||||
public:
|
||||
template <typename T> class atom_iterator; // forward reference
|
||||
|
|
|
@ -304,7 +304,8 @@ public:
|
|||
/// The LinkingContext's can override the default behavior to change the way
|
||||
/// the resolver operates. This uses the currentInputElement. When there are
|
||||
/// no more files to be processed an appropriate InputGraphError is
|
||||
/// returned.
|
||||
/// returned. Ordinals are assigned to files returned by nextFile, which means
|
||||
/// ordinals would be assigned in the way files are resolved.
|
||||
virtual ErrorOr<File &> nextFile();
|
||||
|
||||
/// Set the resolver state for the current Input element This is used by the
|
||||
|
@ -314,6 +315,9 @@ public:
|
|||
/// atoms.
|
||||
virtual void setResolverState(uint32_t resolverState);
|
||||
|
||||
/// Return the next ordinal and Increment it.
|
||||
virtual uint64_t getNextOrdinalAndIncrement() { return _nextOrdinal++; }
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Methods needed by YAML I/O and error messages to convert Kind values
|
||||
|
@ -363,6 +367,7 @@ protected:
|
|||
std::unique_ptr<InputGraph> _inputGraph;
|
||||
mutable llvm::BumpPtrAllocator _allocator;
|
||||
InputElement *_currentInputElement;
|
||||
uint64_t _nextOrdinal;
|
||||
|
||||
private:
|
||||
/// Validate the subclass bits. Only called by validate.
|
||||
|
|
|
@ -67,9 +67,6 @@ public:
|
|||
/// \brief Set Ordinals for all the InputElements that form the InputGraph
|
||||
virtual bool assignOrdinals();
|
||||
|
||||
/// \brief Set ordinals for all the Files that are part of the InputElements
|
||||
virtual bool assignFileOrdinals(uint64_t &ordinal);
|
||||
|
||||
/// Destructor
|
||||
virtual ~InputGraph() {}
|
||||
|
||||
|
@ -149,10 +146,6 @@ public:
|
|||
_ordinal = ordinal;
|
||||
}
|
||||
|
||||
/// \brief Assign File ordinals for files contained
|
||||
/// in the InputElement
|
||||
virtual void assignFileOrdinals(uint64_t &fileOrdinal) = 0;
|
||||
|
||||
virtual int64_t getOrdinal() const { return _ordinal; }
|
||||
|
||||
virtual int64_t weight() const { return _weight; }
|
||||
|
@ -228,10 +221,6 @@ public:
|
|||
return make_range(_elements.begin(), _elements.end());
|
||||
}
|
||||
|
||||
/// \brief Assign File ordinals for files contained
|
||||
/// in the InputElement
|
||||
virtual void assignFileOrdinals(uint64_t &startOrdinal);
|
||||
|
||||
virtual void resetNextIndex() {
|
||||
_currentElementIndex = _nextElementIndex = 0;
|
||||
for (auto &elem : _elements)
|
||||
|
@ -306,10 +295,6 @@ public:
|
|||
_files.push_back(std::move(ai));
|
||||
}
|
||||
|
||||
/// \brief Assign File ordinals for files contained
|
||||
/// in the InputElement
|
||||
virtual void assignFileOrdinals(uint64_t &startOrdinal);
|
||||
|
||||
/// \brief Reset the file index if the resolver needs to process
|
||||
/// the node again.
|
||||
virtual void resetNextIndex();
|
||||
|
@ -426,10 +411,6 @@ public:
|
|||
// Do nothing here.
|
||||
virtual void resetNextIndex() {}
|
||||
|
||||
/// \brief Assign File ordinals for files contained
|
||||
/// in the InputElement
|
||||
virtual void assignFileOrdinals(uint64_t &startOrdinal);
|
||||
|
||||
protected:
|
||||
StringRef _path; // A string associated with this file.
|
||||
InputGraph::FileVectorT _files; // Vector of lld::File objects
|
||||
|
|
|
@ -56,8 +56,6 @@ public:
|
|||
|
||||
assert(result.size() == 1);
|
||||
|
||||
result[0]->setOrdinalAndIncrement(_curChildOrd);
|
||||
|
||||
// give up the pointer so that this object no longer manages it
|
||||
return result[0].release();
|
||||
}
|
||||
|
@ -79,23 +77,9 @@ public:
|
|||
if ((ec = _context.getDefaultReader().parseFile(mbc, result)))
|
||||
return ec;
|
||||
}
|
||||
for (auto &file : result)
|
||||
file->setOrdinalAndIncrement(_curChildOrd);
|
||||
return error_code::success();
|
||||
}
|
||||
|
||||
/// \brief members
|
||||
|
||||
virtual void setOrdinalAndIncrement(uint64_t &ordinal) const {
|
||||
_ordinal = ordinal++;
|
||||
_curChildOrd = _ordinal;
|
||||
// Leave space in ordinal range for all children
|
||||
for (auto mf = _archive->begin_children(),
|
||||
me = _archive->end_children(); mf != me; ++mf) {
|
||||
ordinal++;
|
||||
}
|
||||
}
|
||||
|
||||
virtual const atom_collection<DefinedAtom> &defined() const {
|
||||
return _definedAtoms;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ LinkingContext::LinkingContext()
|
|||
_warnIfCoalesableAtomsHaveDifferentLoadName(false),
|
||||
_printRemainingUndefines(true), _allowRemainingUndefines(false),
|
||||
_logInputFiles(false), _allowShlibUndefines(false),
|
||||
_outputFileType(OutputFileType::Default), _currentInputElement(nullptr) {}
|
||||
_outputFileType(OutputFileType::Default), _currentInputElement(nullptr),
|
||||
_nextOrdinal(0) {}
|
||||
|
||||
LinkingContext::~LinkingContext() {}
|
||||
|
||||
|
|
|
@ -108,8 +108,10 @@ void Resolver::handleArchiveFile(const File &file) {
|
|||
StringRef undefName = undefAtom->name();
|
||||
// load for previous undefine may also have loaded this undefine
|
||||
if (!_symbolTable.isDefined(undefName)) {
|
||||
if (const File *member = archiveFile->find(undefName, false))
|
||||
if (const File *member = archiveFile->find(undefName, false)) {
|
||||
member->setOrdinal(_context.getNextOrdinalAndIncrement());
|
||||
handleFile(*member);
|
||||
}
|
||||
}
|
||||
// If the undefined symbol has an alternative name, try to resolve the
|
||||
// symbol with the name to give it a second chance. This feature is used
|
||||
|
@ -132,8 +134,10 @@ void Resolver::handleArchiveFile(const File &file) {
|
|||
assert(curAtom != nullptr);
|
||||
if (const DefinedAtom *curDefAtom = dyn_cast<DefinedAtom>(curAtom)) {
|
||||
if (curDefAtom->merge() == DefinedAtom::mergeAsTentative) {
|
||||
if (const File *member = archiveFile->find(tentDefName, true))
|
||||
if (const File *member = archiveFile->find(tentDefName, true)) {
|
||||
member->setOrdinal(_context.getNextOrdinalAndIncrement());
|
||||
handleFile(*member);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +151,6 @@ void Resolver::handleSharedLibrary(const File &file) {
|
|||
|
||||
// Add all the atoms from the shared library
|
||||
handleFile(*sharedLibrary);
|
||||
|
||||
do {
|
||||
undefineGenCount = _symbolTable.size();
|
||||
std::vector<const UndefinedAtom *> undefines;
|
||||
|
@ -295,12 +298,20 @@ void Resolver::resolveUndefines() {
|
|||
_context.setResolverState(Resolver::StateNoChange);
|
||||
if (error_code(nextFile) == InputGraphError::no_more_files)
|
||||
break;
|
||||
if (nextFile->kind() == File::kindObject)
|
||||
if (nextFile->kind() == File::kindObject) {
|
||||
nextFile->setOrdinal(_context.getNextOrdinalAndIncrement());
|
||||
handleFile(*nextFile);
|
||||
if (nextFile->kind() == File::kindArchiveLibrary)
|
||||
}
|
||||
if (nextFile->kind() == File::kindArchiveLibrary) {
|
||||
if (!nextFile->hasOrdinal())
|
||||
nextFile->setOrdinal(_context.getNextOrdinalAndIncrement());
|
||||
handleArchiveFile(*nextFile);
|
||||
if (nextFile->kind() == File::kindSharedLibrary)
|
||||
}
|
||||
if (nextFile->kind() == File::kindSharedLibrary) {
|
||||
if (!nextFile->hasOrdinal())
|
||||
nextFile->setOrdinal(_context.getNextOrdinalAndIncrement());
|
||||
handleSharedLibrary(*nextFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,9 +104,6 @@ bool Driver::link(LinkingContext &context, raw_ostream &diagnostics) {
|
|||
|
||||
context.inputGraph().doPostProcess();
|
||||
|
||||
uint64_t ordinal = 0;
|
||||
context.inputGraph().assignFileOrdinals(ordinal);
|
||||
|
||||
// Do core linking.
|
||||
ScopedTask resolveTask(getDefaultDomain(), "Resolve");
|
||||
Resolver resolver(context);
|
||||
|
|
|
@ -29,12 +29,6 @@ bool InputGraph::assignOrdinals() {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool InputGraph::assignFileOrdinals(uint64_t &startOrdinal) {
|
||||
for (auto &ie : _inputArgs)
|
||||
ie->assignFileOrdinals(startOrdinal);
|
||||
return true;
|
||||
}
|
||||
|
||||
void InputGraph::doPostProcess() {
|
||||
std::stable_sort(_inputArgs.begin(), _inputArgs.end(), sortInputElements);
|
||||
}
|
||||
|
@ -103,13 +97,6 @@ FileNode::FileNode(StringRef path, int64_t ordinal)
|
|||
: InputElement(InputElement::Kind::File, ordinal), _path(path),
|
||||
_resolveState(Resolver::StateNoChange), _nextFileIndex(0) {}
|
||||
|
||||
/// \brief Assign File ordinals for files contained
|
||||
/// in the InputElement
|
||||
void FileNode::assignFileOrdinals(uint64_t &startOrdinal) {
|
||||
for (auto &file : _files)
|
||||
file->setOrdinalAndIncrement(startOrdinal);
|
||||
}
|
||||
|
||||
/// \brief Read the file into _buffer.
|
||||
error_code
|
||||
FileNode::readFile(const LinkingContext &ctx, raw_ostream &diagnostics) {
|
||||
|
@ -147,13 +134,6 @@ void FileNode::resetNextIndex() {
|
|||
|
||||
/// ControlNode
|
||||
|
||||
/// \brief Assign File ordinals for files contained
|
||||
/// in the InputElement
|
||||
void ControlNode::assignFileOrdinals(uint64_t &startOrdinal) {
|
||||
for (auto &elem : _elements)
|
||||
elem->assignFileOrdinals(startOrdinal);
|
||||
}
|
||||
|
||||
/// \brief Get the resolver State. The return value of the resolve
|
||||
/// state for a control node is the or'ed value of the resolve states
|
||||
/// contained in it.
|
||||
|
@ -178,13 +158,6 @@ SimpleFileNode::SimpleFileNode(StringRef path, int64_t ordinal)
|
|||
: InputElement(InputElement::Kind::SimpleFile, ordinal), _path(path),
|
||||
_nextFileIndex(0), _resolveState(Resolver::StateNoChange) {}
|
||||
|
||||
/// \brief Assign File ordinals for files contained
|
||||
/// in the InputElement
|
||||
void SimpleFileNode::assignFileOrdinals(uint64_t &startOrdinal) {
|
||||
for (auto &file : _files)
|
||||
file->setOrdinalAndIncrement(startOrdinal);
|
||||
}
|
||||
|
||||
/// Group
|
||||
|
||||
/// \brief Return the next file that need to be processed by the resolver.
|
||||
|
|
|
@ -34,10 +34,6 @@ public:
|
|||
return f->kind() == kindLinkerScript;
|
||||
}
|
||||
|
||||
virtual void setOrdinalAndIncrement(uint64_t &ordinal) const {
|
||||
_ordinal = ordinal++;
|
||||
}
|
||||
|
||||
virtual const LinkingContext &getLinkingContext() const { return _context; }
|
||||
|
||||
virtual const atom_collection<DefinedAtom> &defined() const {
|
||||
|
|
|
@ -600,14 +600,6 @@ template <> struct MappingTraits<const lld::File *> {
|
|||
|
||||
const lld::File *denormalize(IO &io) { return this; }
|
||||
|
||||
virtual void setOrdinalAndIncrement(uint64_t &ordinal) const {
|
||||
_ordinal = ordinal++;
|
||||
// Assign sequential ordinals to member files
|
||||
for (const ArchMember &member : _members) {
|
||||
member._content->setOrdinalAndIncrement(ordinal);
|
||||
}
|
||||
}
|
||||
|
||||
virtual const atom_collection<lld::DefinedAtom> &defined() const {
|
||||
return _noDefinedAtoms;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue