diff --git a/gold/script.cc b/gold/script.cc index d6aa7b2..c242320 100644 --- a/gold/script.cc +++ b/gold/script.cc @@ -1590,7 +1590,7 @@ read_script_file(const char* filename, Command_line* cmdline, Parser_closure closure(filename, cmdline->position_dependent_options(), first_token == Lex::DYNAMIC_LIST, - false, + cmdline->inputs().in_group(), input_file.is_in_sysroot(), cmdline, script_options, @@ -2682,7 +2682,10 @@ script_add_file(void* closurev, const char* name, size_t length) Input_file_argument::INPUT_FILE_TYPE_FILE, extra_search_path, false, closure->position_dependent_options()); - Input_argument& arg = closure->inputs()->add_file(file); + Input_arguments* inputs = (closure->command_line() != NULL) + ? &(closure->command_line()->inputs()) + : closure->inputs(); + Input_argument& arg = inputs->add_file(file); arg.set_script_info(closure->script_info()); } @@ -2701,7 +2704,10 @@ script_add_library(void* closurev, const char* name, size_t length) Input_file_argument::INPUT_FILE_TYPE_LIBRARY, "", false, closure->position_dependent_options()); - Input_argument& arg = closure->inputs()->add_file(file); + Input_arguments* inputs = (closure->command_line() != NULL) + ? &(closure->command_line()->inputs()) + : closure->inputs(); + Input_argument& arg = inputs->add_file(file); arg.set_script_info(closure->script_info()); } @@ -2721,7 +2727,12 @@ script_start_group(void* closurev) { Parser_closure* closure = static_cast(closurev); if (!closure->in_group()) - closure->inputs()->start_group(); + { + if (closure->command_line() != NULL) + closure->command_line()->inputs().start_group(); + else + closure->inputs()->start_group(); + } } // Called by the bison parser at the end of a group. @@ -2731,7 +2742,12 @@ script_end_group(void* closurev) { Parser_closure* closure = static_cast(closurev); if (!closure->in_group()) - closure->inputs()->end_group(); + { + if (closure->command_line() != NULL) + closure->command_line()->inputs().end_group(); + else + closure->inputs()->end_group(); + } } // Called by the bison parser to start an AS_NEEDED list. diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index c8d3093..43c316d 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -1993,6 +1993,24 @@ script_test_14: $(srcdir)/script_test_14.t script_test_14.o gcctestdir/ld script_test_14.stdout: script_test_14 $(TEST_OBJDUMP) -s script_test_14 > $@ +# Test for INPUT and GROUP in a linker script added with -T +check_PROGRAMS += script_test_15 +MOSTLYCLEANFILES += libscript_test_15.a +script_test_15_SOURCES = +script_test_15_DEPENDENCIES = gcctestdir/ld libscript_test_15.a script_test_15a.o script_test_15c.o $(srcdir)/script_test_15.t +script_test_15_LDFLAGS = -Bgcctestdir/ -L. -Wl,-T,$(srcdir)/script_test_15.t +script_test_15_LDADD = +libscript_test_15.a: script_test_15b.o script_test_15d.o + $(TEST_AR) rc $@ $^ +script_test_15a.o: script_test_15a.c script_test_15.h + $(COMPILE) -O0 -c -o $@ $< +script_test_15b.o: script_test_15b.c script_test_15.h + $(COMPILE) -O0 -c -o $@ $< +script_test_15c.o: script_test_15c.c script_test_15.h + $(COMPILE) -O0 -c -o $@ $< +script_test_15d.o: script_test_15d.c script_test_15.h + $(COMPILE) -O0 -c -o $@ $< + # Test --dynamic-list, --dynamic-list-data, --dynamic-list-cpp-new, # and --dynamic-list-cpp-typeinfo diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 4185287..f0f4179 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -308,6 +308,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ # declared in a script file is assigned a non-zero starting address. # Test difference between "*(a b)" and "*(a) *(b)" in input section spec. + +# Test for INPUT and GROUP in a linker script added with -T @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_38 = many_sections_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ many_sections_r_test initpri1 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ initpri2 initpri3a \ @@ -331,7 +333,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ tls_phdrs_script_test \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ tls_script_test script_test_11 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_12 script_test_12i \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ dynamic_list_2 \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_15 dynamic_list_2 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ thin_archive_test_1 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ thin_archive_test_2 @GCC_FALSE@many_sections_test_DEPENDENCIES = @@ -362,7 +364,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4 script_test_5 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_6 script_test_7 \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_8 script_test_9 \ -@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_14 dynamic_list \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_14 \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ libscript_test_15.a dynamic_list \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ dynamic_list.stdout libthin1.a \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ libthin3.a libthinall.a \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ alt/thin_archive_test_2.o \ @@ -470,6 +473,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @NATIVE_LINKER_FALSE@justsyms_exec_DEPENDENCIES = @GCC_FALSE@binary_test_DEPENDENCIES = @NATIVE_LINKER_FALSE@binary_test_DEPENDENCIES = +@GCC_FALSE@script_test_15_DEPENDENCIES = +@NATIVE_LINKER_FALSE@script_test_15_DEPENDENCIES = @GCC_FALSE@thin_archive_test_2_DEPENDENCIES = @NATIVE_LINKER_FALSE@thin_archive_test_2_DEPENDENCIES = @@ -1083,6 +1088,7 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS) @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_11$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_12$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_12i$(EXEEXT) \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_15$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ dynamic_list_2$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ thin_archive_test_1$(EXEEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ thin_archive_test_2$(EXEEXT) @@ -1925,6 +1931,10 @@ script_test_12i_DEPENDENCIES = libgoldtest.a ../libgold.a \ ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) +am_script_test_15_OBJECTS = +script_test_15_OBJECTS = $(am_script_test_15_OBJECTS) +script_test_15_LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(script_test_15_LDFLAGS) $(LDFLAGS) -o $@ @GCC_TRUE@@NATIVE_LINKER_TRUE@am_script_test_2_OBJECTS = \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2.$(OBJEXT) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_2a.$(OBJEXT) \ @@ -2334,7 +2344,8 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \ $(relro_now_test_SOURCES) $(relro_script_test_SOURCES) \ $(relro_strip_test_SOURCES) $(relro_test_SOURCES) \ $(script_test_1_SOURCES) script_test_11.c script_test_12.c \ - script_test_12i.c $(script_test_2_SOURCES) script_test_3.c \ + script_test_12i.c $(script_test_15_SOURCES) \ + $(script_test_2_SOURCES) script_test_3.c \ $(searched_file_test_SOURCES) start_lib_test.c \ $(thin_archive_test_1_SOURCES) $(thin_archive_test_2_SOURCES) \ $(tls_phdrs_script_test_SOURCES) $(tls_pic_test_SOURCES) \ @@ -3168,6 +3179,10 @@ LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@tls_script_test_DEPENDENCIES = $(tls_test_DEPENDENCIES) $(srcdir)/script_test_4.t @GCC_TRUE@@NATIVE_LINKER_TRUE@tls_script_test_LDFLAGS = $(tls_test_LDFLAGS) -Wl,-T,$(srcdir)/script_test_4.t @GCC_TRUE@@NATIVE_LINKER_TRUE@tls_script_test_LDADD = $(tls_test_LDADD) +@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_15_SOURCES = +@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_15_DEPENDENCIES = gcctestdir/ld libscript_test_15.a script_test_15a.o script_test_15c.o $(srcdir)/script_test_15.t +@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_15_LDFLAGS = -Bgcctestdir/ -L. -Wl,-T,$(srcdir)/script_test_15.t +@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_15_LDADD = @GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list_2_SOURCES = dynamic_list_2.cc @GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list_2_DEPENDENCIES = gcctestdir/ld dynamic_list_lib1.so dynamic_list_lib2.so @GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list_2_LDFLAGS = -Bgcctestdir/ -L. -Wl,-R,. -Wl,--no-as-needed @@ -4027,6 +4042,9 @@ script_test_1$(EXEEXT): $(script_test_1_OBJECTS) $(script_test_1_DEPENDENCIES) $ @NATIVE_LINKER_FALSE@script_test_12i$(EXEEXT): $(script_test_12i_OBJECTS) $(script_test_12i_DEPENDENCIES) $(EXTRA_script_test_12i_DEPENDENCIES) @NATIVE_LINKER_FALSE@ @rm -f script_test_12i$(EXEEXT) @NATIVE_LINKER_FALSE@ $(LINK) $(script_test_12i_OBJECTS) $(script_test_12i_LDADD) $(LIBS) +script_test_15$(EXEEXT): $(script_test_15_OBJECTS) $(script_test_15_DEPENDENCIES) $(EXTRA_script_test_15_DEPENDENCIES) + @rm -f script_test_15$(EXEEXT) + $(script_test_15_LINK) $(script_test_15_OBJECTS) $(script_test_15_LDADD) $(LIBS) script_test_2$(EXEEXT): $(script_test_2_OBJECTS) $(script_test_2_DEPENDENCIES) $(EXTRA_script_test_2_DEPENDENCIES) @rm -f script_test_2$(EXEEXT) $(script_test_2_LINK) $(script_test_2_OBJECTS) $(script_test_2_LDADD) $(LIBS) @@ -5380,6 +5398,8 @@ script_test_12.log: script_test_12$(EXEEXT) @p='script_test_12$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) script_test_12i.log: script_test_12i$(EXEEXT) @p='script_test_12i$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +script_test_15.log: script_test_15$(EXEEXT) + @p='script_test_15$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) dynamic_list_2.log: dynamic_list_2$(EXEEXT) @p='dynamic_list_2$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) thin_archive_test_1.log: thin_archive_test_1$(EXEEXT) @@ -6571,6 +6591,16 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -o $@ script_test_14.o -T $(srcdir)/script_test_14.t @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_14.stdout: script_test_14 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_OBJDUMP) -s script_test_14 > $@ +@GCC_TRUE@@NATIVE_LINKER_TRUE@libscript_test_15.a: script_test_15b.o script_test_15d.o +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AR) rc $@ $^ +@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_15a.o: script_test_15a.c script_test_15.h +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_15b.o: script_test_15b.c script_test_15.h +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_15c.o: script_test_15c.c script_test_15.h +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -o $@ $< +@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_15d.o: script_test_15d.c script_test_15.h +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list: basic_test.o gcctestdir/ld $(srcdir)/dynamic_list.t @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ basic_test.o \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ -Wl,--dynamic-list $(srcdir)/dynamic_list.t \ diff --git a/gold/testsuite/script_test_15.h b/gold/testsuite/script_test_15.h new file mode 100644 index 0000000..170acc6 --- /dev/null +++ b/gold/testsuite/script_test_15.h @@ -0,0 +1,3 @@ +extern int func_b(void); +extern int func_c(void); +extern int func_d(void); diff --git a/gold/testsuite/script_test_15.t b/gold/testsuite/script_test_15.t new file mode 100644 index 0000000..7c455ed --- /dev/null +++ b/gold/testsuite/script_test_15.t @@ -0,0 +1,2 @@ +INPUT(script_test_15a.o) +GROUP(-lscript_test_15 script_test_15c.o) diff --git a/gold/testsuite/script_test_15a.c b/gold/testsuite/script_test_15a.c new file mode 100644 index 0000000..8f43fa9 --- /dev/null +++ b/gold/testsuite/script_test_15a.c @@ -0,0 +1,42 @@ +/* script_test_15a.c -- a test case for gold + + Copyright (C) 2016 Free Software Foundation, Inc. + Written by Igor Kudrin . + + This file is part of gold. + + This program 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 3 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. + + This test checks INPUT and GROUP commands in linker scripts. + There are 4 source files for this test: + * script_test_15a.c - contains main() which calls func_b(). + * script_test_15b.c - contains func_b() which calls func_c(). + * script_test_15c.c - contains func_c() which calls func_d(). + * script_test_15d.c - contains func_d() which returns 0. + + script_test_15b.o and script_test_15d.o are put into a library, + which is referenced within the same GROUP as script_test_15c.o, + so that the backward reference from func_c() to func_d() should + be satisfied. +*/ + +#include "script_test_15.h" + +int +main(void) +{ + return func_b(); +} diff --git a/gold/testsuite/script_test_15b.c b/gold/testsuite/script_test_15b.c new file mode 100644 index 0000000..0c47618 --- /dev/null +++ b/gold/testsuite/script_test_15b.c @@ -0,0 +1,42 @@ +/* script_test_15b.c -- a test case for gold + + Copyright (C) 2016 Free Software Foundation, Inc. + Written by Igor Kudrin . + + This file is part of gold. + + This program 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 3 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. + + This test checks INPUT and GROUP commands in linker scripts. + There are 4 source files for this test: + * script_test_15a.c - contains main() which calls func_b(). + * script_test_15b.c - contains func_b() which calls func_c(). + * script_test_15c.c - contains func_c() which calls func_d(). + * script_test_15d.c - contains func_d() which returns 0. + + script_test_15b.o and script_test_15d.o are put into a library, + which is referenced within the same GROUP as script_test_15c.o, + so that the backward reference from func_c() to func_d() should + be satisfied. +*/ + +#include "script_test_15.h" + +int +func_b(void) +{ + return func_c(); +} diff --git a/gold/testsuite/script_test_15c.c b/gold/testsuite/script_test_15c.c new file mode 100644 index 0000000..28fb879 --- /dev/null +++ b/gold/testsuite/script_test_15c.c @@ -0,0 +1,42 @@ +/* script_test_15c.c -- a test case for gold + + Copyright (C) 2016 Free Software Foundation, Inc. + Written by Igor Kudrin . + + This file is part of gold. + + This program 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 3 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. + + This test checks INPUT and GROUP commands in linker scripts. + There are 4 source files for this test: + * script_test_15a.c - contains main() which calls func_b(). + * script_test_15b.c - contains func_b() which calls func_c(). + * script_test_15c.c - contains func_c() which calls func_d(). + * script_test_15d.c - contains func_d() which returns 0. + + script_test_15b.o and script_test_15d.o are put into a library, + which is referenced within the same GROUP as script_test_15c.o, + so that the backward reference from func_c() to func_d() should + be satisfied. +*/ + +#include "script_test_15.h" + +int +func_c(void) +{ + return func_d(); +} diff --git a/gold/testsuite/script_test_15d.c b/gold/testsuite/script_test_15d.c new file mode 100644 index 0000000..ccae625 --- /dev/null +++ b/gold/testsuite/script_test_15d.c @@ -0,0 +1,42 @@ +/* script_test_15d.c -- a test case for gold + + Copyright (C) 2016 Free Software Foundation, Inc. + Written by Igor Kudrin . + + This file is part of gold. + + This program 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 3 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. + + This test checks INPUT and GROUP commands in linker scripts. + There are 4 source files for this test: + * script_test_15a.c - contains main() which calls func_b(). + * script_test_15b.c - contains func_b() which calls func_c(). + * script_test_15c.c - contains func_c() which calls func_d(). + * script_test_15d.c - contains func_d() which returns 0. + + script_test_15b.o and script_test_15d.o are put into a library, + which is referenced within the same GROUP as script_test_15c.o, + so that the backward reference from func_c() to func_d() should + be satisfied. +*/ + +#include "script_test_15.h" + +int +func_d(void) +{ + return 0; +}