[PATCH] [lld] Atoms created from command line options should be available in YAML

kledzik at apple.com kledzik at apple.com
Fri Aug 30 15:43:00 PDT 2013



================
Comment at: lib/Core/LinkingContext.cpp:55-72
@@ -52,1 +54,20 @@
 
+std::vector<std::unique_ptr<File>> LinkingContext::createInternalFiles() {
+  std::vector<std::unique_ptr<File> > result;
+  std::unique_ptr<SimpleFile> simpleFile(
+      new SimpleFile(*this, "command line option -u"));
+  for (auto ai : _initialUndefinedSymbols)
+    simpleFile->addAtom(
+        *(new (_allocator) SimpleUndefinedAtom(*simpleFile, ai)));
+  result.push_back(std::move(simpleFile));
+  StringRef entrySymbol = entrySymbolName();
+  if (!entrySymbol.empty()) {
+    std::unique_ptr<SimpleFile> entryFile(
+        new SimpleFile(*this, "command line option -entry"));
+    entryFile->addAtom(
+        *(new (_allocator) SimpleUndefinedAtom(*simpleFile, entrySymbol)));
+    result.push_back(std::move(entryFile));
+  }
+  return result;
+}
+
----------------
Can this be broken up into separate methods so that a subclass could re-use parts of it?  For example, one method for making the -u file, and another for making the entry point reference.  

================
Comment at: include/lld/ReaderWriter/PECOFFLinkingContext.h:128
@@ +127,3 @@
+  virtual void setEntrySymbolName(StringRef name) {
+    addInitialUndefinedSymbol(name);
+    LinkingContext::setEntrySymbolName(name);
----------------
Why the call to addInitialUndefinedSymbol() here?  What happens if this is called again with a different name?  The old name would still be in the initialUndef list.  

If the undef is just needed for dead code stripping, the Resolver should always put the entrypoint in the root set of atoms to not dead strip.

================
Comment at: lib/ReaderWriter/ELF/ELFLinkingContext.cpp:173-190
@@ -159,1 +172,20 @@
 
+std::vector<std::unique_ptr<File> > ELFLinkingContext::createInternalFiles() {
+  std::vector<std::unique_ptr<File> > result;
+  std::unique_ptr<SimpleFile> simpleFile(
+      new SimpleFile(*this, "command line option -u"));
+  for (auto ai : _initialUndefinedSymbols)
+    simpleFile->addAtom(
+        *(new (_allocator) CommandLineUndefinedAtom(*simpleFile, ai)));
+  result.push_back(std::move(simpleFile));
+  StringRef entrySymbol = entrySymbolName();
+  if (!entrySymbol.empty()) {
+    std::unique_ptr<SimpleFile> entryFile(
+        new SimpleFile(*this, "command line option -entry"));
+    entryFile->addAtom(
+        *(new (_allocator) SimpleUndefinedAtom(*entryFile, entrySymbol)));
+    result.push_back(std::move(entryFile));
+  }
+  return result;
+}
+
----------------
Once the base implementation of createInternalFiles() is modularized, parts can be re-used here.


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



More information about the llvm-commits mailing list