diff options
author | Nick Clifton <nickc@redhat.com> | 2020-05-27 17:49:17 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2020-05-27 17:49:17 +0100 |
commit | 198204a7f0255c0e25dcda6b7d6a72e666d689c1 (patch) | |
tree | dc802f5592620ef65711ded01600f38420541270 /ld/lexsup.c | |
parent | 17ee85fc2af74471e8c57502714a32bbeac5f1ae (diff) | |
download | binutils-gdb-198204a7f0255c0e25dcda6b7d6a72e666d689c1.tar.gz |
[PATCH] allow empty string as argument to -Map
* 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.
Diffstat (limited to 'ld/lexsup.c')
-rw-r--r-- | ld/lexsup.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/ld/lexsup.c b/ld/lexsup.c index 3733a7c8935..49c4f23950d 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"), 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")); |