[PATCH] D134247: [LLD][COFF] Support /MAPINFO flag

Pengxuan Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 19 17:29:28 PDT 2022


pzheng created this revision.
pzheng added reviewers: rnk, thieta, thakis, hans, mstorsjo, ruiu.
Herald added a project: All.
pzheng requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch adds support for link.exe's /MAPINFO flag to lld-link.exe.

Here is a description of the flag from Microsoft
(https://learn.microsoft.com/en-us/cpp/build/reference/mapinfo-include-information-in-mapfile?view=msvc-170):

The /MAPINFO option tells the linker to include the specified information in a
 mapfile, which is created if you specify the /MAP option. EXPORTS tells the
 linker to include exported functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134247

Files:
  lld/COFF/Config.h
  lld/COFF/Driver.cpp
  lld/COFF/MapFile.cpp
  lld/COFF/Options.td
  lld/test/COFF/map.test


Index: lld/test/COFF/map.test
===================================================================
--- lld/test/COFF/map.test
+++ lld/test/COFF/map.test
@@ -8,6 +8,9 @@
 # RUN: lld-link /out:%t.exe /entry:main %t.obj %t-dll.lib /map /lldmap:%T/foo-lld.map
 # RUN: FileCheck -check-prefix=MAP -strict-whitespace %s < %t.map
 # RUN: FileCheck -check-prefix=LLDMAP -strict-whitespace %s < %T/foo-lld.map
+# RUN: lld-link /out:%t.dll /dll %t-dll.obj /export:exportfn1 \
+# RUN:   /export:foo=exportfn2 /map /mapinfo:exports
+# RUN: FileCheck -check-prefix=MAPINFO -strict-whitespace %s < %t.map
 
 # MAP: {{.*}}
 # MAP-EMPTY:
@@ -38,3 +41,12 @@
 # LLDMAP-NEXT: 00001000 00000026  4096 .text
 # LLDMAP-NEXT: 00001000 00000008     4         {{.*}}map.test.tmp.obj:(.text)
 # LLDMAP-NEXT: 00001000 00000000     0                 main
+
+# MAPINFO: Exports
+# MAPINFO-EMPTY:
+# MAPINFO-NEXT:  ordinal    name
+# MAPINFO-EMPTY:
+# MAPINFO-NEXT:        1    exportfn1
+# MAPINFO-NEXT:        2    exportfn3
+# MAPINFO-NEXT:        3    exportfn2
+# MAPINFO-NEXT:               exported name: foo
Index: lld/COFF/Options.td
===================================================================
--- lld/COFF/Options.td
+++ lld/COFF/Options.td
@@ -287,6 +287,7 @@
 def lldmap_file : P_priv<"lldmap">;
 def map : F<"map">;
 def map_file : P_priv<"map">;
+def map_info : P<"mapinfo", "Include the specified information in a map file">;
 def show_timing : F<"time">;
 def summary : F<"summary">;
 
Index: lld/COFF/MapFile.cpp
===================================================================
--- lld/COFF/MapFile.cpp
+++ lld/COFF/MapFile.cpp
@@ -315,6 +315,19 @@
   for (Defined *sym : staticSyms)
     os << staticSymStr[sym] << '\n';
 
+  // Print out the exported functions
+  if (config->mapInfo) {
+    os << "\n";
+    os << " Exports\n";
+    os << "\n";
+    os << "  ordinal    name\n\n";
+    for (Export &e : config->exports) {
+      os << format("  %7d", e.ordinal) << "    " << e.name << "\n";
+      if (!e.extName.empty() && e.extName != e.name)
+        os << "               exported name: " << e.extName << "\n";
+    }
+  }
+
   t4.stop();
   t1.stop();
 }
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -1922,6 +1922,16 @@
   config->lldmapFile = getMapFile(args, OPT_lldmap, OPT_lldmap_file);
   config->mapFile = getMapFile(args, OPT_map, OPT_map_file);
 
+  if (config->mapFile != "" && args.hasArg(OPT_map_info)) {
+    for (auto *arg : args.filtered(OPT_map_info)) {
+      std::string s = StringRef(arg->getValue()).lower();
+      if (s == "exports")
+        config->mapInfo = true;
+      else
+        error("unknown option: /mapinfo:" + s);
+    }
+  }
+
   if (config->lldmapFile != "" && config->lldmapFile == config->mapFile) {
     warn("/lldmap and /map have the same output file '" + config->mapFile +
          "'.\n>>> ignoring /lldmap");
Index: lld/COFF/Config.h
===================================================================
--- lld/COFF/Config.h
+++ lld/COFF/Config.h
@@ -208,6 +208,9 @@
   // Used for /map.
   std::string mapFile;
 
+  // Used for /mapinfo.
+  bool mapInfo = false;
+
   // Used for /thinlto-index-only:
   llvm::StringRef thinLTOIndexOnlyArg;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134247.461429.patch
Type: text/x-patch
Size: 3295 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220920/fc0c2ff6/attachment.bin>


More information about the llvm-commits mailing list