[lld] r208813 - Add -print_atoms options to DarwinLdDriver which dumps final state of all atoms in yaml

Nick Kledzik kledzik at apple.com
Wed May 14 14:32:21 PDT 2014


Author: kledzik
Date: Wed May 14 16:32:21 2014
New Revision: 208813

URL: http://llvm.org/viewvc/llvm-project?rev=208813&view=rev
Log:
Add -print_atoms options to DarwinLdDriver which dumps final state of all atoms in yaml

Modified:
    lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
    lld/trunk/lib/Driver/DarwinLdDriver.cpp
    lld/trunk/lib/Driver/DarwinLdOptions.td
    lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
    lld/trunk/lib/ReaderWriter/MachO/WriterMachO.cpp

Modified: lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h?rev=208813&r1=208812&r2=208813&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h (original)
+++ lld/trunk/include/lld/ReaderWriter/MachOLinkingContext.h Wed May 14 16:32:21 2014
@@ -77,6 +77,7 @@ public:
   bool minOS(StringRef mac, StringRef iOS) const;
   void setDoNothing(bool value) { _doNothing = value; }
   bool doNothing() const { return _doNothing; }
+  bool printAtoms() const { return _printAtoms; }
 
   /// \brief The dylib's binary compatibility version, in the raw uint32 format.
   ///
@@ -123,6 +124,7 @@ public:
     _deadStrippableDylib = deadStrippable;
   }
   void setBundleLoader(StringRef loader) { _bundleLoader = loader; }
+  void setPrintAtoms(bool value=true) { _printAtoms = value; }
   StringRef dyldPath() const { return "/usr/lib/dyld"; }
 
   static Arch archFromCpuType(uint32_t cputype, uint32_t cpusubtype);
@@ -163,6 +165,7 @@ private:
   uint32_t _currentVersion;
   StringRef _installName;
   bool _deadStrippableDylib;
+  bool _printAtoms;
   StringRef _bundleLoader;
   mutable std::unique_ptr<mach_o::KindHandler> _kindHandler;
   mutable std::unique_ptr<Writer> _writer;

Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=208813&r1=208812&r2=208813&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Wed May 14 16:32:21 2014
@@ -258,6 +258,10 @@ bool DarwinLdDriver::parse(int argc, con
     ctx.appendLLVMOption((*it)->getValue());
   }
 
+  // Handle -print_atoms a
+  if (parsedArgs->getLastArg(OPT_print_atoms))
+    ctx.setPrintAtoms();
+
   std::unique_ptr<InputGraph> inputGraph(new InputGraph());
 
   // Handle input files

Modified: lld/trunk/lib/Driver/DarwinLdOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdOptions.td?rev=208813&r1=208812&r2=208813&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdOptions.td (original)
+++ lld/trunk/lib/Driver/DarwinLdOptions.td Wed May 14 16:32:21 2014
@@ -70,6 +70,9 @@ def all_load : Flag<["-"], "all_load">,
         HelpText<"Forces all members of all static libraries to be loaded">,
         Group<grp_libs>;
 
+// test case options
+def print_atoms : Flag<["-"], "print_atoms">, 
+        HelpText<"Emit output as yaml atoms">;
 
 // general options
 def output : Separate<["-"], "o">, HelpText<"Output file path">;

Modified: lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp?rev=208813&r1=208812&r2=208813&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachOLinkingContext.cpp Wed May 14 16:32:21 2014
@@ -122,7 +122,8 @@ MachOLinkingContext::MachOLinkingContext
     : _outputFileType(MH_EXECUTE), _outputFileTypeStatic(false),
       _doNothing(false), _arch(arch_unknown), _os(OS::macOSX), _osMinVersion(0),
       _pageZeroSize(0), _pageSize(4096), _compatibilityVersion(0),
-      _currentVersion(0), _deadStrippableDylib(false), _kindHandler(nullptr) {}
+      _currentVersion(0), _deadStrippableDylib(false), _printAtoms(false),
+      _kindHandler(nullptr) {}
 
 MachOLinkingContext::~MachOLinkingContext() {}
 

Modified: lld/trunk/lib/ReaderWriter/MachO/WriterMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/WriterMachO.cpp?rev=208813&r1=208812&r2=208813&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/WriterMachO.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/WriterMachO.cpp Wed May 14 16:32:21 2014
@@ -39,8 +39,11 @@ public:
     if (error_code ec = nFile.getError())
       return ec;
 
-    // For debugging, write out yaml form of normalized file.
-    //writeYaml(*nFile->get(), llvm::errs());
+    // For testing, write out yaml form of normalized file.
+    if (_context.printAtoms()) {
+      std::unique_ptr<Writer> yamlWriter = createWriterYAML(_context);
+      yamlWriter->writeFile(file, "-");
+    }
 
     // Write normalized file as mach-o binary.
     return writeBinary(*nFile->get(), path);





More information about the llvm-commits mailing list