[PATCH] [TargetInfo] Move LinkerInputFile to TargetInfo and rename more specific name

Shankar Kalpathi Easwaran shankarke at gmail.com
Thu Jun 20 16:18:42 PDT 2013



================
Comment at: lib/Core/TargetInfo.cpp:19-35
@@ +18,19 @@
+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
----------------
If things are moved to TargetInfo, I would want to still keep LinkerInternalFile which can be used for multiple purposes. I want to use the LinkerInternalFile for a variety of things like for example 

a) --defsym option in the ELF linker to define 
b) symbols that are defined by --dynamic-list, and export options

This interface is very restrictive. 

I am not sure about other linkers they might want to keep the symbols specified by the -u option in the command line as weak symbols too.

I would want to stick with the implementation prior to this, so that targets have more control on what type of undefined atoms to add.

================
Comment at: lib/Core/TargetInfo.cpp:70-74
@@ -48,2 +69,7 @@
 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);
----------------
std::unique_ptr

================
Comment at: lib/ReaderWriter/ELF/OutputELFWriter.h:30-39
@@ -29,12 +29,3 @@
 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") {};
-};
-
 //===----------------------------------------------------------------------===//
----------------
Keep this file for reasons mentioned above. Want to use this for other purposes mentioned above.


http://llvm-reviews.chandlerc.com/D1016



More information about the llvm-commits mailing list