[lld] 961c45f - [LLD][COFF] Generate map file even if no /out flag is present
Pengxuan Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 26 09:05:43 PDT 2022
Author: Pengxuan Zheng
Date: 2022-09-26T09:05:23-07:00
New Revision: 961c45fd9f4e289d7d5e3d990c611d2bb7f2f1fb
URL: https://github.com/llvm/llvm-project/commit/961c45fd9f4e289d7d5e3d990c611d2bb7f2f1fb
DIFF: https://github.com/llvm/llvm-project/commit/961c45fd9f4e289d7d5e3d990c611d2bb7f2f1fb.diff
LOG: [LLD][COFF] Generate map file even if no /out flag is present
Currently LLD does not generate a map file if no /out flag (e.g., /out:a.exe) is
present. This is because LLD derives the map file's name from the default output
file name is no output file name is specified explicitly on the command
line. However, in this case, the default output file name has not been set by
LLD yet when LLD tries to set the name of the map file. This patch fixes this
corner case by moving the logic handling map file flags to a place after the
default output file name is set.
Reviewed By: thakis
Differential Revision: https://reviews.llvm.org/D134559
Added:
Modified:
lld/COFF/Driver.cpp
lld/test/COFF/map.test
Removed:
################################################################################
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 25bb7b093df63..ead9e984604a9 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1919,25 +1919,6 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (config->mingw || config->debugDwarf)
config->warnLongSectionNames = false;
- 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");
- config->lldmapFile.clear();
- }
-
if (config->incremental && args.hasArg(OPT_profile)) {
warn("ignoring '/incremental' due to '/profile' specification");
config->incremental = false;
@@ -2143,6 +2124,25 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
return;
}
+ 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");
+ config->lldmapFile.clear();
+ }
+
if (shouldCreatePDB) {
// Put the PDB next to the image if no /pdb flag was passed.
if (config->pdbPath.empty()) {
diff --git a/lld/test/COFF/map.test b/lld/test/COFF/map.test
index d1079c1acd4f7..15c1ec104b07e 100644
--- a/lld/test/COFF/map.test
+++ b/lld/test/COFF/map.test
@@ -11,6 +11,11 @@
# 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
+# RUN: rm -rf %t && mkdir -p %t && cd %t
+# RUN: cp %t.obj map.test.tmp.obj
+# RUN: cp %t-dll.lib map.test.tmp-dll.lib
+# RUN: lld-link /entry:main map.test.tmp.obj map.test.tmp-dll.lib /map
+# RUN: FileCheck -check-prefix=MAP -strict-whitespace %s < map.test.tmp.map
# MAP: {{.*}}
# MAP-EMPTY:
More information about the llvm-commits
mailing list