{ {"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/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 },
}
}
+ /* Run a couple of checks on the map filename. */
+ if (config.map_filename)
+ {
+ if (config.map_filename[0] == 0)
+ {
+ 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, based upon the output filename. */
+ if (stat (config.map_filename, &s) >= 0
+ && S_ISDIR (s.st_mode))
+ {
+ char * new_name;
+
+ /* FIXME: This is a (trivial) memory leak. */
+ if (asprintf (&new_name, "%s/%s.map",
+ config.map_filename, output_filename) < 0)
+ {
+ /* 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;
+ }
+ }
+ }
+
if (command_line.soname && command_line.soname[0] == '\0')
{
einfo (_("%P: SONAME must not be empty string; ignored\n"));