]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld/
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 19 Jan 2007 14:51:27 +0000 (14:51 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 19 Jan 2007 14:51:27 +0000 (14:51 +0000)
2007-01-19 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-19 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.

14 files changed:
ld/ChangeLog
ld/NEWS
ld/ld.h
ld/ld.texinfo
ld/ldmain.c
ld/lexsup.c
ld/testsuite/ChangeLog
ld/testsuite/ld-scripts/default-script.exp [new file with mode: 0644]
ld/testsuite/ld-scripts/default-script.s [new file with mode: 0644]
ld/testsuite/ld-scripts/default-script.t [new file with mode: 0644]
ld/testsuite/ld-scripts/default-script1.d [new file with mode: 0644]
ld/testsuite/ld-scripts/default-script2.d [new file with mode: 0644]
ld/testsuite/ld-scripts/default-script3.d [new file with mode: 0644]
ld/testsuite/ld-scripts/default-script4.d [new file with mode: 0644]

index 939087f5f5babb7a6fcbffab81a412f864e8adb1..8bf6eca77b3eedc84a711ffe8140f2b12afbd68c 100644 (file)
@@ -1,3 +1,17 @@
+2007-01-19 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.
+
 2007-01-16  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/3831
diff --git a/ld/NEWS b/ld/NEWS
index 27ce242752ee7eb3f995ba54dd75ccab8487c03a..e4ebf947ce5393fe8e168336ac8b1988aa810a3b 100644 (file)
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,4 +1,8 @@
 -*- text -*-
+* Add a new command line option '--default-script=FILE' or '-dT FILE'
+  which specifies a replacement for the built in, default linker
+  script.
+
 * 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
diff --git a/ld/ld.h b/ld/ld.h
index 0b978e50185426d504947727e9380eb1cb73b234..e73ffe1d5e062f37994b303c42f6f344008c5d4b 100644 (file)
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -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;
index 51d7323b6f7ec828838b6a6d17f33aea7595289a..3c7b08f19dc50ab4d9f83bc9cb733998157b366d 100644 (file)
@@ -856,6 +856,22 @@ the current directory, @code{ld} looks for it in the directories
 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.  @xref{Scripts}.
+
+This option is similar to the @option{--script} option except that
+processing of the script is delayed until after the rest of the
+command line has been processed.  This allows options placed after the
+@option{--default-script} option on the command line to affect the
+behaviour of the linker script, which can be important when the linker
+command line cannot be directly controlled by the user.  (eg because
+the command line is being constructed by another tool, such as
+@samp{gcc}).
+
 @kindex -u @var{symbol}
 @kindex --undefined=@var{symbol}
 @cindex undefined symbol
index 3f696394bcdd9f2cce814931355b84f12d34ece6..eb59ba8076f045436f25e0a1180792b57f207522 100644 (file)
@@ -388,6 +388,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)
index 4da949625da08dbf84dff24a1d6cfb75728a21aa..125a987faad69aabd40cfb9cbe2e86fc7c2c4206 100644 (file)
@@ -159,7 +159,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
@@ -282,6 +283,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 },
@@ -1149,6 +1154,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;
index a6e96355d4554a5b61a4110e65319a77cc9ddfa9..e40246b5412a2670d53b9b407a1ac7544517f257 100644 (file)
@@ -1,3 +1,13 @@
+2007-01-19 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.
+
 2007-01-18  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/1283
diff --git a/ld/testsuite/ld-scripts/default-script.exp b/ld/testsuite/ld-scripts/default-script.exp
new file mode 100644 (file)
index 0000000..ade4259
--- /dev/null
@@ -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]
+}
+
diff --git a/ld/testsuite/ld-scripts/default-script.s b/ld/testsuite/ld-scripts/default-script.s
new file mode 100644 (file)
index 0000000..494fb62
--- /dev/null
@@ -0,0 +1,3 @@
+       .text
+text:
+       .long 0
diff --git a/ld/testsuite/ld-scripts/default-script.t b/ld/testsuite/ld-scripts/default-script.t
new file mode 100644 (file)
index 0000000..fc70187
--- /dev/null
@@ -0,0 +1,7 @@
+_START = DEFINED(_START) ? _START : 0x9000000;
+SECTIONS
+{
+  . = _START;
+  .text : {*(.text)}
+  /DISCARD/ : {*(*)}
+}
diff --git a/ld/testsuite/ld-scripts/default-script1.d b/ld/testsuite/ld-scripts/default-script1.d
new file mode 100644 (file)
index 0000000..5e8bcc7
--- /dev/null
@@ -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
diff --git a/ld/testsuite/ld-scripts/default-script2.d b/ld/testsuite/ld-scripts/default-script2.d
new file mode 100644 (file)
index 0000000..dcc3104
--- /dev/null
@@ -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
diff --git a/ld/testsuite/ld-scripts/default-script3.d b/ld/testsuite/ld-scripts/default-script3.d
new file mode 100644 (file)
index 0000000..90ca593
--- /dev/null
@@ -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
diff --git a/ld/testsuite/ld-scripts/default-script4.d b/ld/testsuite/ld-scripts/default-script4.d
new file mode 100644 (file)
index 0000000..f8bba44
--- /dev/null
@@ -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