[PATCH] D27595: COFF: Support both /lldmap and /lldmap:<file>

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 8 15:05:10 PST 2016


hans created this revision.
hans added a reviewer: ruiu.
hans added a subscriber: llvm-commits.

The former option bases the filename on the output name, e.g. if the
link output is a.exe, the map will be written to a.exe. This the
behaviour of link.exe's /MAP option and is useful for creating a map
file of each executable when building a large project.


https://reviews.llvm.org/D27595

Files:
  COFF/Driver.cpp
  COFF/Options.td
  test/COFF/lldmap.test


Index: test/COFF/lldmap.test
===================================================================
--- test/COFF/lldmap.test
+++ test/COFF/lldmap.test
@@ -1,6 +1,8 @@
 # RUN: yaml2obj < %p/Inputs/ret42.yaml > %t.obj
-# RUN: lld-link /out:%t.exe /entry:main /lldmap:%t.map %t.obj
-# RUN: FileCheck %s < %t.map
+# RUN: lld-link /out:%t.exe /entry:main /lldmap:%T/foo.map %t.obj
+# RUN: FileCheck %s < %T/foo.map
+# RUN: lld-link /out:%T/bar.exe /entry:main /lldmap %t.obj
+# RUN: FileCheck %s < %T/bar.map
 
 # CHECK: .obj:
 # CHECK-NEXT: 140001000 .text$mn
Index: COFF/Options.td
===================================================================
--- COFF/Options.td
+++ COFF/Options.td
@@ -95,7 +95,8 @@
 
 // Flags for debugging
 def dumppdb : Joined<["/", "-"], "dumppdb">;
-def lldmap : Joined<["/", "-"], "lldmap:">;
+def lldmap : F<"lldmap">;
+def lldmap_file : Joined<["/", "-"], "lldmap:">;
 
 //==============================================================================
 // The flags below do nothing. They are defined only for link.exe compatibility.
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -307,6 +307,15 @@
   return DebugTypes;
 }
 
+static std::string getMapFile(opt::Arg *A, StringRef OutName) {
+  if (A && A->getOption().getID() == OPT_lldmap_file) {
+    return A->getValue();
+  } else if (A && A->getOption().getID() == OPT_lldmap) {
+    return (OutName.substr(0, OutName.rfind('.')) + ".map").str();
+  }
+  return "";
+}
+
 void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
   // If the first command line argument is "/lib", link.exe acts like lib.exe.
   // We call our own implementation of lib.exe that understands bitcode files.
@@ -763,13 +772,16 @@
 
   // Create a symbol map file containing symbol VAs and their names
   // to help debugging.
-  if (auto *Arg = Args.getLastArg(OPT_lldmap)) {
+  std::string MapFile = getMapFile(Args.getLastArg(OPT_lldmap, OPT_lldmap_file),
+                                   Config->OutputFile);
+  if (!MapFile.empty()) {
     std::error_code EC;
-    raw_fd_ostream Out(Arg->getValue(), EC, OpenFlags::F_Text);
+    raw_fd_ostream Out(MapFile, EC, OpenFlags::F_Text);
     if (EC)
-      fatal(EC, "could not create the symbol map");
+      fatal(EC, "could not create the symbol map " + MapFile);
     Symtab.printMap(Out);
   }
+
   // Call exit to avoid calling destructors.
   exit(0);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27595.80831.patch
Type: text/x-patch
Size: 2467 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161208/1871fe8b/attachment.bin>


More information about the llvm-commits mailing list