When --no-define-common is used to build shared library, treat common
symbol as undefined so that common symbols that are referenced from a
shared library to be assigned addresses only in the main program. This
eliminates the unused duplicate space in the shared library, and also
prevents any possible confusion over resolving to the wrong duplicate
when there are many dynamic modules with specialized search paths for
runtime symbol resolution.
--no-define-common is only allowed when building a shared library.
bfd/
PR ld/21903:
* elflink.c (elf_link_add_object_symbols): Treat common symbol
as undefined for --no-define-common.
include/
PR ld/21903:
* bfdlink.h (bfd_link_info): Add inhibit_common_definition.
ld/
PR ld/21903:
* ld.h (command_line): Remove inhibit_common_definition.
* ldgram.y: Replace command_line.inhibit_common_definition with
link_info.inhibit_common_definition.
* ldlang.c (lang_common): Likewise.
* lexsup.c (parse_args): Likewise.
* ldmain.c (main): Only allow --no-define-common with -shared.
* testsuite/ld-elf/pr21903.s: New file.
* testsuite/ld-elf/pr21903a.d: Likewise.
* testsuite/ld-elf/pr21903b.d: Likewise.
* testsuite/ld-elf/pr21903c.d: Likewise.
* testsuite/ld-elf/pr21903d.d: Likewise.
* testsuite/ld-elf/pr21903e.d: Likewise.
* ldgram.y (ldgram_had_keep): Make static.
(ldgram_vers_current_lang): Likewise.
(filename_spec): New rule.
(input_section_spec_no_keep): Use filename_spec.
(wildcard_maybe_exclude): New rule.
(wildcard_spec): Rename to...
(section_name_spec): ...this.
(section_NAME_list): Rename to...
(section_name_list): ...this.
(section_name_spec): Simplifiy and use wildcard_maybe_exclude.
* ldlang.c (placed_commons): Delete.
(lang_add_wild): No longer set placed_commons.
(print_wild_statement): Use full names for SORT specifiers.
* testsuite/ld-scripts/align.exp: Run new tests.
* testsuite/ld-scripts/align3.d: New file.
* testsuite/ld-scripts/align3.t: New file.
* testsuite/ld-scripts/align4.d: New file.
* testsuite/ld-scripts/align4.t: New file.
* testsuite/ld-scripts/align5.d: New file.
* testsuite/ld-scripts/align5.t: New file.
* testsuite/ld-scripts/exclude-file-5.d: New file.
* testsuite/ld-scripts/exclude-file-5.map: New file.
* testsuite/ld-scripts/exclude-file-5.t: New file.
* testsuite/ld-scripts/exclude-file-6.d: New file.
* testsuite/ld-scripts/exclude-file-6.map: New file.
* testsuite/ld-scripts/exclude-file-6.t: New file.
* NEWS: Mention the changes.
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.
Rename file_NAME_list to section_NAME_list in the linker's grammar
file. This rename reflects how the pattern is now being used, and makes
the grammar easier to understand.
There should be no functional change after this commit.
ld/ChangeLog:
* ldgram.y: Rename file_NAME_list to section_NAME_list
throughout.
NOCROSSREFS_TO is similar to the existing NOCROSSREFS command but only
checks one direction of cross referencing.
ld/ChangeLog
* ld.texinfo: Document NOCROSSREFS_TO script command.
* ldlang.h (struct lang_nocrossrefs): Add onlyfirst field.
(lang_add_nocrossref_to): New prototype.
* ldcref.c (check_local_sym_xref): Use onlyfirst to only look for
symbols defined in the first section.
(check_nocrossref): Likewise.
* ldgram.y (NOCROSSREFS_TO): New script command.
* ldlang.c (lang_add_nocrossref): Set onlyfirst to FALSE.
(lang_add_nocrossref_to): New function.
* ldlex.l (NOCROSSREFS_TO): New token.
* NEWS: Mention NOCROSSREFS_TO.
* testsuite/ld-scripts/cross4.t: New file.
* testsuite/ld-scripts/cross5.t: Likewise.
* testsuite/ld-scripts/cross6.t: Likewise.
* testsuite/ld-scripts/cross7.t: Likewise.
* testsuite/ld-scripts/crossref.exp: Run 4 new NOCROSSREFS_TO
tests.
This patch fixes PR 4643 by allowing symbols in the LENGTH and ORIGIN
fields of MEMORY regions. Previously, only constants and constant
expressions are allowed.
For the AVR target, this helps define memory constraints more
accurately (per device), without having to create a ton of device
specific linker scripts.
ld/
PR 4643
* ldexp.c (fold_name): Fold LENGTH only after
lang_first_phase_enum.
* ldgram.y (memory_spec): Don't evaluate ORIGIN and LENGTH
rightaway.
* ldlang.h (struct memory_region_struct): Add origin_exp and
length_exp fields.
* ldlang.c (lang_do_memory_regions): New.
(lang_memory_region_lookup): Initialize origin_exp and
length_exp fields.
(lang_process): Call lang_do_memory_regions.
ld/testsuite/
* ld-scripts/memory.t: Define new symbol tred.
* ld-scripts/memory_sym.t: New.
* ld-scripts/script.exp: Perform MEMORY with symbols test, and
conditionally check values of linker symbols.
* 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.
* ldgram.y: Likewise
* ldlex.l: Likewise
* NEWS: Mention the new feature.
* ld.texinfo: Document the new feature.
* ld-scripts/log2.exp: New: Run the new log2 test.
* ld-scripts/log2.s: Source for the new test.
* ld-scripts/log2.t: Linker script for new test.
* 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.
* ldlang.h (struct lang_input_statement_struct): Rename add_needed
to add_DT_NEEDED_for_dynamic. Rename as_needed to
add_DT_NEEDED_for_regular.
* ldlang.c: Likewise.
* ldlang.h: Likewise.
* ldlang.c: Use the new variable names.
* ldgram.y: Likewise.
* emultempl/elf32.em: Likewise.
* ld.texinfo: Document the renamed option. Also mention its
affect on the resolution of dynamic symbols.
* NEWS: Mention the changed option name.
* ldlang.c: Likewise.
* ldlang.h: Likewise.
* ldlex.l: Likewise.
* NEWS: Mention the new feature.
* ld.texinfo: Document the new feature.
* ld-scripts/regions-alias-1.t: New file.
* ld-scripts/regions-alias-2.t: New file.
* ld-scripts/regions-alias-3.t: New file.
* ld-scripts/regions-alias-4.t: New file.
* ld-scripts/script.exp: Run region alias tests.
nodes.
* ldlang.h (lang_new_vers_pattern): Add literal_p parameter.
* ldgram.y (vers_defns): Allow NAME as well as VERS_IDENTIFIER.
Adjust calls to lang_new_vers_pattern to pass literal_p argument.
* ldlang.c (lang_vers_match): Fix indentation. Do not glob-match
version nodes without a pattern.
(lang_new_vers_pattern): Add literal_p parameter.
(lang_do_version_exports_section): Pass it.
* ld-elfvers/vers.exp: Add vers31.
* ld-elfvers/vers31.c: New file.
* ld-elfvers/vers31.dsym: Likewise.
* ld-elfvers/vers31.map: Likewise.
* ld-elfvers/vers31.ver: Likewise.
extern NAME {}. Handle global, local and extern symbol names.
ld/testsuite/
* ld-elfvers/vers.exp: Add a new test, vers30.
* ld-elfvers/vers30.c: New file.
* ld-elfvers/vers30.map: New file.
* ld-elfvers/vers30.ver: New file.
* ld-elfvers/vers30.dsym: New file.
* ldexp.h: ..here. Add lang_mark_phase_enum.
(node_type): Remove etree_undef and etree_unspec.
(exp_data_seg): Delete.
(struct ldexp_control, expld): New.
(invalid, exp_mark_used_section): Delete.
(exp_fold_tree, exp_get_vma, exp_get_value_int, exp_get_fill,
exp_get_abs_int): Update prototypes.
* ldexp.c (assigning_to_dot): Delete.
(expld): Define.
(make_abs): Operate directly on expld.result. Update all callers.
(new_abs): Likewise. Return void.
(new_rel_from_abs): Rename from new_rel_from_section.
(new_rel, new_rel_from_abs): Operate on expld.result and return void.
Update all callers.
(fold_unary): Operate on expld.result and return void. Remove
"current_section", "allocation_done", "dot", "dotp" and "mark_used"
params. Update all callers.
(fold_binary, fold_trinary, fold_name, exp_fold_tree_1): Likewise.
(fold_unary <ALIGN_K>): Ensure alignment is absolute.
(fold_unary <ABSOLUTE>): Use make_abs.
(fold_unary <DATA_SEGMENT_END>): Evaluate mark_phase as for
allocating_phase.
(fold_binary <DATA_SEGMENT_ALIGN, DATA_SEGMENT_RELRO_END, >): Ditto.
(fold_binary <'%','/'>): Don't error if marking.
(fold_name <SIZEOF_HEADERS>): Don't call bfd_sizeof_headers when
marking.
(fold_name <NAME>): Remove FIXME; -R is handled correctly. Don't
error when marking.
(fold_name <ADDR, LOADADDR, SIZEOF>): Don't set SEC_KEEP.
(exp_fold_tree_1): Don't error when marking.
(exp_fold_tree_1 <etree_rel>): Evaluate in all phases except first.
(exp_fold_tree_1 <etree_assign to dot>): Don't check for NULL
current section, instead check for NULL dotp.
(exp_fold_tree_1 <etree_provide>): Don't evaluate the assignment
source unless the symbol is referenced and undefined.
(exp_fold_tree): Remove "allocation_done" and "dot" params. Save
params to expld.
(exp_fold_tree_no_dot): Remove "current_section", "allocation_done
and "mark_used" params. Save params to expld. Update all callers.
(exp_assop): Do without temp var.
(exp_print_tree <etree_undef>): Delete code.
(exp_get_vma): Remove "allocation_done" param. Correct error return.
(exp_get_fill, exp_get_abs_int): Likewise.
(exp_get_value_int): Remove "allocation_done" param.
(exp_mark_used_section): Delete.
* ldgram.y (fill_exp): Update exp_get_fill call.
(origin_spec, length_spec): Update exp_get_vma call.
* ldlang.c (lang_init): Don't bother clearing lang_statement_iteration.
(lang_mark_used_section_1, lang_mark_used_section): Delete.
(strip_excluded_output_sections): Call one_lang_size_sections_pass in
marking mode. Merge old lang_mark_used_section code. Correct handling
of output sections with excluded input sections and data statements.
Don't drop non-zero sized sections. Don't zap os->bfd_section.
Do set SEC_EXCLUDE when appropriate.
(print_output_section_statement): Update for changed ldexp.c
interface.
(print_assignment, lang_size_sections_1): Likewise.
(lang_do_assignments_1, lang_enter_output_section_statement): Likewise.
(lang_new_phdr, lang_record_phdrs): Likewise.
(lang_size_sections): Likewise.
(insert_pad): Use following statement if it is a pad, rather than
creating a new one.
(lang_size_sections_1 <lang_output_section_statement_enum>): Do
process ignored output section to set vma and lma, but don't
update dot for these sections. Don't error if marking.
(lang_size_sections_1 <lang_assignment_statement_enum>): Don't
update dot for ignored sections.
(lang_size_sections_1 <lang_data_statement_enum>): Don't mark absolute
section with SEC_ALLOC.
(one_lang_size_sections_pass): New function.
(lang_size_sections): Remove first five params. Set expld.phase on
entry and exit. Use one_lang_size_sections_pass.
(lang_do_assignments): Remove all params. Update all callers.
(lang_reset_memory_regions): Clear os->processed for all output
section statements.
* ldlang.h (lang_do_assignments): Update prototype.
(lang_size_sections): Likewise.
(one_lang_size_sections_pass): Declare.
* pe-dll.c (pe_dll_fill_sections, pe_exe_fill_sections): Update
lang_size_sections and lang_do_assignments calls.
* emultempl/elf32.em (layout_sections_again): Likewise.
* emultempl/ppc64elf.em (ppc_before_allocation): Use
one_lang_size_sections_pass.
* ldexp.h (segment_type): New type.
(segments): New variable.
* ldexp.c (segments): New variable.
(exp_print_token): Handle SEGMENT_START.
(fold_binary): Likewise.
* ldgram.y (SEGMENT_START): Declare it as a token.
(exp): Handle SEGMENT_START.
* ldlang.h (lang_address_statement_type): Add segment field.
(lang_section_start): Change prototype.
* ldlang.c (map_input_to_output_sections): Do not process section
assignments if a corresponding SEGMENT_START has already been
seen.
(lang_section_start): Add segment parameter.
* ldlex.l (SEGMENT_START): Add it.
* lexsup.c (seg_segment_start): New function.
(parse_args): Use it for -Tbss, -Tdata, and -Ttext.
* ld.texinfo (SEGMENT_START): Document it.
* emulparams/armsymbian.sh (EMBEDDED): Set it.
* scripttempl/armbpabi.sc: Use SEGMENT_START to control segment
base addresses. Do not map relocations.
* NEWS: Mention SEGMENT_START.