[PATCH] [TargetInfo] Move LinkerInputFile to TargetInfo and rename more specific name
Rui Ueyama
ruiu at google.com
Thu Jun 20 16:02:26 PDT 2013
Hi shankarke,
This is a continuation of r184398. By moving this file object out of
ELFTargetInfo to TargetInfo, we can use this feature from other TargetInfo's.
http://llvm-reviews.chandlerc.com/D1016
Files:
lib/Core/TargetInfo.cpp
lib/ReaderWriter/ELF/OutputELFWriter.h
Index: lib/Core/TargetInfo.cpp
===================================================================
--- lib/Core/TargetInfo.cpp
+++ lib/Core/TargetInfo.cpp
@@ -7,12 +7,33 @@
//
//===----------------------------------------------------------------------===//
+#include "lld/Core/InputFiles.h"
#include "lld/Core/TargetInfo.h"
#include "lld/ReaderWriter/Writer.h"
+#include "lld/ReaderWriter/Simple.h"
#include "llvm/ADT/Triple.h"
namespace lld {
+namespace {
+/// \brief This acts as an pseudo file that the linker uses to add undefined
+/// symbols that are defined by using the linker options such as -u or
+/// --defsym option.
+class UndefinedSymbolsFile : public SimpleFile {
+public:
+ UndefinedSymbolsFile(const TargetInfo &ti)
+ : SimpleFile(ti, "Linker internal file") {
+ for (const StringRef symbolName : ti.undefinedSymbols()) {
+ auto *atom = new (_allocator.Allocate<SimpleUndefinedAtom *>())
+ SimpleUndefinedAtom(*this, symbolName);
+ addAtom(*atom);
+ }
+ }
+
+private:
+ llvm::BumpPtrAllocator _allocator;
+};
+} // anonymous namespace
TargetInfo::TargetInfo()
: Reader(*this), _deadStrip(false), _globalsAreDeadStripRoots(false),
@@ -46,7 +67,12 @@
}
void TargetInfo::addImplicitFiles(InputFiles& inputs) const {
- this->writer().addFiles(inputs);
+ // Symbols that are given by -u options are added here at the head of the
+ // list, so that the resolver will try to resolve them.
+ auto *file = new UndefinedSymbolsFile(*this);
+ inputs.prependFile(*file);
+
+ this->writer().addFiles(inputs);
}
void TargetInfo::addPasses(PassManager &pm) const {
Index: lib/ReaderWriter/ELF/OutputELFWriter.h
===================================================================
--- lib/ReaderWriter/ELF/OutputELFWriter.h
+++ lib/ReaderWriter/ELF/OutputELFWriter.h
@@ -28,15 +28,6 @@
template<class ELFT>
class OutputELFWriter;
-/// \brief This acts as a internal file that the linker uses to add
-/// undefined symbols that are defined by using the linker options such
-/// as -u, or --defsym option.
-template <class ELFT> class LinkerInternalFile : public CRuntimeFile<ELFT> {
-public:
- LinkerInternalFile(const ELFTargetInfo &ti)
- : CRuntimeFile<ELFT>(ti, "Linker Internal File") {};
-};
-
//===----------------------------------------------------------------------===//
// OutputELFWriter Class
//===----------------------------------------------------------------------===//
@@ -123,16 +114,14 @@
LLD_UNIQUE_BUMP_PTR(HashSection<ELFT>) _hashTable;
llvm::StringSet<> _soNeeded;
/// @}
- LinkerInternalFile<ELFT> _linkerInternalFile;
};
//===----------------------------------------------------------------------===//
// OutputELFWriter
//===----------------------------------------------------------------------===//
template <class ELFT>
OutputELFWriter<ELFT>::OutputELFWriter(const ELFTargetInfo &ti)
- : _targetInfo(ti), _targetHandler(ti.getTargetHandler<ELFT>()),
- _linkerInternalFile(ti) {
+ : _targetInfo(ti), _targetHandler(ti.getTargetHandler<ELFT>()) {
_layout = &_targetHandler.targetLayout();
}
@@ -238,12 +227,6 @@
void OutputELFWriter<ELFT>::addFiles(InputFiles &inputFiles) {
// Add all input Files that are defined by the target
_targetHandler.addFiles(inputFiles);
- // Add all symbols that are specified by the -u option
- // as part of the command line argument to lld
- for (auto ai : _targetInfo.undefinedSymbols())
- _linkerInternalFile.addUndefinedAtom(ai);
- // Make the linker internal file to be the first file
- inputFiles.prependFile(_linkerInternalFile);
}
template <class ELFT> void OutputELFWriter<ELFT>::createDefaultSections() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1016.1.patch
Type: text/x-patch
Size: 3709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130620/7240cf07/attachment.bin>
More information about the llvm-commits
mailing list