ld --verbose output
Nick Clifton
nickc@cambridge.redhat.com
Sat Aug 11 16:34:00 GMT 2001
Hi H.J, Hi Andrew,
> > Please try this complete patch. It is based on the one in my Linux
> > bintuils, which has been in since April. It passed "make check" on
> > Linux/x86.
I tried both patches, and in the end I settled on an amalgam of the
two (see below).
There were two problems with the patches. Firstly they would not dump
the linker script if it was specified to LD via the -T command line
switch. (Since the script was read during parse_args() and not in
main()). This might be considered unnecessary, since presumably if
you specified the script on the command line you can find and print it
out yourself, but we are shooting for consistency here, so I decided
that we should always print the script out, even if the user might
already know what it contains.
The second problem was that when dumping the external script the text
read into the buffer was not being terminated with a nul character.
Thus it was possible to see rubbish at the end of the dumped lines.
The patch below fixes both of these problems and also updates the
documentation to reflect the change in the behavior of the --verbose
switch.
Any comments or objections to my checking in this patch ?
Cheers
Nick
2001-08-12 H.J. Lu <hjl@gnu.org>
Andrew Haley <aph@cambridge.redhat.com>
Nick Clifton <nickc@redhat.com>
* ldgram.y (had_script): Change name to saved_script_handle.
Change type to file handle.
* ld.h (had_script): Rename and retype.
* ldfile.c (ldfile_open_command_file): Save the file handle
used in saved_script_handle.
* lexsup.c (parse_args): Do not allow -c option to alter
saved_script_handle.
* ldmain.c (main): Print out the linker script used if
--verbose is given. Check saved_script_handle to obtain the
external linker script used, or if NULL, dump the builtin
script.
* ld.texinfo: Document that --verbose now dumps the linker
script used, regardless of whether it was an internal or an
external script.
Index: ldgram.y
===================================================================
RCS file: /cvs/src/src/ld/ldgram.y,v
retrieving revision 1.11
diff -p -r1.11 ldgram.y
*** ldgram.y 2001/08/03 01:11:21 1.11
--- ldgram.y 2001/08/11 23:16:52
*************** static enum section_type sectype;
*** 50,56 ****
lang_memory_region_type *region;
boolean ldgram_want_filename = true;
! boolean had_script = false;
boolean force_make_executable = false;
boolean ldgram_in_script = false;
--- 50,56 ----
lang_memory_region_type *region;
boolean ldgram_want_filename = true;
! FILE * saved_script_handle = false;
boolean force_make_executable = false;
boolean ldgram_in_script = false;
Index: ld.h
===================================================================
RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.13
diff -p -r1.13 ld.h
*** ld.h 2001/08/03 01:11:21 1.13
--- ld.h 2001/08/11 23:16:43
*************** typedef enum {
*** 221,227 ****
lang_final_phase_enum
} lang_phase_type;
! extern boolean had_script;
extern boolean force_make_executable;
/* Non-zero if we are processing a --defsym from the command line. */
--- 221,227 ----
lang_final_phase_enum
} lang_phase_type;
! extern FILE * saved_script_handle;
extern boolean force_make_executable;
/* Non-zero if we are processing a --defsym from the command line. */
Index: ldfile.c
===================================================================
RCS file: /cvs/src/src/ld/ldfile.c,v
retrieving revision 1.11
diff -p -r1.11 ldfile.c
*** ldfile.c 2001/05/02 16:42:55 1.11
--- ldfile.c 2001/08/11 23:22:54
*************** ldfile_open_command_file (name)
*** 350,356 ****
ldfile_input_filename = name;
lineno = 1;
! had_script = true;
}
#ifdef GNU960
--- 350,357 ----
ldfile_input_filename = name;
lineno = 1;
!
! saved_script_handle = ldlex_input_stack;
}
#ifdef GNU960
Index: lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.37
diff -p -r1.37 lexsup.c
*** lexsup.c 2001/06/18 22:20:57 1.37
--- lexsup.c 2001/08/11 23:16:57
*************** the GNU General Public License. This pr
*** 1017,1027 ****
version information. Read it, but don't assume that
we've seen a linker script. */
{
! boolean hold_had_script;
! hold_had_script = had_script;
ldfile_open_command_file (optarg);
! had_script = hold_had_script;
parser_input = input_version_script;
yyparse ();
}
--- 1017,1027 ----
version information. Read it, but don't assume that
we've seen a linker script. */
{
! FILE * hold_script_handle;
! hold_script_handle = saved_script_handle;
ldfile_open_command_file (optarg);
! saved_script_handle = hold_script_handle;
parser_input = input_version_script;
yyparse ();
}
Index: ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.26
diff -p -r1.26 ldmain.c
*** ldmain.c 2001/08/02 23:12:02 1.26
--- ldmain.c 2001/08/11 23:16:53
*************** main (argc, argv)
*** 296,324 ****
the -L's in argv have been processed. */
set_scripts_dir ();
! if (had_script == false)
{
- /* Read the emulation's appropriate default script. */
int isfile;
! char *s = ldemul_get_script (&isfile);
if (isfile)
ldfile_open_command_file (s);
else
! {
! if (trace_file_tries)
! {
! info_msg (_("using internal linker script:\n"));
! info_msg ("==================================================\n");
! info_msg (s);
! info_msg ("\n==================================================\n");
! }
lex_string = s;
lex_redirect (s);
}
parser_input = input_script;
yyparse ();
lex_string = NULL;
}
lang_final ();
--- 296,349 ----
the -L's in argv have been processed. */
set_scripts_dir ();
! /* If we have not already opened and parsed a linker script
! read the emulation's appropriate default script. */
! if (saved_script_handle == false)
{
int isfile;
! char *s = ldemul_get_script (& isfile);
if (isfile)
ldfile_open_command_file (s);
else
! {
lex_string = s;
lex_redirect (s);
}
parser_input = input_script;
yyparse ();
lex_string = NULL;
+ }
+
+ if (trace_file_tries)
+ {
+ info_msg (_("using %s linker script:\n"),
+ saved_script_handle ? "external" : "internal");
+ info_msg ("==================================================\n");
+
+ if (saved_script_handle)
+ {
+ const int BSIZE = 8192;
+ size_t n;
+ char *buf = xmalloc (BSIZE);
+
+ rewind (saved_script_handle);
+ while ((n = fread (buf, 1, BSIZE - 1, saved_script_handle)) > 0)
+ {
+ buf [n] = 0;
+ info_msg (buf);
+ }
+ rewind (saved_script_handle);
+ free (buf);
+ }
+ else
+ {
+ int isfile;
+
+ info_msg (ldemul_get_script (& isfile));
+ }
+
+ info_msg ("\n==================================================\n");
}
lang_final ();
Index: ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.44
diff -p -r1.44 ld.texinfo
*** ld.texinfo 2001/08/03 01:11:21 1.44
--- ld.texinfo 2001/08/11 23:16:51
*************** for compatibility with other linkers, yo
*** 1339,1345 ****
@itemx --verbose
Display the version number for @code{ld} and list the linker emulations
supported. Display which input files can and cannot be opened. Display
! the linker script if using a default builtin script.
@kindex --version-script=@var{version-scriptfile}
@cindex version script, symbol versions
--- 1339,1345 ----
@itemx --verbose
Display the version number for @code{ld} and list the linker emulations
supported. Display which input files can and cannot be opened. Display
! the linker script being used by the linker.
@kindex --version-script=@var{version-scriptfile}
@cindex version script, symbol versions
More information about the Binutils
mailing list