Fix INCLUDE directive support for gold. 2015-03-03 Cary Coutant gold/ * 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. diff --git a/gold/script-c.h b/gold/script-c.h index 772c76c..dc11d29 100644 --- a/gold/script-c.h +++ b/gold/script-c.h @@ -434,7 +434,7 @@ extern void 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. */ diff --git a/gold/script.cc b/gold/script.cc index 5350afc..56f126c 100644 --- a/gold/script.cc +++ b/gold/script.cc @@ -3366,13 +3366,14 @@ script_parse_memory_attr(void* closurev, const char* attrs, size_t attrlen, } 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(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. diff --git a/gold/yyscript.y b/gold/yyscript.y index 87aab58..b519f54 100644 --- a/gold/yyscript.y +++ b/gold/yyscript.y @@ -201,6 +201,9 @@ %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. */ @@ -232,6 +235,9 @@ top: | 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. */ @@ -281,7 +287,14 @@ file_cmd: { 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 | ';' ; @@ -339,7 +352,14 @@ sections_block: /* 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 @@ -529,7 +549,8 @@ section_cmd: } | 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); } | ';' ; @@ -683,18 +704,6 @@ wildcard_name: } ; -/* 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 @@ -706,9 +715,9 @@ 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); } | ;