This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Add --default-script/-dT


This patch implements:

http://sourceware.org/ml/binutils/2006-12/msg00290.html


H.J.
--
ld/

2007-01-17 H.J. Lu  <hongjiu.lu@intel.com>

	* NEWS: Mention --default-script/-dT.

	* ld.h (args_type): Add a default_script field.

	* ld.texinfo: Document --default-script/-dT.

	* ldmain.c (main): Handle command_line.default_script.

	* lexsup.c (option_values): Add OPTION_DEFAULT_SCRIPT.
	(ld_options): Add entries for --default-script and -dT.
	(parse_args): Handle --default-script/-dT.

ld/testsuite/

2007-01-17 H.J. Lu  <hongjiu.lu@intel.com>

	* ld-scripts/default-script.exp: New file.
	* ld-scripts/default-script.s: Likewise.
	* ld-scripts/default-script.t: Likewise.
	* ld-scripts/default-script1.d: Likewise.
	* ld-scripts/default-script2.d: Likewise.
	* ld-scripts/default-script3.d: Likewise.
	* ld-scripts/default-script4.d: Likewise.

--- ld/NEWS.script	2007-01-16 08:34:53.000000000 -0800
+++ ld/NEWS	2007-01-17 11:23:15.000000000 -0800
@@ -1,4 +1,7 @@
 -*- text -*-
+* Add --default-script/-dT for the default linker script, which will
+  be processed the last.
+
 * ELF: Add -Bsymbolic-functions, --dynamic-list-cpp-new, which puts C++
   operator new and delete on the dynamic list, and --dynamic-list-data,
   builtin list for --dynamic-list, which puts global data symbols on the
--- ld/ld.h.script	2007-01-17 11:23:15.000000000 -0800
+++ ld/ld.h	2007-01-17 11:23:15.000000000 -0800
@@ -191,6 +191,9 @@ typedef struct {
      .exports sections.  */
   char *version_exports_section;
 
+  /* Default linker script.  */
+  char *default_script;
+
   /* If TRUE (the default) check section addresses, once compute,
      fpor overlaps.  */
   bfd_boolean check_section_addresses;
--- ld/ld.texinfo.script	2007-01-17 11:23:15.000000000 -0800
+++ ld/ld.texinfo	2007-01-17 11:23:15.000000000 -0800
@@ -856,6 +856,16 @@ the current directory, @code{ld} looks f
 specified by any preceding @samp{-L} options.  Multiple @samp{-T}
 options accumulate.
 
+@kindex -dT @var{script}
+@kindex --default-script=@var{script}
+@cindex script files
+@item -dT @var{scriptfile}
+@itemx --default-script=@var{scriptfile}
+Use @var{scriptfile} as the default linker script. It is similar to
+@option{--script}. The difference is @var{scriptfile} will be processed
+the last after the rest of command line options, regardless the order
+in which @option{--default-script} appears on the command line.
+
 @kindex -u @var{symbol}
 @kindex --undefined=@var{symbol}
 @cindex undefined symbol
--- ld/ldmain.c.script	2007-01-17 11:23:15.000000000 -0800
+++ ld/ldmain.c	2007-01-17 11:23:15.000000000 -0800
@@ -427,6 +427,16 @@ main (int argc, char **argv)
      the -L's in argv have been processed.  */
   set_scripts_dir ();
 
+  /* If we have not already opened and parsed a linker script,
+     try the default script from command line first.  */
+  if (saved_script_handle == NULL
+      && command_line.default_script != NULL)
+    {
+      ldfile_open_command_file (command_line.default_script);
+      parser_input = input_script;
+      yyparse ();
+    }
+
   /* If we have not already opened and parsed a linker script
      read the emulation's appropriate default script.  */
   if (saved_script_handle == NULL)
--- ld/lexsup.c.script	2007-01-17 11:23:15.000000000 -0800
+++ ld/lexsup.c	2007-01-17 11:23:15.000000000 -0800
@@ -160,7 +160,8 @@ enum option_values
   OPTION_WARN_UNRESOLVED_SYMBOLS,
   OPTION_ERROR_UNRESOLVED_SYMBOLS,
   OPTION_WARN_SHARED_TEXTREL,
-  OPTION_REDUCE_MEMORY_OVERHEADS
+  OPTION_REDUCE_MEMORY_OVERHEADS,
+  OPTION_DEFAULT_SCRIPT
 };
 
 /* The long options.  This structure is used for both the option
@@ -283,6 +284,10 @@ static const struct ld_option ld_options
     't', NULL, N_("Trace file opens"), TWO_DASHES },
   { {"script", required_argument, NULL, 'T'},
     'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
+  { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
+    '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES },
+  { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
+    '\0', NULL, NULL, ONE_DASH },
   { {"undefined", required_argument, NULL, 'u'},
     'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
     TWO_DASHES },
@@ -1153,6 +1158,9 @@ parse_args (unsigned argc, char **argv)
 	  parser_input = input_script;
 	  yyparse ();
 	  break;
+	case OPTION_DEFAULT_SCRIPT:
+	  command_line.default_script = optarg;
+	  break;
 	case OPTION_SECTION_START:
 	  {
 	    char *optarg2;
--- ld/testsuite/ld-scripts/default-script.exp.script	2007-01-17 12:12:00.000000000 -0800
+++ ld/testsuite/ld-scripts/default-script.exp	2007-01-17 12:13:28.000000000 -0800
@@ -0,0 +1,25 @@
+# Test --default-script/-dT
+#   Copyright 2007
+#   Free Software Foundation, Inc.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+
+set test_list [lsort [glob -nocomplain $srcdir/$subdir/default-script*.d]]
+foreach t $test_list {
+    # We need to strip the ".d", but can leave the dirname.
+    verbose [file rootname $t]
+    run_dump_test [file rootname $t]
+}
+
--- ld/testsuite/ld-scripts/default-script.s.script	2007-01-17 12:12:00.000000000 -0800
+++ ld/testsuite/ld-scripts/default-script.s	2007-01-17 11:56:38.000000000 -0800
@@ -0,0 +1,3 @@
+	.text
+text:
+	.long 0
--- ld/testsuite/ld-scripts/default-script.t.script	2007-01-17 12:12:00.000000000 -0800
+++ ld/testsuite/ld-scripts/default-script.t	2007-01-17 12:10:01.000000000 -0800
@@ -0,0 +1,7 @@
+_START = DEFINED(_START) ? _START : 0x9000000;
+SECTIONS
+{
+  . = _START;
+  .text : {*(.text)}
+  /DISCARD/ : {*(*)}
+}
--- ld/testsuite/ld-scripts/default-script1.d.script	2007-01-17 12:12:00.000000000 -0800
+++ ld/testsuite/ld-scripts/default-script1.d	2007-01-17 12:08:01.000000000 -0800
@@ -0,0 +1,6 @@
+# source: default-script.s
+# ld: -defsym _START=0x8000000 -T default-script.t
+# nm: -n
+
+0*8000000 . _START
+0*8000000 t text
--- ld/testsuite/ld-scripts/default-script2.d.script	2007-01-17 12:12:00.000000000 -0800
+++ ld/testsuite/ld-scripts/default-script2.d	2007-01-17 12:09:21.000000000 -0800
@@ -0,0 +1,6 @@
+# source: default-script.s
+# ld: -T default-script.t -defsym _START=0x8000000
+# nm: -n
+
+0*8000000 . _START
+0*9000000 t text
--- ld/testsuite/ld-scripts/default-script3.d.script	2007-01-17 12:12:00.000000000 -0800
+++ ld/testsuite/ld-scripts/default-script3.d	2007-01-17 12:10:35.000000000 -0800
@@ -0,0 +1,6 @@
+# source: default-script.s
+# ld: -defsym _START=0x8000000 -dT default-script.t
+# nm: -n
+
+0*8000000 . _START
+0*8000000 t text
--- ld/testsuite/ld-scripts/default-script4.d.script	2007-01-17 12:12:00.000000000 -0800
+++ ld/testsuite/ld-scripts/default-script4.d	2007-01-17 12:12:43.000000000 -0800
@@ -0,0 +1,6 @@
+# source: default-script.s
+# ld: --default-script default-script.t -defsym _START=0x8000000
+# nm: -n
+
+0*8000000 . _START
+0*8000000 t text


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]