public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] allow empty string as argument to -Map
@ 2020-05-26  7:01 Rasmus Villemoes
  2020-05-27 16:50 ` Nick Clifton
  0 siblings, 1 reply; 17+ messages in thread
From: Rasmus Villemoes @ 2020-05-26  7:01 UTC (permalink / raw)
  To: binutils; +Cc: Rasmus Villemoes

In meta-build systems like Yocto, it's rather easy to add flags like
-fdata-sections, -ffunction-sections, -Wl,--gc-sections to global
CFLAGS/LDFLAGS. But when digging into what effect those had on the
build of a particular package, it would be nice to also have a map
file automatically generated. That's currently a bit harder, since it
requires patching the build system of each individual package to add
something like -Wl,-Map=$@.map somewhere.

My first instinct was to make the argument to -Map optional, but that
will of course break anybody that uses the form "-Map foo.map" rather
than "-Map=foo.map".

So, as the next best thing, use a previously bogus value (the empty
string) as a sentinel to indicate "use the output filename + .map".

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
---
 ld/ld.texi  | 4 +++-
 ld/lexsup.c | 5 +++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ld/ld.texi b/ld/ld.texi
index 9f562935be..25ce1d6524 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -1759,7 +1759,9 @@ 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.
 
 @cindex memory usage
 @kindex --no-keep-memory
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 2597e2d630..e7ab07b50f 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -1617,6 +1617,11 @@ parse_args (unsigned argc, char **argv)
 	}
     }
 
+  if (config.map_filename && !config.map_filename[0]) {
+    if (asprintf (&config.map_filename, "%s.map", output_filename) < 0)
+      einfo (_("%F%P: %s: can not create name of map file: %E\n"));
+  }
+
   if (command_line.soname && command_line.soname[0] == '\0')
     {
       einfo (_("%P: SONAME must not be empty string; ignored\n"));
-- 
2.23.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-11-06 14:38 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26  7:01 [PATCH] allow empty string as argument to -Map 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
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

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).