aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ld/ChangeLog14
-rw-r--r--ld/NEWS4
-rw-r--r--ld/ld.h3
-rw-r--r--ld/ld.texinfo16
-rw-r--r--ld/ldmain.c10
-rw-r--r--ld/lexsup.c10
-rw-r--r--ld/testsuite/ChangeLog10
-rw-r--r--ld/testsuite/ld-scripts/default-script.exp25
-rw-r--r--ld/testsuite/ld-scripts/default-script.s3
-rw-r--r--ld/testsuite/ld-scripts/default-script.t7
-rw-r--r--ld/testsuite/ld-scripts/default-script1.d6
-rw-r--r--ld/testsuite/ld-scripts/default-script2.d6
-rw-r--r--ld/testsuite/ld-scripts/default-script3.d6
-rw-r--r--ld/testsuite/ld-scripts/default-script4.d6
14 files changed, 125 insertions, 1 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 939087f..8bf6eca 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -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 27ce242..e4ebf94 100644
--- 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 0b978e5..e73ffe1 100644
--- 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;
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 51d7323..3c7b08f 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -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
diff --git a/ld/ldmain.c b/ld/ldmain.c
index 3f69639..eb59ba8 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -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)
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 4da9496..125a987 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -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;
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index a6e9635..e40246b 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -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
index 0000000..ade4259
--- /dev/null
+++ b/ld/testsuite/ld-scripts/default-script.exp
@@ -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
index 0000000..494fb62
--- /dev/null
+++ b/ld/testsuite/ld-scripts/default-script.s
@@ -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
index 0000000..fc70187
--- /dev/null
+++ b/ld/testsuite/ld-scripts/default-script.t
@@ -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
index 0000000..5e8bcc7
--- /dev/null
+++ b/ld/testsuite/ld-scripts/default-script1.d
@@ -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
index 0000000..dcc3104
--- /dev/null
+++ b/ld/testsuite/ld-scripts/default-script2.d
@@ -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
index 0000000..90ca593
--- /dev/null
+++ b/ld/testsuite/ld-scripts/default-script3.d
@@ -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
index 0000000..f8bba44
--- /dev/null
+++ b/ld/testsuite/ld-scripts/default-script4.d
@@ -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