+2015-03-21 Cary Coutant <cary@google.com>
+
+ PR gold/18048
+ * script-c.h (script_include_directive): Add first_token parameter.
+ * script.cc (script_include_directive): Add first_token parameter, and
+ pass it to read_script_file.
+ * yyscript.y (PARSING_SECTIONS_BLOCK, PARSING_SECTION_CMDS)
+ (PARSING_MEMORY_DEF): New tokens.
+ (top): Add new productions for INCLUDE files.
+ (file_cmd): Replace file_or_sections_cmd with copy of its productions.
+ Pass PARSING_LINKER_SCRIPT to script_include_directive.
+ (section_block_cmd): Likewise; pass PARSING_SECTIONS_BLOCK.
+ (section_cmd): Pass PARSING_SECTION_CMDS.
+ (file_or_sections_cmd): Remove.
+ (memory_def): Pass PARSING_MEMORY_DEF.
+ * testsuite/Makefile.am (memory_test_2): New test.
+ * testsuite/Makefile.in: Regenerate.
+ * testsuite/memory_test_inc.t: New script file.
+ * testsuite/memory_test_inc_1.t.src: New script file.
+ * testsuite/memory_test_inc_2.t.src: New script file.
+ * testsuite/memory_test_inc_3.t.src: New script file.
+
2015-03-21 Cary Coutant <cary@google.com>
* dwp.cc (Sized_relobj_dwo::do_section_contents): Delete.
script_set_section_region(void*, const char*, size_t, int);
extern void
-script_include_directive(void *, const char*, size_t);
+script_include_directive(int, void *, const char*, size_t);
/* Called by the bison parser for expressions. */
}
extern "C" void
-script_include_directive(void* closurev, const char* filename, size_t length)
+script_include_directive(int first_token, void* closurev,
+ const char* filename, size_t length)
{
Parser_closure* closure = static_cast<Parser_closure*>(closurev);
std::string name(filename, length);
Command_line* cmdline = closure->command_line();
read_script_file(name.c_str(), cmdline, &cmdline->script_options(),
- PARSING_LINKER_SCRIPT, Lex::LINKER_SCRIPT);
+ first_token, Lex::LINKER_SCRIPT);
}
// Functions for memory regions.
memory_test.stdout: memory_test
$(TEST_READELF) -lWS $< > $@
+# Test INCLUDE directives in linker scripts.
+# The binary isn't runnable, so we just check that we can build it without errors.
+check_DATA += memory_test_2
+MOSTLYCLEANFILES += memory_test_inc_1.t memory_test_inc_2.t memory_test_inc_3.t
+memory_test_inc_1.t: $(srcdir)/memory_test_inc_1.t.src
+ cp $< $@
+memory_test_inc_2.t: $(srcdir)/memory_test_inc_2.t.src
+ cp $< $@
+memory_test_inc_3.t: $(srcdir)/memory_test_inc_3.t.src
+ cp $< $@
+memory_test_2: memory_test.o gcctestdir/ld $(srcdir)/memory_test.t memory_test_inc_1.t memory_test_inc_2.t memory_test_inc_3.t
+ $(LINK) -Bgcctestdir/ -nostartfiles -nostdlib -z max-page-size=0x1000 -z common-page-size=0x1000 -Wl,-T,$(srcdir)/memory_test.t -o $@ memory_test.o
+
if HAVE_PUBNAMES
# Test that --gdb-index functions correctly without gcc-generated pubnames.
@GCC_TRUE@@NATIVE_LINKER_TRUE@ no_version_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ strong_ref_weak_def.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ dyn_weak_ref.sh memory_test.sh
+
+# Test INCLUDE directives in linker scripts.
+# The binary isn't runnable, so we just check that we can build it without errors.
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_46 = exclude_libs_test.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_test.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ discard_locals_relocatable_test1.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ no_version_test.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ strong_ref_weak_def.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ dyn_weak_ref.stdout \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ memory_test.stdout
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ memory_test.stdout memory_test_2
@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_47 = exclude_libs_test.syms \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ libexclude_libs_test_1.a \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ libexclude_libs_test_2.a \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ dyn_weak_ref.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ libstart_lib_test.a \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ memory_test.stdout memory_test \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ memory_test.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ memory_test.o \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ memory_test_inc_1.t \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ memory_test_inc_2.t \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ memory_test_inc_3.t
@GCC_TRUE@@MCMODEL_MEDIUM_TRUE@@NATIVE_LINKER_TRUE@am__append_48 = large
@GCC_FALSE@large_DEPENDENCIES =
@MCMODEL_MEDIUM_FALSE@large_DEPENDENCIES =
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -nostartfiles -nostdlib -z max-page-size=0x1000 -z common-page-size=0x1000 -Wl,-T,$(srcdir)/memory_test.t -o $@ memory_test.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@memory_test.stdout: memory_test
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -lWS $< > $@
+@GCC_TRUE@@NATIVE_LINKER_TRUE@memory_test_inc_1.t: $(srcdir)/memory_test_inc_1.t.src
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ cp $< $@
+@GCC_TRUE@@NATIVE_LINKER_TRUE@memory_test_inc_2.t: $(srcdir)/memory_test_inc_2.t.src
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ cp $< $@
+@GCC_TRUE@@NATIVE_LINKER_TRUE@memory_test_inc_3.t: $(srcdir)/memory_test_inc_3.t.src
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ cp $< $@
+@GCC_TRUE@@NATIVE_LINKER_TRUE@memory_test_2: memory_test.o gcctestdir/ld $(srcdir)/memory_test.t memory_test_inc_1.t memory_test_inc_2.t memory_test_inc_3.t
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -nostartfiles -nostdlib -z max-page-size=0x1000 -z common-page-size=0x1000 -Wl,-T,$(srcdir)/memory_test.t -o $@ memory_test.o
@GCC_TRUE@@HAVE_PUBNAMES_TRUE@@NATIVE_LINKER_TRUE@gdb_index_test.o: gdb_index_test.cc
@GCC_TRUE@@HAVE_PUBNAMES_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -g -gno-pubnames -c -o $@ $<
@GCC_TRUE@@HAVE_PUBNAMES_TRUE@@NATIVE_LINKER_TRUE@gdb_index_test_1: gdb_index_test.o gcctestdir/ld
--- /dev/null
+MEMORY
+{
+ region1 : ORIGIN = 0x1000, LENGTH = 0x1000 ,
+ INCLUDE memory_test_inc_1.t
+ region3 (wx) : o = 0x4000, l = 4
+ region4 (!r) : o = 0x6000 + 60, len = 0x30 * 0x6
+}
+
+SECTIONS
+{
+ .sec0 : { *(*.sec0) }
+
+ .sec1 ORIGIN (region1) : { *(*.sec1) } AT> region2
+
+ INCLUDE memory_test_inc_2.t
+
+ .sec2 : { *(*.sec2) } > region3 AT> region4
+
+ .sec3 0x5000 : {
+ INCLUDE memory_test_inc_3.t
+ }
+
+ .sec4 : { *(*.sec4) } AT> region2
+
+ .sec5 : { LONG(0x5555) } > region2
+
+ /DISCARD/ : { *(*) }
+}
--- /dev/null
+ region2 (r) : org = 0x2000, len = 300
--- /dev/null
+ fred = ORIGIN (region1) + LENGTH (region1);
--- /dev/null
+ *(*.sec3)
%token PARSING_VERSION_SCRIPT
%token PARSING_DEFSYM
%token PARSING_DYNAMIC_LIST
+%token PARSING_SECTIONS_BLOCK
+%token PARSING_SECTION_COMMANDS
+%token PARSING_MEMORY_DEF
/* Non-terminal types, where needed. */
| PARSING_VERSION_SCRIPT version_script
| PARSING_DEFSYM defsym_expr
| PARSING_DYNAMIC_LIST dynamic_list_expr
+ | PARSING_SECTIONS_BLOCK sections_block
+ | PARSING_SECTION_COMMANDS section_cmds
+ | PARSING_MEMORY_DEF memory_defs
;
/* A file contains a list of commands. */
{ script_push_lex_into_version_mode(closure); }
version_script '}'
{ script_pop_lex_mode(closure); }
- | file_or_sections_cmd
+ | ENTRY '(' string ')'
+ { script_set_entry(closure, $3.value, $3.length); }
+ | assignment end
+ | ASSERT_K '(' parse_exp ',' string ')'
+ { script_add_assertion(closure, $3, $5.value, $5.length); }
+ | INCLUDE string
+ { script_include_directive(PARSING_LINKER_SCRIPT, closure,
+ $2.value, $2.length); }
| ignore_cmd
| ';'
;
/* A command which may appear within a SECTIONS block. */
section_block_cmd:
- file_or_sections_cmd
+ ENTRY '(' string ')'
+ { script_set_entry(closure, $3.value, $3.length); }
+ | assignment end
+ | ASSERT_K '(' parse_exp ',' string ')'
+ { script_add_assertion(closure, $3, $5.value, $5.length); }
+ | INCLUDE string
+ { script_include_directive(PARSING_SECTIONS_BLOCK, closure,
+ $2.value, $2.length); }
| string section_header
{ script_start_output_section(closure, $1.value, $1.length, &$2); }
'{' section_cmds '}' section_trailer
}
| SORT_BY_NAME '(' CONSTRUCTORS ')'
| INCLUDE string
- { script_include_directive(closure, $2.value, $2.length); }
+ { script_include_directive(PARSING_SECTION_COMMANDS, closure,
+ $2.value, $2.length); }
| ';'
;
}
;
-/* A command which may appear at the top level of a linker script, or
- within a SECTIONS block. */
-file_or_sections_cmd:
- ENTRY '(' string ')'
- { script_set_entry(closure, $3.value, $3.length); }
- | assignment end
- | ASSERT_K '(' parse_exp ',' string ')'
- { script_add_assertion(closure, $3, $5.value, $5.length); }
- | INCLUDE string
- { script_include_directive(closure, $2.value, $2.length); }
- ;
-
/* A list of MEMORY definitions. */
memory_defs:
memory_defs opt_comma memory_def
string memory_attr ':' memory_origin '=' parse_exp opt_comma memory_length '=' parse_exp
{ script_add_memory(closure, $1.value, $1.length, $2, $6, $10); }
|
- /* LD supports an INCLUDE directive here, currently GOLD does not. */
INCLUDE string
- { script_include_directive(closure, $2.value, $2.length); }
+ { script_include_directive(PARSING_MEMORY_DEF, closure,
+ $2.value, $2.length); }
|
;