* ld --print-output-format switch
@ 2011-06-11 8:06 Roland McGrath
2011-07-03 8:52 ` Ian Lance Taylor
0 siblings, 1 reply; 5+ messages in thread
From: Roland McGrath @ 2011-06-11 8:06 UTC (permalink / raw)
To: binutils
This adds an ld option --print-output-format. The intent is to provide
some technique better than ld --verbose and matching the OUTPUT_FORMAT
command at the beginning of the linker script. (Library packages building
a trivial input-only linker script need to give it the right OUTPUT_FORMAT
command to ensure it gets accepted or skipped appropriately for the current
target in biarch installations.)
This emits just one target, never a triple as OUTPUT_FORMAT could take
for endian-switchable targets. I think it will emit the right one when
used with -EB or -EL on configurations where those are meaningful, but I
haven't tested such a target.
Ok for trunk?
If this goes in, someone should implement it for gold as well.
It was not very obvious to me how to go about it there.
Thanks,
Roland
ld/
2011-06-11 Roland McGrath <roland@hack.frob.com>
* ld.h (args_type): New field print_output_format.
* lexsup.c (enum option_values, ld_options, parse_args):
Handle --print-output-format.
* ldmain.c (main): Implement --print-output-format.
* ld.texinfo (Options): Document it.
diff --git a/ld/ld.h b/ld/ld.h
index 9391923..138fdec 100644
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -199,6 +199,9 @@ typedef struct {
input files. */
bfd_boolean accept_unknown_input_arch;
+ /* If TRUE we'll just print the default output on stdout. */
+ bfd_boolean print_output_format;
+
/* Big or little endian as set on command line. */
enum endian_enum endian;
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 0b58396..c8ac331 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -1401,6 +1401,13 @@ default behaviour (of not listing the sections that are removed) can
be restored by specifying @samp{--no-print-gc-sections} on the command
line.
+@kindex --print-output-format
+@cindex output format
+@item --print-output-format
+Print the name of the default output format (perhaps influenced by
+other command-line options). This is the string that would appear
+in an @code{OUTPUT_FORMAT} linker script command (@pxref{File Commands}).
+
@cindex help
@cindex usage
@kindex --help
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 1b4afff..88e34f0 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -427,11 +427,14 @@ main (int argc, char **argv)
info_msg ("\n==================================================\n");
}
+ if (command_line.print_output_format)
+ info_msg ("%s\n", default_target);
+
lang_final ();
if (!lang_has_input_file)
{
- if (version_printed)
+ if (version_printed || command_line.print_output_format)
xexit (0);
einfo (_("%P%F: no input files\n"));
}
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 08ef107..b5e52a8 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -175,6 +175,7 @@ enum option_values
OPTION_PLUGIN_OPT,
#endif /* ENABLE_PLUGINS */
OPTION_DEFAULT_SCRIPT,
+ OPTION_PRINT_OUTPUT_FORMAT,
};
/* The long options. This structure is used for both the option
@@ -491,6 +492,8 @@ static const struct ld_option ld_options[] =
{ {"oformat", required_argument, NULL, OPTION_OFORMAT},
'\0', N_("TARGET"), N_("Specify target of output file"),
EXACTLY_TWO_DASHES },
+ { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
+ '\0', NULL, N_("Print default output format"), TWO_DASHES },
{ {"qmagic", no_argument, NULL, OPTION_IGNORE},
'\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
{ {"reduce-memory-overheads", no_argument, NULL,
@@ -1059,6 +1062,9 @@ parse_args (unsigned argc, char **argv)
case OPTION_OFORMAT:
lang_add_output_format (optarg, NULL, NULL, 0);
break;
+ case OPTION_PRINT_OUTPUT_FORMAT:
+ command_line.print_output_format = TRUE;
+ break;
#ifdef ENABLE_PLUGINS
case OPTION_PLUGIN:
if (plugin_opt_plugin (optarg))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: ld --print-output-format switch
2011-06-11 8:06 ld --print-output-format switch Roland McGrath
@ 2011-07-03 8:52 ` Ian Lance Taylor
2011-07-09 16:52 ` Roland McGrath
0 siblings, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2011-07-03 8:52 UTC (permalink / raw)
To: Roland McGrath; +Cc: binutils
Roland McGrath <roland@hack.frob.com> writes:
> This adds an ld option --print-output-format. The intent is to provide
> some technique better than ld --verbose and matching the OUTPUT_FORMAT
> command at the beginning of the linker script. (Library packages building
> a trivial input-only linker script need to give it the right OUTPUT_FORMAT
> command to ensure it gets accepted or skipped appropriately for the current
> target in biarch installations.)
>
> This emits just one target, never a triple as OUTPUT_FORMAT could take
> for endian-switchable targets. I think it will emit the right one when
> used with -EB or -EL on configurations where those are meaningful, but I
> haven't tested such a target.
>
> Ok for trunk?
>
> If this goes in, someone should implement it for gold as well.
> It was not very obvious to me how to go about it there.
In general I like this idea and I would like somebody to approve it (I
don't approve many binutils patches these days outside of gold).
However, I don't see why this will do the right thing when used with -EB
or -EL, and it seems to me that this matters. Your patch prints
default_target, but as far as I can see -EB/-EL only affect
output_target. I think this does need to be tested to ensure that
-EL/-EB work correctly.
Ian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: ld --print-output-format switch
2011-07-03 8:52 ` Ian Lance Taylor
@ 2011-07-09 16:52 ` Roland McGrath
2011-07-16 8:43 ` Ian Lance Taylor
0 siblings, 1 reply; 5+ messages in thread
From: Roland McGrath @ 2011-07-09 16:52 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: binutils
> In general I like this idea and I would like somebody to approve it (I
> don't approve many binutils patches these days outside of gold).
You seemed like a good candidate to me because you're whom I expect will
implement it compatibly in gold.
> However, I don't see why this will do the right thing when used with -EB
> or -EL, and it seems to me that this matters. Your patch prints
> default_target, but as far as I can see -EB/-EL only affect
> output_target. I think this does need to be tested to ensure that
> -EL/-EB work correctly.
You're right, output_target is correct. However, it's sometimes not set.
I've fixed the patch and tested that it does the right thing for -EB vs -EL
(or default of -EL or of -EB) with a few targets like armelf_linux_eabi and
armelfb_linux_eabi as well as one like ppcmacos where output_target seems
to be NULL:
$ for m in armelf{b,}_linux_eabi ppcmacos; do for e in '' -EL -EB; do echo -n "$e $m:"; ./ld/ld-new -m $m $e --print-output-format; done; done
armelfb_linux_eabi:elf32-bigarm
-EL armelfb_linux_eabi:elf32-littlearm
-EB armelfb_linux_eabi:elf32-bigarm
armelf_linux_eabi:elf32-littlearm
-EL armelf_linux_eabi:elf32-littlearm
-EB armelf_linux_eabi:elf32-bigarm
ppcmacos:xcoff-powermac
-EL ppcmacos:xcoff-powermac
-EB ppcmacos:xcoff-powermac
$
Thanks,
Roland
ld/
2011-07-09 Roland McGrath <roland@hack.frob.com>
* ld.h (args_type): New field print_output_format.
* lexsup.c (enum option_values, ld_options, parse_args):
Handle --print-output-format.
* ldmain.c (main): Implement --print-output-format.
* ld.texinfo (Options): Document it.
* ldlang.c (lang_get_output_target): Don't return current_target
when it's NULL.
diff --git a/ld/ld.h b/ld/ld.h
index 9391923..138fdec 100644
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -199,6 +199,9 @@ typedef struct {
input files. */
bfd_boolean accept_unknown_input_arch;
+ /* If TRUE we'll just print the default output on stdout. */
+ bfd_boolean print_output_format;
+
/* Big or little endian as set on command line. */
enum endian_enum endian;
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 5a8e190..373a24e 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -1401,6 +1401,13 @@ default behaviour (of not listing the sections that are removed) can
be restored by specifying @samp{--no-print-gc-sections} on the command
line.
+@kindex --print-output-format
+@cindex output format
+@item --print-output-format
+Print the name of the default output format (perhaps influenced by
+other command-line options). This is the string that would appear
+in an @code{OUTPUT_FORMAT} linker script command (@pxref{File Commands}).
+
@cindex help
@cindex usage
@kindex --help
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 860ce27..c440940 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -3024,7 +3024,7 @@ lang_get_output_target (void)
/* No - has the current target been set to something other than
the default? */
- if (current_target != default_target)
+ if (current_target != default_target && current_target != NULL)
return current_target;
/* No - can we determine the format of the first input file? */
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 1b4afff..ec9dcff 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -427,11 +427,14 @@ main (int argc, char **argv)
info_msg ("\n==================================================\n");
}
+ if (command_line.print_output_format)
+ info_msg ("%s\n", lang_get_output_target ());
+
lang_final ();
if (!lang_has_input_file)
{
- if (version_printed)
+ if (version_printed || command_line.print_output_format)
xexit (0);
einfo (_("%P%F: no input files\n"));
}
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 08ef107..b5e52a8 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -175,6 +175,7 @@ enum option_values
OPTION_PLUGIN_OPT,
#endif /* ENABLE_PLUGINS */
OPTION_DEFAULT_SCRIPT,
+ OPTION_PRINT_OUTPUT_FORMAT,
};
/* The long options. This structure is used for both the option
@@ -491,6 +492,8 @@ static const struct ld_option ld_options[] =
{ {"oformat", required_argument, NULL, OPTION_OFORMAT},
'\0', N_("TARGET"), N_("Specify target of output file"),
EXACTLY_TWO_DASHES },
+ { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
+ '\0', NULL, N_("Print default output format"), TWO_DASHES },
{ {"qmagic", no_argument, NULL, OPTION_IGNORE},
'\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
{ {"reduce-memory-overheads", no_argument, NULL,
@@ -1059,6 +1062,9 @@ parse_args (unsigned argc, char **argv)
case OPTION_OFORMAT:
lang_add_output_format (optarg, NULL, NULL, 0);
break;
+ case OPTION_PRINT_OUTPUT_FORMAT:
+ command_line.print_output_format = TRUE;
+ break;
#ifdef ENABLE_PLUGINS
case OPTION_PLUGIN:
if (plugin_opt_plugin (optarg))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: ld --print-output-format switch
2011-07-09 16:52 ` Roland McGrath
@ 2011-07-16 8:43 ` Ian Lance Taylor
2011-07-16 11:07 ` Roland McGrath
0 siblings, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2011-07-16 8:43 UTC (permalink / raw)
To: Roland McGrath; +Cc: binutils
Roland McGrath <roland@hack.frob.com> writes:
> ld/
> 2011-07-09 Roland McGrath <roland@hack.frob.com>
>
> * ld.h (args_type): New field print_output_format.
> * lexsup.c (enum option_values, ld_options, parse_args):
> Handle --print-output-format.
> * ldmain.c (main): Implement --print-output-format.
> * ld.texinfo (Options): Document it.
>
> * ldlang.c (lang_get_output_target): Don't return current_target
> when it's NULL.
OK, since nobody seems to care about this patch, I'll approve it.
Maintainers, please scream if you disagree.
Thanks.
Ian
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-16 8:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-11 8:06 ld --print-output-format switch Roland McGrath
2011-07-03 8:52 ` Ian Lance Taylor
2011-07-09 16:52 ` Roland McGrath
2011-07-16 8:43 ` Ian Lance Taylor
2011-07-16 11:07 ` Roland McGrath
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).