1999-05-03 09:29:11 +02:00
|
|
|
/* ldlex.h -
|
2018-01-03 06:17:27 +01:00
|
|
|
Copyright (C) 1991-2018 Free Software Foundation, Inc.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-06 16:09:45 +02:00
|
|
|
This file is part of the GNU Binutils.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-06 16:09:45 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
1999-05-03 09:29:11 +02:00
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-06 16:09:45 +02:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
2007-07-06 16:09:45 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
1999-05-03 09:29:11 +02:00
|
|
|
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
|
2007-07-06 16:09:45 +02:00
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
#ifndef LDLEX_H
|
|
|
|
#define LDLEX_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-05-26 13:13:20 +02:00
|
|
|
/* Codes used for the long options with no short synonyms. 150 isn't
|
|
|
|
special; it's just an arbitrary non-ASCII char value. */
|
|
|
|
enum option_values
|
|
|
|
{
|
|
|
|
OPTION_ASSERT = 150,
|
|
|
|
OPTION_CALL_SHARED,
|
|
|
|
OPTION_CREF,
|
|
|
|
OPTION_DEFSYM,
|
|
|
|
OPTION_DEMANGLE,
|
|
|
|
OPTION_DYNAMIC_LINKER,
|
2015-09-20 04:50:19 +02:00
|
|
|
OPTION_NO_DYNAMIC_LINKER,
|
2012-05-26 13:13:20 +02:00
|
|
|
OPTION_SYSROOT,
|
2016-07-15 18:49:08 +02:00
|
|
|
OPTION_OUT_IMPLIB,
|
2012-05-26 13:13:20 +02:00
|
|
|
OPTION_EB,
|
|
|
|
OPTION_EL,
|
|
|
|
OPTION_EMBEDDED_RELOCS,
|
|
|
|
OPTION_EXPORT_DYNAMIC,
|
|
|
|
OPTION_NO_EXPORT_DYNAMIC,
|
|
|
|
OPTION_HELP,
|
|
|
|
OPTION_IGNORE,
|
|
|
|
OPTION_MAP,
|
|
|
|
OPTION_NO_DEMANGLE,
|
|
|
|
OPTION_NO_KEEP_MEMORY,
|
|
|
|
OPTION_NO_WARN_MISMATCH,
|
|
|
|
OPTION_NO_WARN_SEARCH_MISMATCH,
|
|
|
|
OPTION_NOINHIBIT_EXEC,
|
|
|
|
OPTION_NON_SHARED,
|
|
|
|
OPTION_NO_WHOLE_ARCHIVE,
|
|
|
|
OPTION_OFORMAT,
|
|
|
|
OPTION_RELAX,
|
|
|
|
OPTION_NO_RELAX,
|
|
|
|
OPTION_RETAIN_SYMBOLS_FILE,
|
|
|
|
OPTION_RPATH,
|
|
|
|
OPTION_RPATH_LINK,
|
|
|
|
OPTION_SHARED,
|
|
|
|
OPTION_SONAME,
|
|
|
|
OPTION_SORT_COMMON,
|
|
|
|
OPTION_SORT_SECTION,
|
|
|
|
OPTION_STATS,
|
|
|
|
OPTION_SYMBOLIC,
|
|
|
|
OPTION_SYMBOLIC_FUNCTIONS,
|
|
|
|
OPTION_TASK_LINK,
|
|
|
|
OPTION_TBSS,
|
|
|
|
OPTION_TDATA,
|
|
|
|
OPTION_TTEXT,
|
|
|
|
OPTION_TTEXT_SEGMENT,
|
2012-12-18 21:42:43 +01:00
|
|
|
OPTION_TRODATA_SEGMENT,
|
2013-01-14 14:37:10 +01:00
|
|
|
OPTION_TLDATA_SEGMENT,
|
2012-05-26 13:13:20 +02:00
|
|
|
OPTION_TRADITIONAL_FORMAT,
|
|
|
|
OPTION_UR,
|
|
|
|
OPTION_VERBOSE,
|
|
|
|
OPTION_VERSION,
|
|
|
|
OPTION_VERSION_SCRIPT,
|
|
|
|
OPTION_VERSION_EXPORTS_SECTION,
|
|
|
|
OPTION_DYNAMIC_LIST,
|
|
|
|
OPTION_DYNAMIC_LIST_CPP_NEW,
|
|
|
|
OPTION_DYNAMIC_LIST_CPP_TYPEINFO,
|
|
|
|
OPTION_DYNAMIC_LIST_DATA,
|
|
|
|
OPTION_WARN_COMMON,
|
|
|
|
OPTION_WARN_CONSTRUCTORS,
|
|
|
|
OPTION_WARN_FATAL,
|
|
|
|
OPTION_NO_WARN_FATAL,
|
|
|
|
OPTION_WARN_MULTIPLE_GP,
|
|
|
|
OPTION_WARN_ONCE,
|
|
|
|
OPTION_WARN_SECTION_ALIGN,
|
|
|
|
OPTION_SPLIT_BY_RELOC,
|
|
|
|
OPTION_SPLIT_BY_FILE ,
|
|
|
|
OPTION_WHOLE_ARCHIVE,
|
|
|
|
OPTION_ADD_DT_NEEDED_FOR_DYNAMIC,
|
|
|
|
OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC,
|
|
|
|
OPTION_ADD_DT_NEEDED_FOR_REGULAR,
|
|
|
|
OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR,
|
|
|
|
OPTION_WRAP,
|
|
|
|
OPTION_FORCE_EXE_SUFFIX,
|
|
|
|
OPTION_GC_SECTIONS,
|
|
|
|
OPTION_NO_GC_SECTIONS,
|
|
|
|
OPTION_PRINT_GC_SECTIONS,
|
|
|
|
OPTION_NO_PRINT_GC_SECTIONS,
|
2016-12-16 04:12:02 +01:00
|
|
|
OPTION_GC_KEEP_EXPORTED,
|
2012-05-26 13:13:20 +02:00
|
|
|
OPTION_HASH_SIZE,
|
|
|
|
OPTION_CHECK_SECTIONS,
|
|
|
|
OPTION_NO_CHECK_SECTIONS,
|
|
|
|
OPTION_NO_UNDEFINED,
|
|
|
|
OPTION_INIT,
|
|
|
|
OPTION_FINI,
|
|
|
|
OPTION_SECTION_START,
|
|
|
|
OPTION_UNIQUE,
|
|
|
|
OPTION_TARGET_HELP,
|
|
|
|
OPTION_ALLOW_SHLIB_UNDEFINED,
|
|
|
|
OPTION_NO_ALLOW_SHLIB_UNDEFINED,
|
|
|
|
OPTION_ALLOW_MULTIPLE_DEFINITION,
|
|
|
|
OPTION_NO_UNDEFINED_VERSION,
|
|
|
|
OPTION_DEFAULT_SYMVER,
|
|
|
|
OPTION_DEFAULT_IMPORTED_SYMVER,
|
|
|
|
OPTION_DISCARD_NONE,
|
|
|
|
OPTION_SPARE_DYNAMIC_TAGS,
|
|
|
|
OPTION_NO_DEFINE_COMMON,
|
|
|
|
OPTION_NOSTDLIB,
|
|
|
|
OPTION_NO_OMAGIC,
|
|
|
|
OPTION_STRIP_DISCARDED,
|
|
|
|
OPTION_NO_STRIP_DISCARDED,
|
|
|
|
OPTION_ACCEPT_UNKNOWN_INPUT_ARCH,
|
|
|
|
OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH,
|
|
|
|
OPTION_PIE,
|
|
|
|
OPTION_UNRESOLVED_SYMBOLS,
|
|
|
|
OPTION_WARN_UNRESOLVED_SYMBOLS,
|
|
|
|
OPTION_ERROR_UNRESOLVED_SYMBOLS,
|
|
|
|
OPTION_WARN_SHARED_TEXTREL,
|
|
|
|
OPTION_WARN_ALTERNATE_EM,
|
|
|
|
OPTION_REDUCE_MEMORY_OVERHEADS,
|
|
|
|
#ifdef ENABLE_PLUGINS
|
|
|
|
OPTION_PLUGIN,
|
|
|
|
OPTION_PLUGIN_OPT,
|
|
|
|
#endif /* ENABLE_PLUGINS */
|
|
|
|
OPTION_DEFAULT_SCRIPT,
|
|
|
|
OPTION_PRINT_OUTPUT_FORMAT,
|
2014-10-17 13:06:56 +02:00
|
|
|
OPTION_PRINT_SYSROOT,
|
2012-10-22 15:33:49 +02:00
|
|
|
OPTION_IGNORE_UNRESOLVED_SYMBOL,
|
2014-08-09 02:26:41 +02:00
|
|
|
OPTION_PUSH_STATE,
|
|
|
|
OPTION_POP_STATE,
|
2018-04-17 23:47:13 +02:00
|
|
|
OPTION_DISABLE_MULTIPLE_DEFS_ABS,
|
2015-06-05 15:09:31 +02:00
|
|
|
OPTION_PRINT_MEMORY_USAGE,
|
2015-07-15 19:37:30 +02:00
|
|
|
OPTION_REQUIRE_DEFINED_SYMBOL,
|
ld: Extend options for altering orphan handling behaviour.
Replace the options --warn-orphan and --no-warn-orphan with a single
option --orphan-handling=MODE, where mode can be place, warn, error, and
discard.
Mode 'place' is the default, and is the current behaviour, placing the
orphan section into a suitable output section.
Mode 'warn' is the same as '--warn-orphan'. The orphan is also placed
using the same algorithm as for 'place'.
Mode 'error' is the same as '--warn-orphan' and '--fatal-warnings'.
Mode 'discard' assigns all output sections to the /DISCARD/ section.
ld/ChangeLog:
* ld.h (enum orphan_handling_enum): New.
(ld_config_type): Remove warn_orphan, add orphan_handling.
* ldemul.c (ldemul_place_orphan): Remove warning about orphan
sections.
* ldlang.c (ldlang_place_orphan): New function.
(lang_place_orphans): Call ldlang_place_orphan.
* ldlex.h (enum option_values): Remove OPTION_WARN_ORPHAN and
OPTION_NO_WARN_ORPHAN, add OPTION_ORPHAN_HANDLING.
* lexsup.c (ld_options): Remove 'warn-orphan' and
'no-warn-orphan', add 'orphan-handling'.
(parse_args): Remove handling for OPTION_WARN_ORPHAN and
OPTION_NO_WARN_ORPHAN, add handling for OPTION_ORPHAN_HANDLING.
* NEWS: Replace text about --warn-orphan with --orphan-handling.
* ld.texinfo (Options): Remove --warn-orphan entry and add
entry on --orphan-handling.
(Orphan Sections): Add reference to relevant command line options.
ld/testsuite/ChangeLog:
* ld-elf/elf.exp: Switch to rely on run_dump_test.
* ld-elf/orphan-5.l: Update expected output.
* ld-elf/orphan-5.d: New file.
* ld-elf/orphan-6.d: New file.
* ld-elf/orphan-6.l: New file.
* ld-elf/orphan-7.d: New file.
* ld-elf/orphan-7.map: New file.
* ld-elf/orphan-8.d: New file.
* ld-elf/orphan-8.map: New file.
2015-07-28 20:20:37 +02:00
|
|
|
OPTION_ORPHAN_HANDLING,
|
ld: Allow section groups to be resolved as part of a relocatable link
This commit adds a new linker feature: the ability to resolve section
groups as part of a relocatable link.
Currently section groups are automatically resolved when performing a
final link, and are carried through when performing a relocatable link.
By carried through this means that one copy of each section group (from
all the copies that might be found in all the input files) is placed
into the output file. Sections that are part of a section group will
not match input section specifiers within a linker script and are
forcibly kept as separate sections.
There is a slight resemblance between section groups and common
section. Like section groups, common sections are carried through when
performing a relocatable link, and resolved (allocated actual space)
only at final link time.
However, with common sections there is an ability to force the linker to
allocate space for the common sections when performing a relocatable
link, there's currently no such ability for section groups.
This commit adds such a mechanism. This new facility can be accessed in
two ways, first there's a command line switch --force-group-allocation,
second, there's a new linker script command FORCE_GROUP_ALLOCATION. If
one of these is used when performing a relocatable link then the linker
will resolve the section groups as though it were performing a final
link, the section group will be deleted, and the members of the group
will be placed like normal input sections. If there are multiple copies
of the group (from multiple input files) then only one copy of the group
members will be placed, the duplicate copies will be discarded.
Unlike common sections that have the --no-define-common command line
flag, and INHIBIT_COMMON_ALLOCATION linker script command there is no
way to prevent group resolution during a final link, this is because the
ELF gABI specifically prohibits the presence of SHT_GROUP sections in a
fully linked executable. However, the code as written should make
adding such a feature trivial, setting the new resolve_section_groups
flag to false during a final link should work as you'd expect.
bfd/ChangeLog:
* elf.c (_bfd_elf_make_section_from_shdr): Don't initially mark
SEC_GROUP sections as SEC_EXCLUDE.
(bfd_elf_set_group_contents): Replace use of abort with an assert.
(assign_section_numbers): Use resolve_section_groups flag instead
of relocatable link type.
(_bfd_elf_init_private_section_data): Use resolve_section_groups
flag instead of checking the final_link flag for part of the
checks in here. Fix white space as a result.
* elflink.c (elf_link_input_bfd): Use resolve_section_groups flag
instead of relocatable link type.
(bfd_elf_final_link): Likewise.
include/ChangeLog:
* bfdlink.h (struct bfd_link_info): Add new resolve_section_groups
flag.
ld/ChangeLog:
* ld.h (struct args_type): Add force_group_allocation field.
* ldgram.y: Add support for FORCE_GROUP_ALLOCATION.
* ldlex.h: Likewise.
* ldlex.l: Likewise.
* lexsup.c: Likewise.
* ldlang.c (unique_section_p): Check resolve_section_groups flag
not the relaxable link flag.
(lang_add_section): Discard section groups when we're resolving
groups. Clear the SEC_LINK_ONCE flag if we're resolving section
groups.
* ldmain.c (main): Initialise resolve_section_groups flag in
link_info based on command line flags.
* testsuite/ld-elf/group11.d: New file.
* testsuite/ld-elf/group12.d: New file.
* testsuite/ld-elf/group12.ld: New file.
* NEWS: Mention new features.
* ld.texinfo (Options): Document --force-group-allocation.
(Miscellaneous Commands): Document FORCE_GROUP_ALLOCATION.
2017-03-22 18:27:49 +01:00
|
|
|
OPTION_FORCE_GROUP_ALLOCATION,
|
2012-05-26 13:13:20 +02:00
|
|
|
};
|
|
|
|
|
1999-05-03 09:29:11 +02:00
|
|
|
/* The initial parser states. */
|
|
|
|
typedef enum input_enum {
|
|
|
|
input_selected, /* We've set the initial state. */
|
|
|
|
input_script,
|
|
|
|
input_mri_script,
|
|
|
|
input_version_script,
|
2006-09-07 19:16:34 +02:00
|
|
|
input_dynamic_list,
|
1999-05-03 09:29:11 +02:00
|
|
|
input_defsym
|
|
|
|
} input_type;
|
|
|
|
|
|
|
|
extern input_type parser_input;
|
|
|
|
|
|
|
|
extern unsigned int lineno;
|
|
|
|
extern const char *lex_string;
|
|
|
|
|
|
|
|
/* In ldlex.l. */
|
2003-06-28 07:28:54 +02:00
|
|
|
extern int yylex (void);
|
2012-03-08 06:29:33 +01:00
|
|
|
extern void lex_push_file (FILE *, const char *, unsigned int);
|
PR ld/13343
* ld.h (parsing_defsym): Delete.
* ldexp.c (exp_intop, exp_bigintop, exp_relop): Set type.filename.
(fold_binary, fold_name, exp_fold_tree_1, exp_get_vma, exp_get_fill,
exp_get_abs_int): Add tree arg for %S in error messages. Don't
fudge lineno.
(exp_binop, exp_unop, exp_nameop, exp_assop, exp_assert): Copy
type.filename from sub-tree.
(exp_trinop): Likewise, and use "cond" rather than "lhs".
* ldexp.h (node_type): Add filename field to struct.
* ldfile.c (ldfile_input_filename): Delete. Remove all refs.
* ldfile.h (ldfile_input_filename): Delete.
* ldgram.y (phdr_type, phdr_qualifiers, yyerror): Add NULL arg for
%S in error messages.
* ldemul.c (syslib_default, hll_default): Likewise.
* ldlang.c (lang_memory_region_lookup, lang_memory_region_alias,
lang_get_regions, lang_new_phdr): Likewise.
(lang_size_sections_1): Pass addr_tree for %S.
* ldlex.h (lex_redirect): Update prototype.
(ldlex_filename): Declare.
* ldlex.l (<EOF>): Don't set ldfile_input_filename.
(lex_redirect): Add fake_filename and count params. Push
fake_filename to file_name_stack and init lineno from count.
(ldlex_filename): New function.
(lex_warn_invalid): Use above.
* ldmain.c (main): Update lex_redirect call.
* ldmisc.c (vfinfo <%S>): Take file name and line number from
etree_type arg, or use current if arg is NULL.
* lexsup.c (parsing_defsym): Delete.
(parse_args <OPTION_DEFSYM>): Update lex_redirect call.
2012-02-17 15:09:57 +01:00
|
|
|
extern void lex_redirect (const char *, const char *, unsigned int);
|
2003-06-28 07:28:54 +02:00
|
|
|
extern void ldlex_script (void);
|
Allow unquoted = as the first character in ldscript input_list names
* ldlex.l (INPUTLIST): New start condition.
(comment pattern, ",", "(", ")", "AS_NEEDED")
({FILENAMECHAR1}{FILENAMECHAR}*, "-l"{FILENAMECHAR}+)
(quoted string pattern, whitespace pattern): Add INPUTLIST to
valid start conditions.
(<INPUTLIST>"="{FILENAMECHAR1}{FILENAMECHAR}*): New NAME rule.
(ldlex_inputlist): New start-condition-setter function.
* ldgram.y (input_list1): Rename from input_list. All recursive
use changed.
(input_list): New wrapper rule for input_list1, setting
INPUTLIST lexer state for the duration of parsing input_list1.
All this to say INPUT(=/path/to/file) and not be forced to use
INPUT("=/path/to/file") whenever there's a need to force a sysroot-
prefix. Still, IMHO it seems better to make use of a previously
invalid syntax and not only change the meaning of quoted =-prefixed
paths (though arguably that's not very useful before this patchset).
This got a little bit hairier than I'd expected: I had to add a new
lexer state (aka. start condition) to avoid a first "=" being lexed as
the token "=", despite that not making sense in constructs expecting
file-names in the first place. (The grammar doesn't allow for
expressions in any part of those lists.) I guess I *could* have made
it work using that token anyway, but I didn't like the idea that you
would be able to separate the "=" from the rest of the file-name with
whitespace.
2014-10-15 03:10:25 +02:00
|
|
|
extern void ldlex_inputlist (void);
|
2003-06-28 07:28:54 +02:00
|
|
|
extern void ldlex_mri_script (void);
|
|
|
|
extern void ldlex_version_script (void);
|
|
|
|
extern void ldlex_version_file (void);
|
|
|
|
extern void ldlex_defsym (void);
|
|
|
|
extern void ldlex_expression (void);
|
|
|
|
extern void ldlex_both (void);
|
|
|
|
extern void ldlex_popstate (void);
|
PR ld/13343
* ld.h (parsing_defsym): Delete.
* ldexp.c (exp_intop, exp_bigintop, exp_relop): Set type.filename.
(fold_binary, fold_name, exp_fold_tree_1, exp_get_vma, exp_get_fill,
exp_get_abs_int): Add tree arg for %S in error messages. Don't
fudge lineno.
(exp_binop, exp_unop, exp_nameop, exp_assop, exp_assert): Copy
type.filename from sub-tree.
(exp_trinop): Likewise, and use "cond" rather than "lhs".
* ldexp.h (node_type): Add filename field to struct.
* ldfile.c (ldfile_input_filename): Delete. Remove all refs.
* ldfile.h (ldfile_input_filename): Delete.
* ldgram.y (phdr_type, phdr_qualifiers, yyerror): Add NULL arg for
%S in error messages.
* ldemul.c (syslib_default, hll_default): Likewise.
* ldlang.c (lang_memory_region_lookup, lang_memory_region_alias,
lang_get_regions, lang_new_phdr): Likewise.
(lang_size_sections_1): Pass addr_tree for %S.
* ldlex.h (lex_redirect): Update prototype.
(ldlex_filename): Declare.
* ldlex.l (<EOF>): Don't set ldfile_input_filename.
(lex_redirect): Add fake_filename and count params. Push
fake_filename to file_name_stack and init lineno from count.
(ldlex_filename): New function.
(lex_warn_invalid): Use above.
* ldmain.c (main): Update lex_redirect call.
* ldmisc.c (vfinfo <%S>): Take file name and line number from
etree_type arg, or use current if arg is NULL.
* lexsup.c (parsing_defsym): Delete.
(parse_args <OPTION_DEFSYM>): Update lex_redirect call.
2012-02-17 15:09:57 +01:00
|
|
|
extern const char* ldlex_filename (void);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
/* In lexsup.c. */
|
2003-06-28 07:28:54 +02:00
|
|
|
extern int lex_input (void);
|
|
|
|
extern void lex_unput (int);
|
|
|
|
extern void parse_args (unsigned, char **);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
#endif
|