[PATCH] allow empty string as argument to -Map
authorNick Clifton <nickc@redhat.com>
Wed, 27 May 2020 16:49:17 +0000 (17:49 +0100)
committerNick Clifton <nickc@redhat.com>
Wed, 27 May 2020 16:49:17 +0000 (17:49 +0100)
* lexsup.c (parse_args): If the map filename is defined but empty
create a name based upon the output file name.  If the name is
defined but refers to a directory create a file inside the
directory based on the output file name.
* ld.texi: Document the new feature.
* testsuite/ld-script/map-address.exp: Add test of new feature.
* NEWS: Mention the new feature.

ld/ChangeLog
ld/NEWS
ld/ld.texi
ld/lexsup.c
ld/testsuite/ld-scripts/map-address.exp

index 3fd9b7457ee87d3fbb1c923e8576fe5e27db2f64..fa0510d8bf627cdc250583be9177b41205536889 100644 (file)
@@ -1,3 +1,14 @@
+2020-05-27  Rasmus Villemoes <rv@rasmusvillemoes.dk>
+           Nick Clifton  <nickc@redhat.com>
+
+       * lexsup.c (parse_args): If the map filename is defined but empty
+       create a name based upon the output file name.  If the name is
+       defined but refers to a directory create a file inside the
+       directory based on the output file name.
+       * ld.texi: Document the new feature.
+       * testsuite/ld-script/map-address.exp: Add test of new feature.
+       * NEWS: Mention the new feature.
+
 2020-05-27  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/22909
diff --git a/ld/NEWS b/ld/NEWS
index 0aaa13d4874c1428849391422a56abd3708fcfe6..98f07a73e12c2ed7e0d9e18baa0b7e9d887e381a 100644 (file)
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,5 +1,10 @@
 -*- text -*-
 
+* The -Map=<filename> command line option has been extended so that if
+  <filename> is omitted then a file called <output-filename>.map will be
+  created.  Plus if <filename> is a directory then
+  <filename>/<output-filename>.map will be created.
+
 * Add a command-line option for ELF linker, --warn-textrel, to warn that
   DT_TEXTREL is set in a position-independent executable or shared object.
 
index a7ec0d01b3dd2675937ac6a5b57cd72e6f827cf1..52342523ed3372bf2c9bb5aec9db443eb99c870b 100644 (file)
@@ -1760,7 +1760,12 @@ Print a summary of all target-specific options on the standard output and exit.
 @kindex -Map=@var{mapfile}
 @item -Map=@var{mapfile}
 Print a link map to the file @var{mapfile}.  See the description of the
-@option{-M} option, above.
+@option{-M} option, above.  Specifying the empty string as @var{mapfile}
+(that is, @code{-Map=}) causes the link map to be written to a file
+named after the @var{output} file, with @code{.map} appended.
+Specifying a directory as @var{mapfile} causes the link map to be
+written into a file inside the directory.  The name of the file is
+again based upon the @var{output} filename with @code{.map} appended.
 
 @cindex memory usage
 @kindex --no-keep-memory
index 3733a7c8935a6c16286a6ff587978767dab6a4c3..49c4f23950dda582b35e4ab0291d2244356cafd1 100644 (file)
@@ -359,7 +359,7 @@ static const struct ld_option ld_options[] =
   { {"init", required_argument, NULL, OPTION_INIT},
     '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
   { {"Map", required_argument, NULL, OPTION_MAP},
-    '\0', N_("FILE"), N_("Write a map file"), ONE_DASH },
+    '\0', N_("[FILE]"), N_("Write a map file (default: <outputname>.map)"), ONE_DASH },
   { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON},
     '\0', NULL, N_("Do not define Common storage"), TWO_DASHES },
   { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
@@ -1595,6 +1595,37 @@ parse_args (unsigned argc, char **argv)
        }
     }
 
+  /* Run a couple of checks on the map filename.  */
+  if (config.map_filename)
+    {
+      /* If name has been provided then use the
+        output filename with a .map extension.  */
+      if (config.map_filename[0] == 0)
+       {
+         /* FIXME: This is a memory leak as the string is never freed.  */
+         if (asprintf (&config.map_filename, "%s.map", output_filename) < 0)
+           einfo (_("%F%P: %s: can not create name of map file: %E\n"));
+       }
+      else
+       {
+         struct stat s;
+
+         /* If the map filename is actually a directory then create
+            a file inside it, again based upon the output filename.  */
+         if (stat (config.map_filename, &s) >= 0
+             && S_ISDIR (s.st_mode))
+           {
+             char * new_name;
+
+             /* FIXME: Another memory leak.  */
+             if (asprintf (&new_name, "%s/%s.map",
+                           config.map_filename, output_filename) < 0)
+               einfo (_("%F%P: %s: can not create name of map file: %E\n"));
+             config.map_filename = new_name;
+           }
+       }
+    }
+
   if (command_line.soname && command_line.soname[0] == '\0')
     {
       einfo (_("%P: SONAME must not be empty string; ignored\n"));
index 0f9479a34f5c57ef24c8a3c7eb96bc7c864adc83..352a9d8f1efd9ce6e5370798dbbe2cfb6817d97c 100644 (file)
@@ -45,3 +45,25 @@ if {[regexp_diff \
 } else {
     pass $testname
 }
+
+set testname "map to directory"
+
+if {![ld_link $ld tmpdir/map-address \
+        "-T $srcdir/$subdir/map-address.t \
+         tmpdir/map-address.o \
+         -Map tmpdir --output fred"]} {
+    fail $testname
+    return
+}
+
+if [is_remote host] then {
+    remote_upload host "tmpdir/fred.map"
+}
+
+if {[regexp_diff \
+              "tmpdir/fred.map" \
+              "$srcdir/$subdir/map-address.d"]} {
+    fail $testname
+} else {
+    pass $testname
+}
This page took 0.030234 seconds and 4 git commands to generate.