public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: Rasmus Villemoes <rv@rasmusvillemoes.dk>, binutils@sourceware.org
Subject: Re: [PATCH] allow empty string as argument to -Map
Date: Thu, 28 May 2020 10:54:27 +0100	[thread overview]
Message-ID: <0fc094c4-c915-511c-c5da-2654811fbeec@redhat.com> (raw)
In-Reply-To: <7ad73b09-c551-9a17-f0fa-0839919158b4@rasmusvillemoes.dk>

[-- Attachment #1: Type: text/plain, Size: 1059 bytes --]

Hi Rasmus,

> That makes a lot of sense, thanks. And one can get "my" behaviour by
> passing "-Map=." or "-Map .", 

Ha!  I had not even though of that.

> ... eliminates the somewhat clumsy need to specify the empty string as
> argument, 

Agreed.

> So before this gets set in stone, can I retract my suggestion of
> assigning meaning to the empty string (maybe continue to handle it
> internally equivalent to ".", but not advertising it)?

I have made the change.  See the attached patch.  I decided that for
the empty string case it would be best to generate a message telling
the user and ignoring the map file request.


> (And perhaps change "map file" to "link map" or "linker map")

Also done.

Cheers
  Nick

ld/ChangeLog
2020-05-28  Nick Clifton  <nickc@redhat.com>

	* lexsup.c (parse_args): Generate an error if a name is not
	provided to the -Map option.
	(ld_options): Mention that the -Map option supports a directory
	name as an argument.
	* NEWS: Remove mention of support for an empty string as an
	argument to -Map.
	* ld.texi: Likewise.

[-- Attachment #2: map.patch --]
[-- Type: text/x-patch, Size: 3906 bytes --]

diff --git a/ld/NEWS b/ld/NEWS
index 98f07a73e1..2240aeb788 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,9 +1,8 @@
 -*- 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.
+  <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.
diff --git a/ld/ld.texi b/ld/ld.texi
index 52342523ed..cb38f47cd3 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -1760,12 +1760,10 @@ 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.  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.
+@option{-M} option, above.  Specifying a directory as @var{mapfile}
+causes the linker map to be written into a file inside the directory.
+The name of the file is based upon the @var{output} filename with
+@code{.map} appended.
 
 @cindex memory usage
 @kindex --no-keep-memory
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 49c4f23950..781f58aff7 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -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 (default: <outputname>.map)"), ONE_DASH },
+    '\0', N_("FILE/DIR"), N_("Write a linker map to FILE or DIR/<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 },
@@ -1598,29 +1598,33 @@ 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"));
+	  einfo (_("%P: no file/directory name provided for map output; ignored\n"));
+	  config.map_filename = NULL;
 	}
       else
 	{
 	  struct stat s;
 
 	  /* If the map filename is actually a directory then create
-	     a file inside it, again based upon the output filename.  */
+	     a file inside it, based upon the output filename.  */
 	  if (stat (config.map_filename, &s) >= 0
 	      && S_ISDIR (s.st_mode))
 	    {
 	      char * new_name;
 
-	      /* FIXME: Another memory leak.  */
+	      /* FIXME: This is a (trivial) 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"));
+		{
+		  /* If this alloc fails then something is probably very
+		     wrong.  Better to halt now rather than continue on
+		     into more problems.  */
+		  einfo (_("%P%F: cannot create name for linker map file: %E\n"));
+		  new_name = NULL;
+		}
+
 	      config.map_filename = new_name;
 	    }
 	}

  parent reply	other threads:[~2020-05-28  9:54 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26  7:01 Rasmus Villemoes
2020-05-27 16:50 ` Nick Clifton
2020-05-28  0:33   ` Rasmus Villemoes
2020-05-28  4:23     ` Fangrui Song
2020-05-28  9:54     ` Nick Clifton [this message]
2020-10-23 12:31       ` Rasmus Villemoes
2020-10-29 15:52         ` Nick Clifton
2020-10-30 12:37           ` Rasmus Villemoes
2020-10-30 16:35             ` Nick Clifton
2020-11-03  9:13               ` Rasmus Villemoes
2020-11-04 11:07                 ` Nick Clifton
2020-11-04 11:13                   ` Rasmus Villemoes
2020-11-05  0:47                     ` Fangrui Song
2020-11-05 10:01                       ` Nick Clifton
2020-11-05 11:41                       ` Nick Clifton
2020-11-05 12:23                         ` Rasmus Villemoes
2020-11-06 14:38                           ` Nick Clifton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0fc094c4-c915-511c-c5da-2654811fbeec@redhat.com \
    --to=nickc@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=rv@rasmusvillemoes.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).