The machinery to do this was there, but not enabled if the terminator
was the only thing in the section.
bfd/
* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Don't exit early
for a section containing just a terminator. Allow multiple
terminators at end of section.
* elflink.c (bfd_elf_discard_info): Iterate over .eh_frame
sections when not adding alignment. Assert on terminator in
the middle of FDEs.
ld/
* testsuite/ld-elf/eh3.d: Update.
* testsuite/ld-elf/eh4.d: Update.
Until all .eh_frame sections have been edited we don't know their
sizes. So it isn't possible to properly decide whether a non-empty
.eh_frame section follows a given section until editing is complete.
bfd/
PR 21441
* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame): Don't add
alignment padding here.
* elflink.c (bfd_elf_discard_info): Add .eh_frame padding here
in a reverse pass over sections.
ld/
PR 21441
* testsuite/ld-x86-64/pr21038a.d: Adjust.
* testsuite/ld-x86-64/pr21038a-now.d: Adjust.
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.
One way to print 64-bit bfd_vma or bfd_size_type values on 32-bit
hosts is to cast the value to long long and use the 'll' modifier in
printf format strings. However, that's awkward because we also
support the Microsoft C library printf that uses 'I64' as a modifier
instead, and having variants of translated strings would not endear us
to the translation project. So, rewrite the 'll' modifier in
_doprint for Microsoft. Even with that capability it's not so nice
for 32-bit code to need casts to long long, so this patch makes 'L' a
modifier for bfd_vma rather than an alias for 'll'.
I've then used the new 'L' modifier to fix selected format strings.
* bfd.c (_doprnt): Rewrite "ll" and "L" modifiers to "I64" for
__MSVCRT__. Support "L" modifier for bfd_vma. Formatting.
* elf.c (setup_group): Use "Lx" to print sh_size.
(_bfd_elf_setup_sections): Remove unnecessary cast and print
unknown section type in hex.
(copy_special_section_fields): Style fix.
(bfd_section_from_shdr): Correct format for sh_link. Use a
common error message for all the variants of unrecognized
section types.
(assign_file_positions_for_load_sections): Use "Lx" for lma
adjust error message.
(assign_file_positions_for_non_load_sections): Formatting.
(rewrite_elf_program_header): Formatting. Use "Lx" for
bfd_vma values in error messages.
* elfcode.h (elf_slurp_reloc_table_from_section): Cast
ELF_R_SYM value to type expected by format.
* elflink.c (elf_link_read_relocs_from_section): Use "Lx"
in error messages.
(elf_link_add_object_symbols): Use "Lu" for symbol sizes.
(elf_link_input_bfd): Use "Lx" for r_info.
(bfd_elf_gc_record_vtinherit): Use "Lx" for offset.
All sections on a --just-syms bfd are discarded from the output, so
attaching linker created sections to such a bfd results in errors.
In other cases, like the .note.GNU-stack check, it's wrong to have a
--just-syms object potentially affect the output.
bfd/
* elflink.c (_bfd_elf_link_create_dynstrtab): Don't make dynobj
a --just-syms bfd.
(_bfd_elf_size_group_sections): Skip --just-syms bfds.
(bfd_elf_size_dynamic_sections): Ignore .note.GNU-stack and
.preinit_array on --just-syms bfds.
(_bfd_elf_gc_mark_extra_sections): Skip --just-syms bfds.
(elf_gc_sweep, bfd_elf_parse_eh_frame_entries): Likewise.
(bfd_elf_gc_sections, bfd_elf_discard_info): Likewise.
ld/
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Skip
--just-syms bfds when looking for a place to attach .note.gnu.build-id
and .eh_frame_hdr sections. Delete dead code.
Currently, linker will define __start_SECNAME and __stop_SECNAME symbols
only for orphaned sections.
However, during garbage collection, ELF linker marks all sections with
references to __start_SECNAME and __stop_SECNAME symbols as used even
when section SECNAME isn't an orphaned section and linker won't define
__start_SECNAME nor __stop_SECNAME. And ELF linker stores the first
input section whose name matches __start_SECNAME or __stop_SECNAME in
u.undef.section for garbage collection. If these symbols are provided
in linker script, u.undef.section is set to the section where they will
defined by linker script, which leads to the incorrect output.
This patch changes linker to always define referenced __start_SECNAME and
__stop_SECNAME if the input section name is the same as the output section
name, which is always true for orphaned sections, and SECNAME is a C
identifier. Also __start_SECNAME and __stop_SECNAME symbols are marked
as hidden by ELF linker so that __start_SECNAME and __stop_SECNAME symbols
for section SECNAME in different modules are unique. For garbage
collection, ELF linker stores the first matched input section in the
unused vtable field.
bfd/
PR ld/20022
PR ld/21557
PR ld/21562
PR ld/21571
* elf-bfd.h (elf_link_hash_entry): Add start_stop. Change the
vtable field to a union.
(_bfd_elf_is_start_stop): Removed.
* elf32-i386.c (elf_i386_convert_load_reloc): Also check for
__start_SECNAME and __stop_SECNAME symbols.
* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Likewise.
* elflink.c (_bfd_elf_is_start_stop): Removed.
(_bfd_elf_gc_mark_rsec): Check start_stop instead of calling
_bfd_elf_is_start_stop.
(elf_gc_propagate_vtable_entries_used): Skip __start_SECNAME and
__stop_SECNAME symbols. Updated.
(elf_gc_smash_unused_vtentry_relocs): Likewise.
(bfd_elf_gc_record_vtinherit): Likewise.
(bfd_elf_gc_record_vtentry): Likewise.
ld/
PR ld/20022
PR ld/21557
PR ld/21562
PR ld/21571
* ld.texinfo: Update __start_SECNAME/__stop_SECNAME symbols.
* ldlang.c (lang_insert_orphan): Move handling of __start_SECNAME
and __stop_SECNAME symbols to ...
(lang_set_startof): Here. Also define __start_SECNAME and
__stop_SECNAME for -Ur.
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Mark
referenced __start_SECNAME and __stop_SECNAME symbols as hidden
and set start_stop for garbage collection.
* testsuite/ld-elf/pr21562a.d: New file.
* testsuite/ld-elf/pr21562a.s: Likewise.
* testsuite/ld-elf/pr21562a.t: Likewise.
* testsuite/ld-elf/pr21562b.d: Likewise.
* testsuite/ld-elf/pr21562b.s: Likewise.
* testsuite/ld-elf/pr21562b.t: Likewise.
* testsuite/ld-elf/pr21562c.d: Likewise.
* testsuite/ld-elf/pr21562c.t: Likewise.
* testsuite/ld-elf/pr21562d.d: Likewise.
* testsuite/ld-elf/pr21562d.t: Likewise.
* testsuite/ld-elf/pr21562e.d: Likewise.
* testsuite/ld-elf/pr21562f.d: Likewise.
* testsuite/ld-elf/pr21562g.d: Likewise.
* testsuite/ld-elf/pr21562h.d: Likewise.
* testsuite/ld-elf/pr21562i.d: Likewise.
* testsuite/ld-elf/pr21562j.d: Likewise.
* testsuite/ld-elf/pr21562k.d: Likewise.
* testsuite/ld-elf/pr21562l.d: Likewise.
* testsuite/ld-elf/pr21562m.d: Likewise.
* testsuite/ld-elf/pr21562n.d: Likewise.
* testsuite/ld-gc/pr20022.d: Likewise.
* testsuite/ld-gc/pr20022a.s: Likewise.
* testsuite/ld-gc/pr20022b.s: Likewise.
* testsuite/ld-gc/gc.exp: Run PR ld/20022 tests.
* testsuite/ld-gc/pr19161.d: Also accept local __start_SECNAME
symbol.
* testsuite/ld-gc/start.d: Likewise.
* testsuite/ld-x86-64/lea1a.d: Updated.
* testsuite/ld-x86-64/lea1b.d: Updated.
* testsuite/ld-x86-64/lea1d.d: Updated.
* testsuite/ld-x86-64/lea1e.d: Likewise.
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.
Correct a commit e5713223cb ("MIPS/BFD: For n64 hold the number of
internal relocs in `->reloc_count'") regression and change internal
relocation handling in the generic ELF BFD linker code such that, except
in the presence of R_SPARC_OLO10 relocations, a section's `reloc_count'
holds the number of internal rather than external relocations, making
the handling more consistent between GAS, which sets `->reloc_count'
with a call to `bfd_set_reloc', and LD, which sets `->reloc_count' as it
reads input sections.
The handling of dynamic relocations remains unchanged and they continue
holding the number of external relocations in `->reloc_count'; they are
also not converted to the internal form except in `elf_link_sort_relocs'
(which does not handle the general, i.e. non-n64-MIPS case of composed
relocations correctly as per the ELF gABI, though it does not seem to
matter for the targets we currently support).
The n64 MIPS backend is the only one with `int_rels_per_ext_rel' set to
non-one, and consequently the change is trivial for all the remaining
backends and targets.
bfd/
* elf-bfd.h (RELOC_AGAINST_DISCARDED_SECTION): Subtract `count'
from `reloc_count' rather than decrementing it.
* elf.c (bfd_section_from_shdr): Multiply the adjustment to
`reloc_count' by `int_rels_per_ext_rel'.
* elf32-score.c (score_elf_final_link_relocate): Do not multiply
`reloc_count' by `int_rels_per_ext_rel' for last relocation
entry determination.
(s3_bfd_score_elf_check_relocs): Likewise.
* elf32-score7.c (score_elf_final_link_relocate): Likewise.
(s7_bfd_score_elf_relocate_section): Likewise.
(s7_bfd_score_elf_check_relocs): Likewise.
* elf64-mips.c (mips_elf64_get_reloc_upper_bound): Remove
prototype and function.
(mips_elf64_slurp_one_reloc_table): Do not update `reloc_count'.
(mips_elf64_slurp_reloc_table): Assert that `reloc_count' is
triple rather than once the sum of REL and RELA relocation entry
counts.
(bfd_elf64_get_reloc_upper_bound): Remove macro.
* elflink.c (_bfd_elf_link_read_relocs): Do not multiply
`reloc_count' by `int_rels_per_ext_rel' for internal relocation
storage allocation size determination.
(elf_link_input_bfd): Multiply `.ctors' and `.dtors' section's
size by `int_rels_per_ext_rel'. Do not multiply `reloc_count'
by `int_rels_per_ext_rel' for last relocation entry
determination.
(bfd_elf_final_link): Do not multiply `reloc_count' by
`int_rels_per_ext_rel' for internal relocation storage
allocation size determination.
(init_reloc_cookie_rels): Do not multiply `reloc_count' by
`int_rels_per_ext_rel' for last relocation entry determination.
(elf_gc_smash_unused_vtentry_relocs): Likewise.
* elfxx-mips.c (_bfd_mips_elf_check_relocs): Likewise.
(_bfd_mips_elf_relocate_section): Likewise.
The pr20882 testcase fails on a number of targets that add attribute
or note sections to object files, and the default linker script says
those sections should be kept. This patch changes --gc-sections to
drop debug and special sections like .comment when no SEC_ALLOC
section in an object file is kept. The assumption is that debug
sections are describing code and data that will become part of the
final image in memory.
* elflink.c (_bfd_elf_gc_mark_extra_sections): Don't keep
debug and special sections when no non-note alloc sections in an
object are kept.
If a debug section is referenced by a kept debug section, it should
also be kept.
Some targets, like mips, keep input files when there are some special
sections, like .gnu.attributes, even if input file is unused otherwise.
In this case, all debug sections are kept. The new test will fail on
such targets. We can either fix those targets or XFAIL the test.
bfd/
PR ld/20882
* elflink.c (elf_gc_mark_debug_section): New function.
(_bfd_elf_gc_mark_extra_sections): Mark any debug sections
referenced by kept debug sections.
ld/
PR ld/20882
* testsuite/ld-gc/gc.exp: Run pr20882.
* testsuite/ld-gc/pr20882.d: New file.
* testsuite/ld-gc/pr20882a.s: Likewise.
* testsuite/ld-gc/pr20882b.s: Likewise.
* testsuite/ld-gc/pr20882c.s: Likewise.
dynamic_ref_after_ir_def is a little odd compared to other symbol
flags in that as the name suggests, it is set only for certain
references after a definition. It turns out that setting a flag for
any non-ir reference from a dynamic object can be used to solve the
problem for which this flag was invented, which I think is a cleaner.
This patch does that, and sets non_ir_ref only for regular object
references.
include/
* bfdlink.h (struct bfd_link_hash_entry): Update non_ir_ref
comment. Rename dynamic_ref_after_ir_def to non_ir_ref_dynamic.
ld/
* plugin.c (is_visible_from_outside): Use non_ir_ref_dynamic.
(plugin_notice): Set non_ir_ref for references from regular
objects, non_ir_ref_dynamic for references from dynamic objects.
bfd/
* elf64-ppc.c (add_symbol_adjust): Transfer non_ir_ref_dynamic.
* elflink.c (elf_link_add_object_symbols): Update to use
non_ir_ref_dynamic.
(elf_link_input_bfd): Test non_ir_ref_dynamic in addition to
non_ir_ref.
* linker.c (_bfd_generic_link_add_one_symbol): Likewise.
For ELF targets --out-implib currently generates an executable file
(e_type is ET_EXEC) despite the file being expected to be linked against
some other object file to make an executable later. It seems therefore
more sensible to make the import library a relocatable object file
(e_type set to ET_REL).
Incidentally, as dicted by requirement 8 of
"ARM v8-M Security Extensions: Requirements on Development Tools"
(document ARM-ECM-0359818) version 1.0, import libraries generated when
using --cmse-implib *must* be relocatable object file so this commit
also adds an assert there in case the type of ELF import library is
changed again in the future.
2017-05-08 Thomas Preud'homme <thomas.preudhomme@arm.com>
bfd/
* elflink.c (elf_output_implib): Remove executable flag from import
library bfd.
* elf32-arm.c (elf32_arm_filter_implib_symbols): Assert that the import
library is a relocatable object file.
ld/
* testsuite/ld-arm/arm-elf.exp
(Secure gateway import library generation): Check e_type field
of import library and executable produced.
* testsuite/ld-arm/cmse-implib.type: Expectations for e_type field.
The commit to "Always descend into output section statements in
lang_do_assignments" meant that linker script symbols were not
bfd_link_hash_new when ld called bfd_elf_record_link_assignment.
This patch corrects that problem by testing h->non_elf instead.
PR 21384
* elflink.c (bfd_elf_link_mark_dynamic_symbol): Test h->non_elf
rather than h->root.type == bfd_link_hash_new.
(bfd_elf_record_link_assignment): Similarly, call
bfd_elf_link_mark_dynamic_symbol when h->non_elf.
Experimental support for moving symbols defined in .eh_frame as their
CIEs/FDEs are edited or merged.
* elf-bfd.h (struct eh_cie_fde): Add aug_str_len and aug_data_len.
(_bfd_elf_adjust_eh_frame_global_symbol): Declare.
* elf-eh-frame.c (_bfd_elf_parse_eh_frame): Set aug_str_len and
aug_data_len.
(offset_adjust): New function.
(_bfd_elf_adjust_eh_frame_global_symbol): Likewise.
(adjust_eh_frame_local_symbols): Likewise.
(_bfd_elf_discard_section_eh_frame): Call adjust_eh_frame_local_symbols
after changing anything. Return true if anything changed.
* elflink.c (bfd_elf_discard_info): If .eh_frame changed, call
_bfd_elf_adjust_eh_frame_global_symbol for globals.
This is really just cosmetic, but it does protect a little from
accidentally reading a stale value.
* elflink.c (_bfd_elf_link_hash_hide_symbol): Clear dynstr_index
when force_local.
Complement commit e17b0c351f ("MIPS/BFD: Respect the ELF gABI dynamic
symbol table sort requirement") and correct an inconsistency in dynamic
symbol accounting data causing an assertion failure in the MIPS backend:
ld: BFD (GNU Binutils) 2.28.51.20170330 assertion fail
../../binutils-gdb/bfd/elfxx-mips.c:3860
in the course of making a GOT entry in a static binary to satisfy a GOT
relocation present in input, due to the local dynamic symbol count not
having been established.
To do so let backends request `_bfd_elf_link_renumber_dynsyms' to be
always called, rather than where a dynamic binary is linked only, and
then make this request in the MIPS backend.
bfd/
PR ld/21334
* elf-bfd.h (elf_backend_data): Add `always_renumber_dynsyms'
member.
* elfxx-target.h [!elf_backend_always_renumber_dynsyms]
(elf_backend_always_renumber_dynsyms): Define.
(elfNN_bed): Initialize `always_renumber_dynsyms' member.
* elfxx-mips.h (elf_backend_always_renumber_dynsyms): Define.
* elflink.c (bfd_elf_size_dynamic_sections): Also call
`_bfd_elf_link_renumber_dynsyms' if the backend has requested
it.
(bfd_elf_size_dynsym_hash_dynstr): Likewise.
ld/
PR ld/21334
* testsuite/ld-mips-elf/pr21334.dd: New test.
* testsuite/ld-mips-elf/pr21334.gd: New test.
* testsuite/ld-mips-elf/pr21334.ld: New test linker script.
* testsuite/ld-mips-elf/pr21334.s: New test source.
* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
Consistently call `_bfd_elf_link_renumber_dynsyms' only if linking a
dynamic binary, complementing code in `bfd_elf_size_dynsym_hash_dynstr'
and commit ccabcbe51e ("New attempt at fixing MIPS --gc-sections et
al."), <https://sourceware.org/ml/binutils/2005-08/msg00258.html>.
bfd/
* elflink.c (bfd_elf_size_dynamic_sections): Only call
`_bfd_elf_link_renumber_dynsyms' after section GC if dynamic
sections have been created.
When -static -E/--dynamic-list are passed to linker, linker may create
executable with dynamic sections which aren't supported by run-time.
We require --no-dynamic-linker together with -static -E/--dynamic-list
before adding dynamic symbol table to static executable.
bfd/
PR ld/19617
PR ld/21086
* elflink.c (elf_link_add_object_symbols): Require
--no-dynamic-linker with -E/--dynamic-list when creating
dynamic sections.
ld/
PR ld/19617
PR ld/21086
* testsuite/ld-elf/pr19617a.d: Pass --no-dynamic-linker to ld.
* testsuite/ld-elf/pr19617b.d: Likewise.
* testsuite/ld-elf/pr19617c.d: Likewise.
*testsuite/ld-i386/pr19636-4d.d: Likewise.
* testsuite/ld-elf/readelf.exp: Pass --no-dynamic-linker to ld
with --export-dynamic.
* testsuite/ld-elf/shared.exp: Pass --no-dynamic-linker to ld
with -E.
Do not require forced local (STB_LOCAL) symbols to have a definition in
a regular file to be considered to resolve local to the current module,
matching `elf_link_renumber_local_hash_table_dynsyms'. In the absence
of a regular definition any reference to a STB_LOCAL symbol will have to
be garbage collected along with the undefined symbol itself, or the link
will eventually fail. Either way the symbol concerned is not going to
be external.
bfd/
* elflink.c (_bfd_elf_symbol_refs_local_p): Always return TRUE
if forced local.
We need to make an IR symbol visible if it is defined in an IR object
and referenced in a dynamic object. When --as-needed is used, since
linker removes the IR symbol reference of the dynamic object if the
dynamic object isn't needed in the first pass, the IR definition isn't
visible to the dynamic object even if the dynamic object becomes needed
in the second pass. Add dynamic_ref_after_ir_def to bfd_link_hash_entry
to track IR symbol which is defined in an IR object and later referenced
in a dynamic object. dynamic_ref_after_ir_def is preserved when restoring
the symbol table for unneeded dynamic object.
bfd/
PR ld/21382
* elflink.c (elf_link_add_object_symbols): Preserve
dynamic_ref_after_ir_def when restoring the symbol table for
unneeded dynamic object.
include/
PR ld/21382
* bfdlink.h (bfd_link_hash_entry): Add dynamic_ref_after_ir_def.
ld/
PR ld/21382
* plugin.c (is_visible_from_outside): Symbol may be visible
from outside if dynamic_ref_after_ir_def is set.
(plugin_notice): Set dynamic_ref_after_ir_def if the symbol is
defined in an IR object and referenced in a dynamic object.
* testsuite/ld-plugin/lto.exp: Run PR ld/21382 tests.
* testsuite/ld-plugin/pr21382a.c: New file.
* testsuite/ld-plugin/pr21382b.c: Likewise.
-z nodynamic-undefined-weak is only implemented for x86. (The sparc
backend has some support code but doesn't enable the option by
including ld/emulparams/dynamic_undefined_weak.sh, and since the
support looks like it may be broken I haven't enabled it.) This patch
adds the complementary -z dynamic-undefined-weak, extends both options
to affect building of shared libraries as well as executables, and
adds support for the option on powerpc.
include/
* bfdlink.h (struct bfd_link_info <dynamic_undefined_weak>):
Revise comment.
bfd/
* elflink.c (_bfd_elf_adjust_dynamic_symbol): Hide undefweak
or make dynamic for info->dynamic_undefined_weak 0 and 1.
* elf32-ppc.c:Formatting.
(ensure_undefweak_dynamic): Don't make dynamic when
info->dynamic_undefined_weak is zero.
(allocate_dynrelocs): Discard undefweak dyn_relocs for
info->dynamic_undefined_weak. Discard undef dyn_relocs when
not default visibility. Discard undef and undefweak
dyn_relocs earlier.
(ppc_elf_relocate_section): Adjust to suit.
* elf64-ppc.c: Formatting.
(ensure_undefweak_dynamic): Don't make dynamic when
info->dynamic_undefined_weak is zero.
(allocate_dynrelocs): Discard undefweak dyn_relocs for
info->dynamic_undefined_weak. Discard them earlier.
ld/
* ld.texinfo (dynamic-undefined-weak): Document.
(nodynamic-undefined-weak): Document that this option now can
be used with shared libs.
* emulparams/dynamic_undefined_weak.sh: Support -z
dynamic-undefined-weak.
* emulparams/elf32ppccommon.sh: Include dynamic_undefined_weak.sh.
* testsuite/ld-undefined/weak-undef.exp (undef_weak_so),
(undef_weak_exe): New. Use them. Add -z dynamic-undefined-weak
and -z nodynamic-undefined-weak tests.
* Makefile.am: Update powerpc dependencies.
* Makefile.in: Regenerate.
commit 902e9fc76a
Author: Maciej W. Rozycki <macro@imgtec.com>
Date: Tue Feb 21 01:46:42 2017 +0000
PR ld/20828: Move symbol version processing ahead of GC symbol sweep
breaks version definition with --version-script --soname. This patch
fixes it by getting soname index before generating the version definition
section.
bfd/
PR ld/21389
* elflink.c (bfd_elf_size_dynamic_sections): Get soname index
before generating the version definition section.
ld/
PR ld/21389
* testsuite/ld-elf/pr21389.map: New file.
* testsuite/ld-elf/pr21389.s: Likewise.
* testsuite/ld-elf/pr21389a.d: Likewise.
* testsuite/ld-elf/pr21389b.d: Likewise.
* testsuite/ld-elf/pr21389c.d: Likewise.
We already handle the case of an object file first defining a symbol
that a later shared library also defines where the symbol types are
incompatible. This patch handles the reverse, when a later object
file defines an incompatible symbol defined by an earlier shared
library.
bfd/
* elflink.c (_bfd_elf_merge_symbol): Undo dynamic linking
state when a regular object file defines a symbol with
incompatible type to that defined by an earlier shared lib.
ld/
* testsuite/ld-elf/indirect5a.c,
* testsuite/ld-elf/indirect5b.c,
* testsuite/ld-elf/indirect5.map,
* testsuite/ld-elf/indirect5.out: New test.
* testsuite/ld-elf/indirect6a.c: Likewise.
* testsuite/ld-elf/indirect.exp (check_dynamic_syms): New proc.
Run new tests and check dynsyms.
Not a comprehensive change, just some split out from fixes made for
the %A and %B changes.
* coffcode.h: Wrap some overly long _bfd_error_handler args.
* elf.c: Likewise.
* elf32-arm.c: Likewise.
* elf32-i386.c: Likewise.
* elf32-mep.c: Likewise.
* elf64-ia64-vms.c: Likewise.
* elf64-x86-64.c: Likewise.
* elflink.c: Likewise.
* elfnn-ia64.c: Likewise.
* elfxx-mips.c: Likewise.
This steals _doprnt from libiberty, extended to handle %A and %B.
Which lets us do away with the current horrible %A and %B handling
that requires all %A and %B arguments to be passed first, rather than
in the natural order.
* bfd.c (PRINT_TYPE): Define.
(_doprnt): New function.
(error_handler_internal): Use _doprnt.
* coff-arm.c: Put %A and %B arguments to _bfd_error_handler
calls in their natural order, throughout file.
* coff-mcore.c: Likewise.
* coff-ppc.c: Likewise.
* coff-tic80.c: Likewise.
* cofflink.c: Likewise.
* elf-s390-common.c: Likewise.
* elf.c: Likewise.
* elf32-arm.c: Likewise.
* elf32-i386.c: Likewise.
* elf32-m32r.c: Likewise.
* elf32-msp430.c: Likewise.
* elf32-spu.c: Likewise.
* elf64-ia64-vms.c: Likewise.
* elf64-sparc.c: Likewise.
* elf64-x86-64.c: Likewise.
* elflink.c: Likewise.
* elfnn-aarch64.c: Likewise.
* elfnn-ia64.c: Likewise.
* elfxx-mips.c: Likewise.
Since common symbols that are turned into definitions don't have the
DEF_REGULAR flag set, we need to check ELF_COMMON_DEF_P for common
symbols.
bfd/
PR ld/19579
PR ld/21306
* elf32-s390.c (elf_s390_finish_dynamic_symbol): Check
ELF_COMMON_DEF_P for common symbols.
* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
* elflink.c (_bfd_elf_merge_symbol): Revert commits
202ac193bb and
07492f668d.
ld/
PR ld/19579
PR ld/21306
* testsuite/ld-elf/pr19579a.c (main): Updated.
PR binutils/21342
* elflink.c (_bfd_elf_define_linkage_sym): Prevent null pointer
dereference.
(bfd_elf_final_link): Only initialize the extended symbol index
section if there are extended symbol tables to list.
I'd made this dynamic section read-only so a flag test distinguished
it from .dynbss, but like any other .data.rel.ro section it really
should be marked read-write. (It is read-only after relocation, not
before.) When using the standard linker scripts this usually doesn't
matter since the output section is among other read-write sections and
not page aligned. However, it might matter in the extraordinary case
of the dynamic section being the only .data.rel.ro section with the
output section just happening to be page aligned and a multiple of a
page in size. In that case the output section would be read-only, and
live it its own read-only PT_LOAD segment, which is incorrect.
* elflink.c (_bfd_elf_create_dynamic_sections): Don't make
dynamic .data.rel.ro read-only.
* elf32-arm.c (elf32_arm_finish_dynamic_symbol): Compare section
rather than section flags when deciding where copy reloc goes.
* elf32-cris.c (elf_cris_finish_dynamic_symbol): Likewise.
* elf32-hppa.c (elf32_hppa_finish_dynamic_symbol): Likewise.
* elf32-i386.c (elf_i386_finish_dynamic_symbol): Likewise.
* elf32-metag.c (elf_metag_finish_dynamic_symbol): Likewise.
* elf32-microblaze.c (microblaze_elf_finish_dynamic_symbol): Likewise.
* elf32-nios2.c (nios2_elf32_finish_dynamic_symbol): Likewise.
* elf32-or1k.c (or1k_elf_finish_dynamic_symbol): Likewise.
* elf32-ppc.c (ppc_elf_finish_dynamic_symbol): Likewise.
* elf32-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
* elf32-tic6x.c (elf32_tic6x_finish_dynamic_symbol): Likewise.
* elf32-tilepro.c (tilepro_elf_finish_dynamic_symbol): Likewise.
* elf64-ppc.c (ppc64_elf_finish_dynamic_symbol): Likewise.
* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_symbol): Likewise.
* elfnn-riscv.c (riscv_elf_finish_dynamic_symbol): Likewise.
* elfxx-mips.c (_bfd_mips_vxworks_finish_dynamic_symbol): Likewise.
* elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): Likewise.
* elfxx-tilegx.c (tilegx_elf_finish_dynamic_symbol): Likewise.
Complement commit b531344c34 ("PR ld/20828: Reorder the symbol sweep
stage of section GC") and commit 81ff47b3a5 ("PR ld/20828: Fix linker
script symbols wrongly forced local with section GC") and move symbol
version processing ahead of the symbol sweep stage of section GC, all in
`bfd_elf_size_dynamic_sections', so that version symbols created stay in
the global scope and are not output as local symbols to the dynamic
symbol table in the presence of corresponding symbol definitions pulled
from a DSO involved in a link.
Consolidate the whole of symbol version processing into a single block
from all parts scattered across the function and rearranging the local
variables used as necessary, however leaving the setting of dynamic
entries associated with the DT_VERDEF, DT_VERDEFNUM, DT_VERNEED and
DT_VERNEEDNUM tags and the SEC_EXCLUDE flag for unused `.gnu.version'
section in the original places.
With the rearrangement of code blocks `Elf_Internal_Verneed *t' would
shadow the previous definition of `struct bfd_elf_version_tree *t', so
rename the former variable to `vn'.
bfd/
PR ld/20828
* elflink.c (bfd_elf_size_dynamic_sections): Move symbol version
processing ahead of the call to `elf_gc_sweep_symbol'.
ld/
PR ld/20828
* testsuite/ld-elf/pr20828-d.sd: New test.
* testsuite/ld-elf/pr20828-e.sd: New test.
* testsuite/ld-elf/pr20828-v.od: New test.
* testsuite/ld-elf/pr20828-v.ver: New test version script.
* testsuite/ld-elf/pr20828-v.ld: New test linker script.
* testsuite/ld-elf/pr20828.ld: Add `.gnu.version' and
`.gnu.version_d'.
* testsuite/ld-elf/shared.exp: Run the new tests.
Complement commit 81ff47b3a5 ("PR ld/20828: Fix linker script symbols
wrongly forced local with section GC") and move the symbol sweep stage
of section GC from `elf_gc_sweep' to `bfd_elf_size_dynamic_sections',
avoiding the need to clear the `forced_local' marker, problematic for
targets that have special processing in their `elf_backend_hide_symbol'
handler. Set `mark' instead in `bfd_elf_record_link_assignment' and,
matching changes from commit 3bd43ebcb6 ("ld --gc-sections fail with
__tls_get_addr_opt"), also in PowerPC `__tls_get_addr_opt' handling
code, removing a:
FAIL: PR ld/20828 dynamic symbols with section GC (version script)
test suite failure with the `score-elf' target.
The rationale is it is enough if symbols are swept at the beginning of
`bfd_elf_size_dynamic_sections' as it is only in this function that the
size of the GOT, the dynamic symbol table and other dynamic sections is
determined, which will depend on the number of symbols making it to the
dynamic symbol table. It is also appropriate to do the sweep at this
point as it is already after any changes have been made to symbols with
`bfd_elf_record_link_assignment', and not possible any earlier as calls
to that function are only made just beforehand -- barring audit entry
processing -- via `gld${EMULATION_NAME}_find_statement_assignment'
invoked from `gld${EMULATION_NAME}_before_allocation' which is the ELF
handler for `ldemul_before_allocation'.
bfd/
PR ld/20828
* elflink.c (bfd_elf_record_link_assignment): Revert last
change and don't ever clear `forced_local'. Set `mark'
unconditionally.
(elf_gc_sweep_symbol_info, elf_gc_sweep_symbol): Reorder within
file.
(elf_gc_sweep): Move the call to `elf_gc_sweep_symbol'...
(bfd_elf_size_dynamic_sections): ... here.
* elf32-ppc.c (ppc_elf_tls_setup): Don't clear `forced_local'
and set `mark' instead in `__tls_get_addr_opt' processing.
* elf64-ppc.c (ppc64_elf_tls_setup): Likewise.
Fix a generic ELF linker regression introduced with a chain of changes
made to unused input section garbage collection:
- commit 1a766c6843 ("Also hide symbols without PLT nor GOT
references."),
<https://sourceware.org/ml/binutils/2011-09/msg00076.html>,
- commit 1d5316ab67 ("PR ld/13177: garbage collector retains zombie
references to external libraries"),
<https://sourceware.org/ml/binutils/2011-10/msg00161.html>,
- commit 6673f753c0 ("Fix PR 12772, garbage collection of dynamic
syms"), <https://sourceware.org/ml/binutils/2011-12/msg00077.html>,
causing the garbage collection of unused symbols present in a DSO
involved in a link to make identically named symbols ordinarily defined
(i.e. not hidden or PROVIDEd) by a linker script local, even though the
latter symbols are supposed to be global as if no DSO defined them as
well.
This is because linker script assignments are processed very late as
`lang_process' proceeds, down in the call to `ldemul_before_allocation',
which is made after the call to `lang_gc_sections' to do input section
garbage collecting. Consequently if unused, then any such DSO-defined
symbol has already been garbage-collected and internally marked local.
It would ordinarily be removed from dynamic symbol table output, however
a linker script assignment correctly replaces its original definition
with the new one and enters it into the dynamic symbol table produced as
it is supposed to be exported. The original local marking is however
retained making the symbol local in the dynamic symbol table and
therefore not available externally. This also causes a sorting problem
with the MIPS target, which does not expect non-section local dynamic
symbols to be output and produces an invalid binary.
Fix the problem then, by removing the `forced_local' marking for the
offending case and add suitable test cases. First to verify that unused
symbols ordinarily defined with linker script assignments remain
exported in the context of input section garbage collection whether or
not a DSO defining identically named symbols is present in the link.
Second that a linker version script still correctly retains or removes
such symbols as requested.
bfd/
PR ld/20828
* elflink.c (bfd_elf_record_link_assignment): Clear any
`forced_local' marking for DSO symbols that are not being
provided.
ld/
PR ld/20828
* testsuite/ld-elf/pr20828-1.sd: New test.
* testsuite/ld-elf/pr20828-2a.sd: New test.
* testsuite/ld-elf/pr20828-2b.sd: New test.
* testsuite/ld-elf/pr20828.ld: New test linker script.
* testsuite/ld-elf/pr20828.ver: New test version script.
* testsuite/ld-elf/pr20828.s: New test source.
* testsuite/ld-elf/shared.exp: Run the new test.
A while ago HJ fixed PR ld/18720 with commit 6e33951ed, which, among
other things, modified _bfd_elf_link_hash_copy_indirect to not copy
ref_dynamic, ref_regular, ref_regular_nonweak, non_got_ref, needs_plt
and pointer_equality_needed when setting up an indirect non-versioned
symbol pointing to a non-default versioned symbol. I didn't notice at
the time, but the pr18720 testcase fails on hppa-linux with
"internal error, aborting at binutils-gdb-2.28/bfd/elf32-hppa.c:3933
in elf32_hppa_relocate_section".
Now hppa-linux creates entries in the plt even for local functions, if
they are referenced using plabel (function pointer) relocations. So
needs_plt is set for foo when processing pr18720a.o. When the aliases
in pr28720b.o are processed, we get an indirection from foo to
foo@FOO, but don't copy needs_plt. Since foo@FOO is the "real" symbol
that is used after that point, no plt entry is made for foo and we
bomb when relocating the plabel.
As shown by the hppa-linux scenario, needs_plt should be copied even
for non-default versioned symbols. I believe all of the others ought
to be copied too, with the exception of ref_dynamic. Not copying
ref_dynamic is right because if a shared lib references "foo" it
should not be satisfied by any non-default version "foo@FOO".
* elflink.c (_bfd_elf_link_hash_copy_indirect): Only omit
copying one flag, ref_dynamic, when versioned_hidden.
* elf64-ppc.c (ppc64_elf_copy_indirect_symbol): Likewise.
* elf32-hppa.c (elf32_hppa_copy_indirect_symbol): Use same
logic for copying weakdef flags. Copy plabel flag and merge
tls_type.
* elf32-i386.c (elf_i386_copy_indirect_symbol): Use same logic
for copying weakdef flags.
* elf32-ppc.c (ppc_elf_copy_indirect_symbol): Likewise.
* elf32-s390.c (elf_s390_copy_indirect_symbol): Likewise.
* elf32-sh.c (sh_elf_copy_indirect_symbol): Likewise.
* elf64-s390.c (elf_s390_copy_indirect_symbol): Likewise.
* elfnn-ia64.c (elfNN_ia64_hash_copy_indirect): Likewise.
* elf64-x86-64.c (elf_x86_64_copy_indirect_symbol): Likewise.
Simplify.
PR ld/20995
bfd/
* elflink.c (elf_link_add_object_symbols): Mark relro sections
in dynamic objects SEC_READONLY.
ld/
* testsuite/ld-elf/pr20995c.s: New test file.
* testsuite/ld-elf/pr20995-2so.r: Likewise.
* testsuite/ld-elf/elf.exp: Run it.
Variables defined in shared libraries are copied into an executable's
.bss section when code in the executable is non-PIC and thus would
require dynamic text relocations to access the variable directly in
the shared library. Recent x86 toolchains also copy variables into
the executable to gain a small speed improvement.
The problem is that if the variable was originally read-only, the copy
in .bss is writable, potentially opening a security hole. This patch
cures that problem by putting the copy in a section that becomes
read-only after ld.so relocation, provided -z relro is in force.
The patch also fixes a microblaze linker segfault on attempting to
use dynamic bss variables.
bfd/
PR ld/20995
* elf-bfd.h (struct elf_link_hash_table): Add sdynrelro and
sreldynrelro.
(struct elf_backend_data): Add want_dynrelro.
* elfxx-target.h (elf_backend_want_dynrelro): Define.
(elfNN_bed): Update initializer.
* elflink.c (_bfd_elf_create_dynamic_sections): Create
sdynrelro and sreldynrelro sections.
* elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Place variables
copied into the executable from read-only sections into sdynrelro.
(elf32_arm_size_dynamic_sections): Handle sdynrelro.
(elf32_arm_finish_dynamic_symbol): Select sreldynrelro for
dynamic relocs in sdynrelro.
(elf_backend_want_dynrelro): Define.
* elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol)
(elf32_hppa_size_dynamic_sections, elf32_hppa_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elf32-i386.c (elf_i386_adjust_dynamic_symbol)
(elf_i386_size_dynamic_sections, elf_i386_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elf32-metag.c (elf_metag_adjust_dynamic_symbol)
(elf_metag_size_dynamic_sections, elf_metag_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elf32-microblaze.c (microblaze_elf_adjust_dynamic_symbol)
(microblaze_elf_size_dynamic_sections)
(microblaze_elf_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elf32-nios2.c (nios2_elf32_finish_dynamic_symbol)
(nios2_elf32_adjust_dynamic_symbol)
(nios2_elf32_size_dynamic_sections)
(elf_backend_want_dynrelro): As above.
* elf32-or1k.c (or1k_elf_finish_dynamic_symbol)
(or1k_elf_adjust_dynamic_symbol, or1k_elf_size_dynamic_sections)
(elf_backend_want_dynrelro): As above.
* elf32-ppc.c (ppc_elf_adjust_dynamic_symbol)
(ppc_elf_size_dynamic_sections, ppc_elf_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elf32-s390.c (elf_s390_adjust_dynamic_symbol)
(elf_s390_size_dynamic_sections, elf_s390_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elf32-tic6x.c (elf32_tic6x_adjust_dynamic_symbol)
(elf32_tic6x_size_dynamic_sections)
(elf32_tic6x_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elf32-tilepro.c (tilepro_elf_adjust_dynamic_symbol)
(tilepro_elf_size_dynamic_sections)
(tilepro_elf_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol)
(ppc64_elf_size_dynamic_sections, ppc64_elf_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elf64-s390.c (elf_s390_adjust_dynamic_symbol)
(elf_s390_size_dynamic_sections, elf_s390_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol)
(elf_x86_64_size_dynamic_sections)
(elf_x86_64_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol)
(elfNN_aarch64_size_dynamic_sections)
(elfNN_aarch64_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elfnn-riscv.c (riscv_elf_adjust_dynamic_symbol)
(riscv_elf_size_dynamic_sections, riscv_elf_finish_dynamic_symbol)
(elf_backend_want_dynrelro): As above.
* elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol)
(_bfd_mips_elf_size_dynamic_sections)
(_bfd_mips_vxworks_finish_dynamic_symbol): As above.
* elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol)
(_bfd_sparc_elf_size_dynamic_sections)
(_bfd_sparc_elf_finish_dynamic_symbol): As above.
* elfxx-tilegx.c (tilegx_elf_adjust_dynamic_symbol)
(tilegx_elf_size_dynamic_sections)
(tilegx_elf_finish_dynamic_symbol): As above.
* elf32-mips.c (elf_backend_want_dynrelro): Define.
* elf64-mips.c (elf_backend_want_dynrelro): Define.
* elf32-sparc.c (elf_backend_want_dynrelro): Define.
* elf64-sparc.c (elf_backend_want_dynrelro): Define.
* elf32-tilegx.c (elf_backend_want_dynrelro): Define.
* elf64-tilegx.c (elf_backend_want_dynrelro): Define.
* elf32-microblaze.c (microblaze_elf_adjust_dynamic_symbol): Tidy.
(microblaze_elf_size_dynamic_sections): Handle sdynbss.
* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Make use
of linker shortcuts to dynamic sections rather than comparing
names. Correctly set "got" flag.
ld/
PR ld/20995
* testsuite/ld-arm/farcall-mixed-app-v5.d: Update to suit changed
stub hash table traversal caused by section id increment. Accept
the previous output too.
* testsuite/ld-arm/farcall-mixed-app.d: Likewise.
* testsuite/ld-arm/farcall-mixed-lib-v4t.d: Likewise.
* testsuite/ld-arm/farcall-mixed-lib.d: Likewise.
* testsuite/ld-elf/pr20995a.s, * testsuite/ld-elf/pr20995b.s,
* testsuite/ld-elf/pr20995.r: New test.
* testsuite/ld-elf/elf.exp: Run it.