1 // script.cc -- handle linker scripts for gold.
12 #include "workqueue.h"
21 // A token read from a script file. We don't implement keywords here;
22 // all keywords are simply represented as a string.
27 // Token classification.
32 // Token indicates end of input.
34 // Token is a string of characters.
36 // Token is an operator.
38 // Token is a number (an integer).
42 // We need an empty constructor so that we can put this STL objects.
44 : classification_(TOKEN_INVALID
), value_(), opcode_(0),
45 lineno_(0), charpos_(0)
48 // A general token with no value.
49 Token(Classification classification
, int lineno
, int charpos
)
50 : classification_(classification
), value_(), opcode_(0),
51 lineno_(lineno
), charpos_(charpos
)
53 gold_assert(classification
== TOKEN_INVALID
54 || classification
== TOKEN_EOF
);
57 // A general token with a value.
58 Token(Classification classification
, const std::string
& value
,
59 int lineno
, int charpos
)
60 : classification_(classification
), value_(value
), opcode_(0),
61 lineno_(lineno
), charpos_(charpos
)
63 gold_assert(classification
!= TOKEN_INVALID
64 && classification
!= TOKEN_EOF
);
67 // A token representing a string of characters.
68 Token(const std::string
& s
, int lineno
, int charpos
)
69 : classification_(TOKEN_STRING
), value_(s
), opcode_(0),
70 lineno_(lineno
), charpos_(charpos
)
73 // A token representing an operator.
74 Token(int opcode
, int lineno
, int charpos
)
75 : classification_(TOKEN_OPERATOR
), value_(), opcode_(opcode
),
76 lineno_(lineno
), charpos_(charpos
)
79 // Return whether the token is invalid.
82 { return this->classification_
== TOKEN_INVALID
; }
84 // Return whether this is an EOF token.
87 { return this->classification_
== TOKEN_EOF
; }
89 // Return the token classification.
91 classification() const
92 { return this->classification_
; }
94 // Return the line number at which the token starts.
97 { return this->lineno_
; }
99 // Return the character position at this the token starts.
102 { return this->charpos_
; }
104 // Get the value of a token.
109 gold_assert(this->classification_
== TOKEN_STRING
);
114 operator_value() const
116 gold_assert(this->classification_
== TOKEN_OPERATOR
);
117 return this->opcode_
;
121 integer_value() const
123 gold_assert(this->classification_
== TOKEN_INTEGER
);
124 return strtoll(this->value_
.c_str(), NULL
, 0);
128 // The token classification.
129 Classification classification_
;
130 // The token value, for TOKEN_STRING or TOKEN_INTEGER.
132 // The token value, for TOKEN_OPERATOR.
134 // The line number where this token started (one based).
136 // The character position within the line where this token started
141 // This class handles lexing a file into a sequence of tokens. We
142 // don't expect linker scripts to be large, so we just read them and
143 // tokenize them all at once.
148 Lex(Input_file
* input_file
)
149 : input_file_(input_file
), tokens_()
152 // Tokenize the file. Return the final token, which will be either
153 // an invalid token or an EOF token. An invalid token indicates
154 // that tokenization failed.
159 typedef std::vector
<Token
> Token_sequence
;
161 // Return the tokens.
162 const Token_sequence
&
164 { return this->tokens_
; }
168 Lex
& operator=(const Lex
&);
170 // Read the file into a string buffer.
172 read_file(std::string
*);
174 // Make a general token with no value at the current location.
176 make_token(Token::Classification c
, const char* p
) const
177 { return Token(c
, this->lineno_
, p
- this->linestart_
+ 1); }
179 // Make a general token with a value at the current location.
181 make_token(Token::Classification c
, const std::string
& v
, const char* p
)
183 { return Token(c
, v
, this->lineno_
, p
- this->linestart_
+ 1); }
185 // Make an operator token at the current location.
187 make_token(int opcode
, const char* p
) const
188 { return Token(opcode
, this->lineno_
, p
- this->linestart_
+ 1); }
190 // Make an invalid token at the current location.
192 make_invalid_token(const char* p
)
193 { return this->make_token(Token::TOKEN_INVALID
, p
); }
195 // Make an EOF token at the current location.
197 make_eof_token(const char* p
)
198 { return this->make_token(Token::TOKEN_EOF
, p
); }
200 // Return whether C can be the first character in a name. C2 is the
201 // next character, since we sometimes need that.
203 can_start_name(char c
, char c2
);
205 // Return whether C can appear in a name which has already started.
207 can_continue_name(char c
);
209 // Return whether C, C2, C3 can start a hex number.
211 can_start_hex(char c
, char c2
, char c3
);
213 // Return whether C can appear in a hex number.
215 can_continue_hex(char c
);
217 // Return whether C can start a non-hex number.
219 can_start_number(char c
);
221 // Return whether C can appear in a non-hex number.
223 can_continue_number(char c
)
224 { return Lex::can_start_number(c
); }
226 // If C1 C2 C3 form a valid three character operator, return the
227 // opcode. Otherwise return 0.
229 three_char_operator(char c1
, char c2
, char c3
);
231 // If C1 C2 form a valid two character operator, return the opcode.
232 // Otherwise return 0.
234 two_char_operator(char c1
, char c2
);
236 // If C1 is a valid one character operator, return the opcode.
237 // Otherwise return 0.
239 one_char_operator(char c1
);
241 // Read the next token.
243 get_token(const char**);
245 // Skip a C style /* */ comment. Return false if the comment did
248 skip_c_comment(const char**);
250 // Skip a line # comment. Return false if there was no newline.
252 skip_line_comment(const char**);
254 // Build a token CLASSIFICATION from all characters that match
255 // CAN_CONTINUE_FN. The token starts at START. Start matching from
256 // MATCH. Set *PP to the character following the token.
258 gather_token(Token::Classification
, bool (*can_continue_fn
)(char),
259 const char* start
, const char* match
, const char** pp
);
261 // Build a token from a quoted string.
263 gather_quoted_string(const char** pp
);
265 // The file we are reading.
266 Input_file
* input_file_
;
267 // The token sequence we create.
268 Token_sequence tokens_
;
269 // The current line number.
271 // The start of the current line in the buffer.
272 const char* linestart_
;
275 // Read the whole file into memory. We don't expect linker scripts to
276 // be large, so we just use a std::string as a buffer. We ignore the
277 // data we've already read, so that we read aligned buffers.
280 Lex::read_file(std::string
* contents
)
285 unsigned char buf
[BUFSIZ
];
288 this->input_file_
->file().read(off
, sizeof buf
, buf
, &got
);
289 contents
->append(reinterpret_cast<char*>(&buf
[0]), got
);
291 while (got
== sizeof buf
);
294 // Return whether C can be the start of a name, if the next character
295 // is C2. A name can being with a letter, underscore, period, or
296 // dollar sign. Because a name can be a file name, we also permit
297 // forward slash, backslash, and tilde. Tilde is the tricky case
298 // here; GNU ld also uses it as a bitwise not operator. It is only
299 // recognized as the operator if it is not immediately followed by
300 // some character which can appear in a symbol. That is, "~0" is a
301 // symbol name, and "~ 0" is an expression using bitwise not. We are
305 Lex::can_start_name(char c
, char c2
)
309 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
310 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
311 case 'M': case 'N': case 'O': case 'Q': case 'P': case 'R':
312 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
314 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
315 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
316 case 'm': case 'n': case 'o': case 'q': case 'p': case 'r':
317 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
319 case '_': case '.': case '$': case '/': case '\\':
323 return can_continue_name(c2
);
330 // Return whether C can continue a name which has already started.
331 // Subsequent characters in a name are the same as the leading
332 // characters, plus digits and "=+-:[],?*". So in general the linker
333 // script language requires spaces around operators.
336 Lex::can_continue_name(char c
)
340 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
341 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
342 case 'M': case 'N': case 'O': case 'Q': case 'P': case 'R':
343 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
345 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
346 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
347 case 'm': case 'n': case 'o': case 'q': case 'p': case 'r':
348 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
350 case '_': case '.': case '$': case '/': case '\\':
352 case '0': case '1': case '2': case '3': case '4':
353 case '5': case '6': case '7': case '8': case '9':
354 case '=': case '+': case '-': case ':': case '[': case ']':
355 case ',': case '?': case '*':
363 // For a number we accept 0x followed by hex digits, or any sequence
364 // of digits. The old linker accepts leading '$' for hex, and
365 // trailing HXBOD. Those are for MRI compatibility and we don't
366 // accept them. The old linker also accepts trailing MK for mega or
367 // kilo. Those are mentioned in the documentation, and we accept
370 // Return whether C1 C2 C3 can start a hex number.
373 Lex::can_start_hex(char c1
, char c2
, char c3
)
375 if (c1
== '0' && (c2
== 'x' || c2
== 'X'))
376 return Lex::can_continue_hex(c3
);
380 // Return whether C can appear in a hex number.
383 Lex::can_continue_hex(char c
)
387 case '0': case '1': case '2': case '3': case '4':
388 case '5': case '6': case '7': case '8': case '9':
389 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
390 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
398 // Return whether C can start a non-hex number.
401 Lex::can_start_number(char c
)
405 case '0': case '1': case '2': case '3': case '4':
406 case '5': case '6': case '7': case '8': case '9':
414 // If C1 C2 C3 form a valid three character operator, return the
415 // opcode (defined in the yyscript.h file generated from yyscript.y).
416 // Otherwise return 0.
419 Lex::three_char_operator(char c1
, char c2
, char c3
)
424 if (c2
== '<' && c3
== '=')
428 if (c2
== '>' && c3
== '=')
437 // If C1 C2 form a valid two character operator, return the opcode
438 // (defined in the yyscript.h file generated from yyscript.y).
439 // Otherwise return 0.
442 Lex::two_char_operator(char c1
, char c2
)
500 // If C1 is a valid operator, return the opcode. Otherwise return 0.
503 Lex::one_char_operator(char c1
)
536 // Skip a C style comment. *PP points to just after the "/*". Return
537 // false if the comment did not end.
540 Lex::skip_c_comment(const char** pp
)
543 while (p
[0] != '*' || p
[1] != '/')
554 this->linestart_
= p
+ 1;
563 // Skip a line # comment. Return false if there was no newline.
566 Lex::skip_line_comment(const char** pp
)
569 size_t skip
= strcspn(p
, "\n");
578 this->linestart_
= p
;
584 // Build a token CLASSIFICATION from all characters that match
585 // CAN_CONTINUE_FN. Update *PP.
588 Lex::gather_token(Token::Classification classification
,
589 bool (*can_continue_fn
)(char),
594 while ((*can_continue_fn
)(*match
))
597 return this->make_token(classification
,
598 std::string(start
, match
- start
),
602 // Build a token from a quoted string.
605 Lex::gather_quoted_string(const char** pp
)
607 const char* start
= *pp
;
608 const char* p
= start
;
610 size_t skip
= strcspn(p
, "\"\n");
612 return this->make_invalid_token(start
);
614 return this->make_token(Token::TOKEN_STRING
,
615 std::string(p
, skip
),
619 // Return the next token at *PP. Update *PP. General guideline: we
620 // require linker scripts to be simple ASCII. No unicode linker
621 // scripts. In particular we can assume that any '\0' is the end of
625 Lex::get_token(const char** pp
)
634 return this->make_eof_token(p
);
637 // Skip whitespace quickly.
638 while (*p
== ' ' || *p
== '\t')
645 this->linestart_
= p
;
649 // Skip C style comments.
650 if (p
[0] == '/' && p
[1] == '*')
652 int lineno
= this->lineno_
;
653 int charpos
= p
- this->linestart_
+ 1;
656 if (!this->skip_c_comment(pp
))
657 return Token(Token::TOKEN_INVALID
, lineno
, charpos
);
663 // Skip line comments.
667 if (!this->skip_line_comment(pp
))
668 return this->make_eof_token(p
);
674 if (Lex::can_start_name(p
[0], p
[1]))
675 return this->gather_token(Token::TOKEN_STRING
,
676 Lex::can_continue_name
,
679 // We accept any arbitrary name in double quotes, as long as it
680 // does not cross a line boundary.
684 return this->gather_quoted_string(pp
);
687 // Check for a number.
689 if (Lex::can_start_hex(p
[0], p
[1], p
[2]))
690 return this->gather_token(Token::TOKEN_INTEGER
,
691 Lex::can_continue_hex
,
694 if (Lex::can_start_number(p
[0]))
695 return this->gather_token(Token::TOKEN_INTEGER
,
696 Lex::can_continue_number
,
699 // Check for operators.
701 int opcode
= Lex::three_char_operator(p
[0], p
[1], p
[2]);
705 return this->make_token(opcode
, p
);
708 opcode
= Lex::two_char_operator(p
[0], p
[1]);
712 return this->make_token(opcode
, p
);
715 opcode
= Lex::one_char_operator(p
[0]);
719 return this->make_token(opcode
, p
);
722 return this->make_token(Token::TOKEN_INVALID
, p
);
726 // Tokenize the file. Return the final token.
731 std::string contents
;
732 this->read_file(&contents
);
734 const char* p
= contents
.c_str();
737 this->linestart_
= p
;
741 Token
t(this->get_token(&p
));
743 // Don't let an early null byte fool us into thinking that we've
744 // reached the end of the file.
746 && static_cast<size_t>(p
- contents
.c_str()) < contents
.length())
747 t
= this->make_invalid_token(p
);
749 if (t
.is_invalid() || t
.is_eof())
752 this->tokens_
.push_back(t
);
756 // A trivial task which waits for THIS_BLOCKER to be clear and then
757 // clears NEXT_BLOCKER. THIS_BLOCKER may be NULL.
759 class Script_unblock
: public Task
762 Script_unblock(Task_token
* this_blocker
, Task_token
* next_blocker
)
763 : this_blocker_(this_blocker
), next_blocker_(next_blocker
)
768 if (this->this_blocker_
!= NULL
)
769 delete this->this_blocker_
;
773 is_runnable(Workqueue
*)
775 if (this->this_blocker_
!= NULL
&& this->this_blocker_
->is_blocked())
781 locks(Workqueue
* workqueue
)
783 return new Task_locker_block(*this->next_blocker_
, workqueue
);
791 Task_token
* this_blocker_
;
792 Task_token
* next_blocker_
;
795 // This class holds data passed through the parser to the lexer and to
796 // the parser support functions. This avoids global variables. We
797 // can't use global variables because we need not be called in the
803 Parser_closure(const char* filename
,
804 const Position_dependent_options
& posdep_options
,
806 const Lex::Token_sequence
* tokens
)
807 : filename_(filename
), posdep_options_(posdep_options
),
808 in_group_(in_group
), tokens_(tokens
),
809 next_token_index_(0), inputs_(NULL
)
812 // Return the file name.
815 { return this->filename_
; }
817 // Return the position dependent options. The caller may modify
819 Position_dependent_options
&
820 position_dependent_options()
821 { return this->posdep_options_
; }
823 // Return whether this script is being run in a group.
826 { return this->in_group_
; }
828 // Whether we are at the end of the token list.
831 { return this->next_token_index_
>= this->tokens_
->size(); }
833 // Return the next token.
837 const Token
* ret
= &(*this->tokens_
)[this->next_token_index_
];
838 ++this->next_token_index_
;
842 // Return the list of input files, creating it if necessary. This
843 // is a space leak--we never free the INPUTS_ pointer.
847 if (this->inputs_
== NULL
)
848 this->inputs_
= new Input_arguments();
849 return this->inputs_
;
852 // Return whether we saw any input files.
855 { return this->inputs_
!= NULL
&& !this->inputs_
->empty(); }
858 // The name of the file we are reading.
859 const char* filename_
;
860 // The position dependent options.
861 Position_dependent_options posdep_options_
;
862 // Whether we are currently in a --start-group/--end-group.
865 // The tokens to be returned by the lexer.
866 const Lex::Token_sequence
* tokens_
;
867 // The index of the next token to return.
868 unsigned int next_token_index_
;
869 // New input files found to add to the link.
870 Input_arguments
* inputs_
;
873 // FILE was found as an argument on the command line. Try to read it
874 // as a script. We've already read BYTES of data into P, but we
875 // ignore that. Return true if the file was handled.
878 read_input_script(Workqueue
* workqueue
, const General_options
& options
,
879 Symbol_table
* symtab
, Layout
* layout
,
880 const Dirsearch
& dirsearch
, Input_objects
* input_objects
,
881 Input_group
* input_group
,
882 const Input_argument
* input_argument
,
883 Input_file
* input_file
, const unsigned char*, off_t
,
884 Task_token
* this_blocker
, Task_token
* next_blocker
)
887 if (lex
.tokenize().is_invalid())
890 Parser_closure
closure(input_file
->filename().c_str(),
891 input_argument
->file().options(),
895 if (yyparse(&closure
) != 0)
898 // THIS_BLOCKER must be clear before we may add anything to the
899 // symbol table. We are responsible for unblocking NEXT_BLOCKER
900 // when we are done. We are responsible for deleting THIS_BLOCKER
901 // when it is unblocked.
903 if (!closure
.saw_inputs())
905 // The script did not add any files to read. Note that we are
906 // not permitted to call NEXT_BLOCKER->unblock() here even if
907 // THIS_BLOCKER is NULL, as we are not in the main thread.
908 workqueue
->queue(new Script_unblock(this_blocker
, next_blocker
));
912 for (Input_arguments::const_iterator p
= closure
.inputs()->begin();
913 p
!= closure
.inputs()->end();
917 if (p
+ 1 == closure
.inputs()->end())
921 nb
= new Task_token();
924 workqueue
->queue(new Read_symbols(options
, input_objects
, symtab
,
925 layout
, dirsearch
, &*p
,
926 input_group
, this_blocker
, nb
));
933 // Manage mapping from keywords to the codes expected by the bison
936 class Keyword_to_parsecode
939 // The structure which maps keywords to parsecodes.
940 struct Keyword_parsecode
944 // Corresponding parsecode.
948 // Return the parsecode corresponding KEYWORD, or 0 if it is not a
951 keyword_to_parsecode(const char* keyword
);
954 // The array of all keywords.
955 static const Keyword_parsecode keyword_parsecodes_
[];
957 // The number of keywords.
958 static const int keyword_count
;
961 // Mapping from keyword string to keyword parsecode. This array must
962 // be kept in sorted order. Parsecodes are looked up using bsearch.
963 // This array must correspond to the list of parsecodes in yyscript.y.
965 const Keyword_to_parsecode::Keyword_parsecode
966 Keyword_to_parsecode::keyword_parsecodes_
[] =
968 { "ABSOLUTE", ABSOLUTE
},
970 { "ALIGN", ALIGN_K
},
971 { "ASSERT", ASSERT_K
},
972 { "AS_NEEDED", AS_NEEDED
},
977 { "CONSTANT", CONSTANT
},
978 { "CONSTRUCTORS", CONSTRUCTORS
},
980 { "CREATE_OBJECT_SYMBOLS", CREATE_OBJECT_SYMBOLS
},
981 { "DATA_SEGMENT_ALIGN", DATA_SEGMENT_ALIGN
},
982 { "DATA_SEGMENT_END", DATA_SEGMENT_END
},
983 { "DATA_SEGMENT_RELRO_END", DATA_SEGMENT_RELRO_END
},
984 { "DEFINED", DEFINED
},
987 { "EXCLUDE_FILE", EXCLUDE_FILE
},
988 { "EXTERN", EXTERN
},
991 { "FORCE_COMMON_ALLOCATION", FORCE_COMMON_ALLOCATION
},
994 { "INCLUDE", INCLUDE
},
996 { "INHIBIT_COMMON_ALLOCATION", INHIBIT_COMMON_ALLOCATION
},
999 { "LENGTH", LENGTH
},
1000 { "LOADADDR", LOADADDR
},
1004 { "MEMORY", MEMORY
},
1007 { "NOCROSSREFS", NOCROSSREFS
},
1008 { "NOFLOAT", NOFLOAT
},
1009 { "NOLOAD", NOLOAD
},
1010 { "ONLY_IF_RO", ONLY_IF_RO
},
1011 { "ONLY_IF_RW", ONLY_IF_RW
},
1012 { "ORIGIN", ORIGIN
},
1013 { "OUTPUT", OUTPUT
},
1014 { "OUTPUT_ARCH", OUTPUT_ARCH
},
1015 { "OUTPUT_FORMAT", OUTPUT_FORMAT
},
1016 { "OVERLAY", OVERLAY
},
1018 { "PROVIDE", PROVIDE
},
1019 { "PROVIDE_HIDDEN", PROVIDE_HIDDEN
},
1021 { "SEARCH_DIR", SEARCH_DIR
},
1022 { "SECTIONS", SECTIONS
},
1023 { "SEGMENT_START", SEGMENT_START
},
1025 { "SIZEOF", SIZEOF
},
1026 { "SIZEOF_HEADERS", SIZEOF_HEADERS
},
1027 { "SORT_BY_ALIGNMENT", SORT_BY_ALIGNMENT
},
1028 { "SORT_BY_NAME", SORT_BY_NAME
},
1029 { "SPECIAL", SPECIAL
},
1031 { "STARTUP", STARTUP
},
1032 { "SUBALIGN", SUBALIGN
},
1033 { "SYSLIB", SYSLIB
},
1034 { "TARGET", TARGET_K
},
1035 { "TRUNCATE", TRUNCATE
},
1036 { "VERSION", VERSIONK
},
1037 { "global", GLOBAL
},
1043 { "sizeof_headers", SIZEOF_HEADERS
},
1046 const int Keyword_to_parsecode::keyword_count
=
1047 (sizeof(Keyword_to_parsecode::keyword_parsecodes_
)
1048 / sizeof(Keyword_to_parsecode::keyword_parsecodes_
[0]));
1050 // Comparison function passed to bsearch.
1056 ktt_compare(const void* keyv
, const void* kttv
)
1058 const char* key
= static_cast<const char*>(keyv
);
1059 const Keyword_to_parsecode::Keyword_parsecode
* ktt
=
1060 static_cast<const Keyword_to_parsecode::Keyword_parsecode
*>(kttv
);
1061 return strcmp(key
, ktt
->keyword
);
1064 } // End extern "C".
1067 Keyword_to_parsecode::keyword_to_parsecode(const char* keyword
)
1069 void* kttv
= bsearch(keyword
,
1070 Keyword_to_parsecode::keyword_parsecodes_
,
1071 Keyword_to_parsecode::keyword_count
,
1072 sizeof(Keyword_to_parsecode::keyword_parsecodes_
[0]),
1076 Keyword_parsecode
* ktt
= static_cast<Keyword_parsecode
*>(kttv
);
1077 return ktt
->parsecode
;
1080 } // End namespace gold.
1082 // The remaining functions are extern "C", so it's clearer to not put
1083 // them in namespace gold.
1085 using namespace gold
;
1087 // This function is called by the bison parser to return the next
1091 yylex(YYSTYPE
* lvalp
, void* closurev
)
1093 Parser_closure
* closure
= static_cast<Parser_closure
*>(closurev
);
1095 if (closure
->at_eof())
1098 const Token
* token
= closure
->next_token();
1100 switch (token
->classification())
1103 case Token::TOKEN_INVALID
:
1104 case Token::TOKEN_EOF
:
1107 case Token::TOKEN_STRING
:
1109 const char* str
= token
->string_value().c_str();
1110 int parsecode
= Keyword_to_parsecode::keyword_to_parsecode(str
);
1113 lvalp
->string
= str
;
1117 case Token::TOKEN_OPERATOR
:
1118 return token
->operator_value();
1120 case Token::TOKEN_INTEGER
:
1121 lvalp
->integer
= token
->integer_value();
1126 // This function is called by the bison parser to report an error.
1129 yyerror(void* closurev
, const char* message
)
1131 Parser_closure
* closure
= static_cast<Parser_closure
*>(closurev
);
1133 fprintf(stderr
, _("%s: %s: %s\n"),
1134 program_name
, closure
->filename(), message
);
1138 // Called by the bison parser to add a file to the link.
1141 script_add_file(void* closurev
, const char* name
)
1143 Parser_closure
* closure
= static_cast<Parser_closure
*>(closurev
);
1144 Input_file_argument
file(name
, false, closure
->position_dependent_options());
1145 closure
->inputs()->add_file(file
);
1148 // Called by the bison parser to start a group. If we are already in
1149 // a group, that means that this script was invoked within a
1150 // --start-group --end-group sequence on the command line, or that
1151 // this script was found in a GROUP of another script. In that case,
1152 // we simply continue the existing group, rather than starting a new
1153 // one. It is possible to construct a case in which this will do
1154 // something other than what would happen if we did a recursive group,
1155 // but it's hard to imagine why the different behaviour would be
1156 // useful for a real program. Avoiding recursive groups is simpler
1157 // and more efficient.
1160 script_start_group(void* closurev
)
1162 Parser_closure
* closure
= static_cast<Parser_closure
*>(closurev
);
1163 if (!closure
->in_group())
1164 closure
->inputs()->start_group();
1167 // Called by the bison parser at the end of a group.
1170 script_end_group(void* closurev
)
1172 Parser_closure
* closure
= static_cast<Parser_closure
*>(closurev
);
1173 if (!closure
->in_group())
1174 closure
->inputs()->end_group();
1177 // Called by the bison parser to start an AS_NEEDED list.
1180 script_start_as_needed(void* closurev
)
1182 Parser_closure
* closure
= static_cast<Parser_closure
*>(closurev
);
1183 closure
->position_dependent_options().set_as_needed();
1186 // Called by the bison parser at the end of an AS_NEEDED list.
1189 script_end_as_needed(void* closurev
)
1191 Parser_closure
* closure
= static_cast<Parser_closure
*>(closurev
);
1192 closure
->position_dependent_options().clear_as_needed();