summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-09-12 19:14:05 +0000
committerRui Ueyama <ruiu@google.com>2013-09-12 19:14:05 +0000
commite5416ec2d21854f34801c33ef567072d3e647f6f (patch)
treef216f2c3028f202636221ce64abf9cf5a3dbfeb3 /lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
parent1e2e3ea584121f523aa4118f383927ed6b73246c (diff)
downloadbcm5719-llvm-e5416ec2d21854f34801c33ef567072d3e647f6f.tar.gz
bcm5719-llvm-e5416ec2d21854f34801c33ef567072d3e647f6f.zip
Add a fallback mechanism for undefined atom.
In COFF, an undefined symbol can have up to one alternative name. If a symbol is resolved by its regular name, then it's linked normally. If a symbol is not found in any input files, all references to the regular name are resolved using the alternative name. If the alternative name is not found, it's a link error. This mechanism is called "weak externals". To support this mechanism, I added a new member function fallback() to undefined atom. If an undefined atom has the second name, fallback() returns a new undefined atom that should be used instead of the original one to resolve undefines. If it does not have the second name, the function returns nullptr. Differential Revision: http://llvm-reviews.chandlerc.com/D1550 llvm-svn: 190625
Diffstat (limited to 'lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp')
-rw-r--r--lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
index 404bad73d99..5109097bd2f 100644
--- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
+++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "lld/ReaderWriter/Reader.h"
+#include "lld/ReaderWriter/Simple.h"
#include "lld/ReaderWriter/Writer.h"
#include "lld/Core/ArchiveLibraryFile.h"
@@ -957,10 +958,13 @@ template <> struct MappingTraits<const lld::UndefinedAtom *> {
class NormalizedAtom : public lld::UndefinedAtom {
public:
NormalizedAtom(IO &io)
- : _file(fileFromContext(io)), _name(), _canBeNull(canBeNullNever) {}
+ : _file(fileFromContext(io)), _name(), _canBeNull(canBeNullNever),
+ _fallback(nullptr) {}
+
NormalizedAtom(IO &io, const lld::UndefinedAtom *atom)
: _file(fileFromContext(io)), _name(atom->name()),
- _canBeNull(atom->canBeNull()) {}
+ _canBeNull(atom->canBeNull()), _fallback(atom->fallback()) {}
+
const lld::UndefinedAtom *denormalize(IO &io) {
ContextInfo *info = reinterpret_cast<ContextInfo *>(io.getContext());
assert(info != nullptr);
@@ -972,10 +976,11 @@ template <> struct MappingTraits<const lld::UndefinedAtom *> {
DEBUG_WITH_TYPE("WriterYAML",
llvm::dbgs() << "created UndefinedAtom named: '" << _name
- << "' (" << (void *)_name.data() << ", "
- << _name.size() << ")\n");
+ << "' (" << (void *)_name.data() << ", "
+ << _name.size() << ")\n");
return this;
}
+
// Extract current File object from YAML I/O parsing context
const lld::File &fileFromContext(IO &io) {
ContextInfo *info = reinterpret_cast<ContextInfo *>(io.getContext());
@@ -987,10 +992,12 @@ template <> struct MappingTraits<const lld::UndefinedAtom *> {
virtual const lld::File &file() const { return _file; }
virtual StringRef name() const { return _name; }
virtual CanBeNull canBeNull() const { return _canBeNull; }
+ virtual const UndefinedAtom *fallback() const { return _fallback; }
const lld::File &_file;
StringRef _name;
CanBeNull _canBeNull;
+ const UndefinedAtom *_fallback;
};
static void mapping(IO &io, const lld::UndefinedAtom *&atom) {
@@ -1000,6 +1007,8 @@ template <> struct MappingTraits<const lld::UndefinedAtom *> {
io.mapRequired("name", keys->_name);
io.mapOptional("can-be-null", keys->_canBeNull,
lld::UndefinedAtom::canBeNullNever);
+ io.mapOptional("fallback", keys->_fallback,
+ (const lld::UndefinedAtom *)nullptr);
}
};
OpenPOWER on IntegriCloud