void appendLLVMOption(const char *opt) { _llvmOptions.push_back(opt); }
+ void addAlias(StringRef from, StringRef to) { _aliasSymbols[from] = to; }
+ const std::map<std::string, std::string> &getAliases() const {
+ return _aliasSymbols;
+ }
+
void setInputGraph(std::unique_ptr<InputGraph> inputGraph) {
_inputGraph = std::move(inputGraph);
}
/// Abstract method to lazily instantiate the Writer.
virtual Writer &writer() const = 0;
- /// Method to create a internal file for the entry symbol
+ /// Method to create an internal file for the entry symbol
virtual std::unique_ptr<File> createEntrySymbolFile() const;
std::unique_ptr<File> createEntrySymbolFile(StringRef filename) const;
- /// Method to create a internal file for an undefined symbol
+ /// Method to create an internal file for an undefined symbol
virtual std::unique_ptr<File> createUndefinedSymbolFile() const;
std::unique_ptr<File> createUndefinedSymbolFile(StringRef filename) const;
+ /// Method to create an internal file for alias symbols
+ std::unique_ptr<File> createAliasSymbolFile() const;
+
StringRef _outputPath;
StringRef _entrySymbolName;
bool _deadStrip;
bool _allowShlibUndefines;
OutputFileType _outputFileType;
std::vector<StringRef> _deadStripRoots;
+ std::map<std::string, std::string> _aliasSymbols;
std::vector<const char *> _llvmOptions;
StringRefVector _initialUndefinedSymbols;
std::unique_ptr<InputGraph> _inputGraph;
--- /dev/null
+//===- lld/ReaderWriter/Alias.h - Alias atoms -----------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief Provide alias atoms.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_READER_WRITER_ALIAS_H
+#define LLD_READER_WRITER_ALIAS_H
+
+#include "lld/Core/LLVM.h"
+#include "lld/ReaderWriter/Simple.h"
+
+#include <string>
+
+namespace lld {
+
+// An AliasAtom is a zero-size atom representing an alias for other atom. It has
+// a LayoutAfter reference to the target atom, so that this atom and the target
+// atom will be laid out at the same location in the final result. Initially
+// the target atom is an undefined atom. Resolver will replace it with a defined
+// one.
+//
+// It does not have attributes itself. Most member function calls are forwarded
+// to the target atom.
+class AliasAtom : public SimpleDefinedAtom {
+public:
+ AliasAtom(const File &file, StringRef name)
+ : SimpleDefinedAtom(file), _target(nullptr), _name(name) {}
+
+ StringRef name() const override { return _name; }
+ uint64_t size() const override { return 0; }
+ ArrayRef<uint8_t> rawContent() const override { return ArrayRef<uint8_t>(); }
+
+ Scope scope() const override {
+ getTarget();
+ return _target ? _target->scope() : scopeLinkageUnit;
+ }
+
+ Merge merge() const override {
+ getTarget();
+ return _target ? _target->merge() : mergeNo;
+ }
+
+ ContentType contentType() const override {
+ getTarget();
+ return _target ? _target->contentType() : typeUnknown;
+ }
+
+ Interposable interposable() const override {
+ getTarget();
+ return _target ? _target->interposable() : interposeNo;
+ }
+
+ SectionChoice sectionChoice() const override {
+ getTarget();
+ return _target ? _target->sectionChoice() : sectionBasedOnContent;
+ }
+
+ StringRef customSectionName() const override {
+ getTarget();
+ return _target ? _target->customSectionName() : StringRef("");
+ }
+
+private:
+ void getTarget() const {
+ if (_target)
+ return;
+ for (const Reference *r : *this) {
+ if (r->kindNamespace() == lld::Reference::KindNamespace::all &&
+ r->kindValue() == lld::Reference::kindLayoutAfter) {
+ _target = dyn_cast<DefinedAtom>(r->target());
+ return;
+ }
+ }
+ }
+
+ mutable const DefinedAtom *_target;
+ std::string _name;
+};
+
+} // end namespace lld
+
+#endif
_absoluteSymbols[name] = addr;
}
- void addAlias(StringRef sym, StringRef target) {
- _aliasSymbols[sym] = target;
- }
-
/// Return the list of initializer symbols that are specified in the
/// linker command line, using the -init option.
range<const StringRef *> initFunctions() const {
return _absoluteSymbols;
}
- const std::map<std::string, std::string> &getAliases() const {
- return _aliasSymbols;
- }
-
/// \brief Helper function to allocate strings.
StringRef allocateString(StringRef ref) const {
char *x = _allocator.Allocate<char>(ref.size() + 1);
StringRefVector _rpathList;
StringRefVector _rpathLinkList;
std::map<std::string, uint64_t> _absoluteSymbols;
- std::map<std::string, std::string> _aliasSymbols;
};
} // end namespace lld
#include "lld/Core/LinkingContext.h"
#include "lld/Core/Resolver.h"
-#include "lld/ReaderWriter/Writer.h"
+#include "lld/ReaderWriter/Alias.h"
#include "lld/ReaderWriter/Simple.h"
-
+#include "lld/ReaderWriter/Writer.h"
#include "llvm/ADT/Triple.h"
namespace lld {
return std::move(undefinedSymFile);
}
+std::unique_ptr<File> LinkingContext::createAliasSymbolFile() const {
+ if (getAliases().empty())
+ return nullptr;
+ std::unique_ptr<SimpleFile> file(new SimpleFile("<alias>"));
+ for (const auto &i : getAliases()) {
+ StringRef from = i.first;
+ StringRef to = i.second;
+ SimpleDefinedAtom *fromAtom = new (_allocator) AliasAtom(*file, from);
+ UndefinedAtom *toAtom = new (_allocator) SimpleUndefinedAtom(*file, to);
+ fromAtom->addReference(Reference::KindNamespace::all,
+ Reference::KindArch::all, Reference::kindLayoutAfter,
+ 0, toAtom, 0);
+ file->addAtom(*fromAtom);
+ file->addAtom(*toAtom);
+ }
+ return std::move(file);
+}
+
void LinkingContext::createInternalFiles(
std::vector<std::unique_ptr<File> > &result) const {
if (std::unique_ptr<File> file = createEntrySymbolFile())
result.push_back(std::move(file));
if (std::unique_ptr<File> file = createUndefinedSymbolFile())
result.push_back(std::move(file));
+ if (std::unique_ptr<File> file = createAliasSymbolFile())
+ result.push_back(std::move(file));
}
void LinkingContext::addPasses(PassManager &pm) {}
uint64_t _value;
};
-// An AliasAtom is a zero-size atom representing an alias for other atom. It has
-// a LayoutAfter reference to the target atom, so that this atom and the target
-// atom will be laid out at the same location in the final result. Initially
-// the target atom is an undefined atom. Resolver will replace it with a defined
-// one.
-//
-// It does not have attributes itself. Most member function calls are forwarded
-// to the target atom.
-class AliasAtom : public SimpleDefinedAtom {
-public:
- AliasAtom(const File &file, StringRef name)
- : SimpleDefinedAtom(file), _target(nullptr), _name(name) {}
-
- StringRef name() const override { return _name; }
- uint64_t size() const override { return 0; }
- ArrayRef<uint8_t> rawContent() const override { return ArrayRef<uint8_t>(); }
-
- Scope scope() const override {
- getTarget();
- return _target ? _target->scope() : scopeLinkageUnit;
- }
-
- Merge merge() const override {
- getTarget();
- return _target ? _target->merge() : mergeNo;
- }
-
- ContentType contentType() const override {
- getTarget();
- return _target ? _target->contentType() : typeUnknown;
- }
-
- Interposable interposable() const override {
- getTarget();
- return _target ? _target->interposable() : interposeNo;
- }
-
- SectionChoice sectionChoice() const override {
- getTarget();
- return _target ? _target->sectionChoice() : sectionBasedOnContent;
- }
-
- StringRef customSectionName() const override {
- getTarget();
- return _target ? _target->customSectionName() : StringRef("");
- }
-
-private:
- void getTarget() const {
- if (_target)
- return;
- for (const Reference *r : *this) {
- if (r->kindNamespace() == lld::Reference::KindNamespace::all &&
- r->kindValue() == lld::Reference::kindLayoutAfter) {
- _target = dyn_cast<DefinedAtom>(r->target());
- return;
- }
- }
- }
-
- mutable const DefinedAtom *_target;
- StringRef _name;
-};
-
class CommandLineUndefinedAtom : public SimpleUndefinedAtom {
public:
CommandLineUndefinedAtom(const File &f, StringRef name)
uint64_t val = i.second;
file->addAtom(*(new (_allocator) CommandLineAbsoluteAtom(*file, sym, val)));
}
- for (auto &i : getAliases()) {
- StringRef from = i.first;
- StringRef to = i.second;
- SimpleDefinedAtom *fromAtom = new (_allocator) AliasAtom(*file, from);
- UndefinedAtom *toAtom = new (_allocator) SimpleUndefinedAtom(*file, to);
- fromAtom->addReference(Reference::KindNamespace::all,
- Reference::KindArch::all, Reference::kindLayoutAfter,
- 0, toAtom, 0);
- file->addAtom(*fromAtom);
- file->addAtom(*toAtom);
- }
files.push_back(std::move(file));
LinkingContext::createInternalFiles(files);
}