PR 25570
* ldlang.c (lang_size_sections_1): Don't report changes on
second and subsequent iterations that make no change in
alignment from that already reported.
Note that because we should report a signed delta from the previous
VMA it isn't possible to use ngettext. ngettext only supports
unsigned long values. So byte/bytes goes from the message.
PR 25570
* ldlang.c (lang_sizing_iteration): New static var.
(lang_size_sections_1): Warn about no memory region only on first
iteration. Warn about changing start address on first iteration
then any delta from that on subsequent iterations. Report a signed
delta.
(one_lang_size_sections_pass): Increment lang_sizing_iteration.
I reckon it's quite OK to write &p->field in C when p might be NULL,
and lots of old C programmers probably agree with me. However, ubsan
disagrees and so do some people I respect. I suspect C++ influence is
to blame for the ubsan behaviour. See
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92634. So far no one has
educated me as to why I'm wrong to claim that there isn't anything in
the C standard to say that p->field is always (*p).field. Note 79
doesn't quite do that because it doesn't cover null pointers. If
there was such an equivalence then you could claim &p->field has a
null pointer reference when p is NULL, even though no C compiler would
ever dereference p.
Anyway, to silence ubsan I'm going to apply the following though I
prefer to avoid casts when possible. And I'm using (void *)
deliberately because this is C, not C++!
* ldlang.c (lang_output_section_find_by_flags): Don't use &p->field
when p might be NULL.
* ldelf.c (output_rel_find, ldelf_place_orphan): Likewise.
(insert_os_after, lang_insert_orphan, lookup_name): Likewise.
(strip_excluded_output_sections, lang_clear_os_map): Likewise.
(lang_check, lang_for_each_input_file): Likewise.
(lang_reset_memory_regions, find_replacements_insert_point): Likewise.
(find_rescan_insertion, lang_propagate_lma_regions): Likewise.
(lang_record_phdrs): Likewise.
* emultempl/alphaelf.em (alpha_after_open): Likewise.
* emultempl/mmo.em (mmo_place_orphan): Likewise.
* emultempl/pe.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
* emultempl/pep.em (gld_${EMULATION_NAME}_place_orphan): Likewise.
* emultempl/ppc32elf.em (ppc_after_check_relocs): Likewise.
* emultempl/spuelf.em (spu_before_allocation): Likewise.
(embedded_spu_file): Likewise.
and other tidies. I think it's better to default to passing the
section to bfd_octets_per_byte, even in cases where we know it won't
make a difference.
A number of the coff reloc functions used bfd_octets_per_byte wrongly,
not factoring it into the offset into the data buffer. As it happens,
the targets using those files always had bfd_octets_per_byte equal to
one, so there wasn't any detectable wrong behaviour. However, it is
wrong in the source and might cause trouble for anyone creating a new
target. Besides fixing that, the patch also defines OCTETS_PER_BYTE
as one in target files where that is appropriate.
bfd/
* archures.c (bfd_octets_per_byte): Tail call
bfd_arch_mach_octets_per_byte.
* coff-arm.c (OCTETS_PER_BYTE): Define.
(coff_arm_reloc): Introduce new "octets" temp. Use OCTETS_PER_BYTE
with section. Correct "addr". Remove ATTRIBUTE_UNUSED.
* coff-i386.c (coff_i386_reloc): Similarly.
* coff-mips.c (mips_reflo_reloc): Similarly.
* coff-x86_64.c (coff_amd64_reloc): Similarly.
* elf32-msp430.c (OCTETS_PER_BYTE): Define.
(rl78_sym_diff_handler): Use OCTETS_PER_BYTE, with section.
* elf32-nds32.c (nds32_elf_get_relocated_section_contents): Similarly.
* elf32-ppc.c (ppc_elf_addr16_ha_reloc): Similarly.
* elf32-pru.c (pru_elf32_do_ldi32_relocate): Similarly.
* elf32-s12z.c (opru18_reloc): Similarly.
* elf32-sh.c (sh_elf_reloc): Similarly.
* elf32-spu.c (spu_elf_rel9): Similarly.
* elf32-xtensa.c (bfd_elf_xtensa_reloc): Similarly.
* elf64-ppc.c (ppc64_elf_ha_reloc, ppc64_elf_brtaken_reloc),
(ppc64_elf_toc64_reloc): Similarly.
* bfd.c (bfd_get_section_limit): Pass section to bfd_octets_per_byte.
* cofflink.c (_bfd_coff_link_input_bfd),
(_bfd_coff_reloc_link_order): Likewise.
* elf.c (_bfd_elf_section_offset): Likewise.
* elflink.c (resolve_section, bfd_elf_perform_complex_relocation),
(elf_link_input_bfd, elf_reloc_link_order, elf_fixup_link_order),
(bfd_elf_final_link): Likewise.
* elf.c (_bfd_elf_make_section_from_shdr): Don't strncmp twice
to set SEC_ELF_OCTETS.
* reloc.c (bfd_perform_relocation): Tidy SEC_ELF_OCTETS special case.
(bfd_install_relocation): Likewise.
(_bfd_final_link_relocate): Don't recalculate octets.
* syms.c (_bfd_stab_section_find_nearest_line): Introduc new
"octets" temp.
* bfd-in2.h: Regenerate.
ld/
* ldexp.c (fold_name): Pass section to bfd_octets_per_byte.
* ldlang.c (init_opb): Don't call bfd_arch_mach_octets_per_byte
unnecessarily.
All symbols, sizes and relocations in this section are octets instead of
bytes. Required for DWARF debug sections as DWARF information is
organized in octets, not bytes.
bfd/
* section.c (struct bfd_section): New flag SEC_ELF_OCTETS.
* archures.c (bfd_octets_per_byte): New parameter sec.
If section is not NULL and SEC_ELF_OCTETS is set, one octet es
returned [ELF targets only].
* bfd.c (bfd_get_section_limit): Provide section parameter to
bfd_octets_per_byte.
* bfd-in2.h: regenerate.
* binary.c (binary_set_section_contents): Move call to
bfd_octets_per_byte into section loop. Provide section parameter
to bfd_octets_per_byte.
* coff-arm.c (coff_arm_reloc): Provide section parameter
to bfd_octets_per_byte.
* coff-i386.c (coff_i386_reloc): likewise.
* coff-mips.c (mips_reflo_reloc): likewise.
* coff-x86_64.c (coff_amd64_reloc): likewise.
* cofflink.c (_bfd_coff_link_input_bfd): likewise.
(_bfd_coff_reloc_link_order): likewise.
* elf.c (_bfd_elf_section_offset): likewise.
(_bfd_elf_make_section_from_shdr): likewise.
Set SEC_ELF_OCTETS for sections with names .gnu.build.attributes,
.debug*, .zdebug* and .note.gnu*.
* elf32-msp430.c (rl78_sym_diff_handler): Provide section parameter
to bfd_octets_per_byte.
* elf32-nds.c (nds32_elf_get_relocated_section_contents): likewise.
* elf32-ppc.c (ppc_elf_addr16_ha_reloc): likewise.
* elf32-pru.c (pru_elf32_do_ldi32_relocate): likewise.
* elf32-s12z.c (opru18_reloc): likewise.
* elf32-sh.c (sh_elf_reloc): likewise.
* elf32-spu.c (spu_elf_rel9): likewise.
* elf32-xtensa.c (bfd_elf_xtensa_reloc): likewise
* elf64-ppc.c (ppc64_elf_brtaken_reloc): likewise.
(ppc64_elf_addr16_ha_reloc): likewise.
(ppc64_elf_toc64_reloc): likewise.
* elflink.c (bfd_elf_final_link): likewise.
(bfd_elf_perform_complex_relocation): likewise.
(elf_fixup_link_order): likewise.
(elf_link_input_bfd): likewise.
(elf_link_sort_relocs): likewise.
(elf_reloc_link_order): likewise.
(resolve_section): likewise.
* linker.c (_bfd_generic_reloc_link_order): likewise.
(bfd_generic_define_common_symbol): likewise.
(default_data_link_order): likewise.
(default_indirect_link_order): likewise.
* srec.c (srec_set_section_contents): likewise.
(srec_write_section): likewise.
* syms.c (_bfd_stab_section_find_nearest_line): likewise.
* reloc.c (_bfd_final_link_relocate): likewise.
(bfd_generic_get_relocated_section_contents): likewise.
(bfd_install_relocation): likewise.
For section which have SEC_ELF_OCTETS set, multiply output_base
and output_offset with bfd_octets_per_byte.
(bfd_perform_relocation): likewise.
include/
* coff/ti.h (GET_SCNHDR_SIZE, PUT_SCNHDR_SIZE, GET_SCN_SCNLEN),
(PUT_SCN_SCNLEN): Adjust bfd_octets_per_byte calls.
binutils/
* objdump.c (disassemble_data): Provide section parameter to
bfd_octets_per_byte.
(dump_section): likewise
(dump_section_header): likewise. Show SEC_ELF_OCTETS flag if set.
gas/
* as.h: Define SEC_OCTETS as SEC_ELF_OCTETS if OBJ_ELF.
* dwarf2dbg.c: (dwarf2_finish): Set section flag SEC_OCTETS for
.debug_line, .debug_info, .debug_abbrev, .debug_aranges, .debug_str
and .debug_ranges sections.
* write.c (maybe_generate_build_notes): Set section flag
SEC_OCTETS for .gnu.build.attributes section.
* frags.c (frag_now_fix): Don't divide by OCTETS_PER_BYTE if
SEC_OCTETS is set.
* symbols.c (resolve_symbol_value): Likewise.
ld/
* ldexp.c (fold_name): Provide section parameter to
bfd_octets_per_byte.
* ldlang (init_opb): New argument s. Set opb_shift to 0 if
SEC_ELF_OCTETS for the current section is set.
(print_input_section): Pass current section to init_opb.
(print_data_statement,print_reloc_statement,
print_padding_statement): Likewise.
(lang_check_section_addresses): Call init_opb for each
section.
(lang_size_sections_1,lang_size_sections_1,
lang_do_assignments_1): Likewise.
(lang_process): Pass NULL to init_opb.
For targets with octets_per_byte > 1, testsuite/ld-scripts/rgn-over*
produce wrong sizes in the generated map files:
.text 0x0000000000001000 0x6
^^^ # correct
*(.txt)
.txt 0x0000000000001000 0xc tmpdir/rgn-over.o
^^^ # should also be 0x6
* ldlang.c (print_input_section): Shift printed size by opb_shift.
The testcase in the PR has two empty output sections, .sec1 with an
ALIGN and symbol assignment, and .sec2 just with an empty input
section. The symbol assignment results in .sec1 being kept, but
because it is empty this section doesn't take space from the memory
region as you might expect from the ALIGN. Instead the next section
.sec2, has vma/lma as if .sec1 wasn't present. However, .sec2 is
discarded and os->ignored set, which unfortunately meant that dot
wasn't set from .sec2 vma. That in turn results in .sec2 lma being
set incorrectly. That vma/lma difference is then propagated to
.sec3 where it is seen as an overlap.
PR 25081
* ldlang.c (lang_size_sections_1): Set lma from section vma
rather than dot.
This is quite complicated because the CTF section's contents depend on
the final contents of the symtab and strtab, because it has two sections
whose contents are shuffled to be in 1:1 correspondence with the symtab,
and an internal strtab that gets deduplicated against the ELF strtab
(with offsets adjusted to point into the ELF strtab instead). It is
also compressed if large enough, so its size depends on its contents!
So we cannot construct it as early as most sections: we cannot even
*begin* construction until after the symtab and strtab are finalized.
Thankfully there is already one section treated similarly: compressed
debugging sections: the only differences are that compressed debugging
sections have extra handling to deal with their changing name if
compressed (CTF sections are always called ".ctf" for now, though we
have reserved ".ctf.*" against future use), and that compressed
debugging sections have previously-uncompressed content which has to be
stashed away for later compression, while CTF sections have no content
at all until we generate it (very late).
BFD also cannot do the link itself: libctf knows how to do it, and BFD
cannot call libctf directly because libctf already depends on bfd for
file I/O. So we have to use a pair of callbacks, one, examine_strtab,
which allows a caller to examine the symtab and strtab after
finalization (called from elf_link_swap_symbols_out(), right before the
symtabs are written, and after the strtab has been finalized), and one
which actually does the emission (called emit_ctf simply because it is
grouped with a bunch of section-specific late-emission function calls at
the bottom of bfd_elf_final_link, and a section-specific name seems best
for that). emit_ctf is actually called *twice*: once from lang_process
if the emulation suggests that this bfd target does not examine the
symtab or strtab, and once via a bfd callback if it does. (This means
that non-ELF targets still get CTF emitted, even though the late CTF
emission stage is never called for them).
v2: merged with non-ELF support patch: slight commit message
adjustments.
v3: do not spend time merging CTF, or crash, if the CTF section is
explicitly discarded. Do not try to merge or compress CTF unless
linking.
v4: add CTF_COMPRESSION_THRESHOLD. Annul the freed input ctf_file_t's
after writeout: set SEC_IN_MEMORY on the output contents so a future
bfd enhancement knows it could free it. Add SEC_LINKER_CREATED |
SEC_KEEP to avoid having to add .ctf to the linker script. Drop
now-unnecessary ldlang.h-level elf-bfd.h include and hackery around
it. Adapt to elf32.em->elf.em and elf-generic.em->ldelf*.c
changes.
v5: fix tabdamage. Drop #inclusions in .h files: include in .c files,
.em files, and use struct forwards instead. Use bfd_section_is_ctf
inline function rather than SECTION_IS_CTF macro. Move a few
comments.
* Makefile.def (dependencies): all-ld depends on all-libctf.
* Makefile.in: Regenerated.
include/
* bfdlink.h (elf_strtab_hash): New forward.
(elf_sym_strtab): Likewise.
(struct bfd_link_callbacks <examine_strtab>): New.
(struct bfd_link_callbacks <emit_ctf>): Likewise.
bfd/
* elf-bfd.h (bfd_section_is_ctf): New inline function.
* elf.c (special_sections_c): Add ".ctf".
(assign_file_positions_for_non_load_sections): Note that
compressed debugging sections etc are not assigned here. Treat
CTF sections like SEC_ELF_COMPRESS sections when is_linker_output:
sh_offset -1.
(assign_file_positions_except_relocs): Likewise.
(find_section_in_list): Note that debugging and CTF sections, as
well as reloc sections, are assigned later.
(_bfd_elf_assign_file_positions_for_non_load): CTF sections get
their size and contents updated.
(_bfd_elf_set_section_contents): Skip CTF sections: unlike
compressed sections, they have no uncompressed content to copy at
this stage.
* elflink.c (elf_link_swap_symbols_out): Call the examine_strtab
callback right before the strtab is written out.
(bfd_elf_final_link): Don't cache the section contents of CTF
sections: they are not populated yet. Call the emit_ctf callback
right at the end, after all the symbols and strings are flushed
out.
ld/
* ldlang.h: (struct lang_input_statement_struct): Add the_ctf.
(struct elf_sym_strtab): Add forward.
(struct elf_strtab_hash): Likewise.
(ldlang_ctf_apply_strsym): Declare.
(ldlang_write_ctf_late): Likewise.
* ldemul.h (ldemul_emit_ctf_early): New.
(ldemul_examine_strtab_for_ctf): Likewise.
(ld_emulation_xfer_type) <emit_ctf_early>: Likewise.
(ld_emulation_xfer_type) <examine_strtab_for_ctf>: Likewise.
* ldemul.c (ldemul_emit_ctf_early): New.
(ldemul_examine_strtab_for_ctf): Likewise.
* ldlang.c: Include ctf-api.h.
(CTF_COMPRESSION_THRESHOLD): New.
(ctf_output): New. Initialized in...
(ldlang_open_ctf): ... this new function. Open all the CTF
sections in the input files: mark them non-loaded and empty
so as not to copy their contents to the output, but linker-created
so the section gets created in the target.
(ldlang_merge_ctf): New, merge types via ctf_link_add_ctf and
ctf_link.
(ldlang_ctf_apply_strsym): New, an examine_strtab callback: wrap
ldemul_examine_strtab_for_ctf.
(lang_write_ctf): New, write out the CTF section.
(ldlang_write_ctf_late): New, late call via bfd's emit_ctf hook.
(lang_process): Call ldlang_open_ctf, ldlang_merge_ctf, and
lang_write_ctf.
* ldmain.c (link_callbacks): Add ldlang_ctf_apply_strsym,
ldlang_write_ctf_late.
* emultempl/aix.em: Add ctf-api.h.
* emultempl/armcoff.em: Likewise.
* emultempl/beos.em: Likewise.
* emultempl/elf.em: Likewise.
* emultempl/generic.em: Likewise.
* emultempl/linux.em: Likewise.
* emultempl/msp430.em: Likewise.
* emultempl/pe.em: Likewise.
* emultempl/pep.em: Likewise.
* emultempl/ticoff.em: Likewise.
* emultempl/vanilla.em: Likewise.
* ldcref.c: Likewise.
* ldctor.c: Likewise.
* ldelf.c: Likewise.
* ldelfgen.c: Likewise.
* ldemul.c: Likewise.
* ldexp.c: Likewise.
* ldfile.c: Likewise.
* ldgram.c: Likewise.
* ldlex.l: Likewise.
* ldmain.c: Likewise.
* ldmisc.c: Likewise.
* ldver.c: Likewise.
* ldwrite.c: Likewise.
* lexsup.c: Likewise.
* mri.c: Likewise.
* pe-dll.c: Likewise.
* plugin.c: Likewise.
* ldelfgen.c (ldelf_emit_ctf_early): New.
(ldelf_examine_strtab_for_ctf): tell libctf about the symtab and
strtab.
(struct ctf_strsym_iter_cb_arg): New, state to do so.
(ldelf_ctf_strtab_iter_cb): New: tell libctf about
each string in the strtab in turn.
(ldelf_ctf_symbols_iter_cb): New, tell libctf
about each symbol in the symtab in turn.
* ldelfgen.h (struct elf_sym_strtab): Add forward.
(struct elf_strtab_hash): Likewise.
(struct ctf_file): Likewise.
(ldelf_emit_ctf_early): Declare.
(ldelf_examine_strtab_for_ctf): Likewise.
* emultempl/elf-generic.em (LDEMUL_EMIT_CTF_EARLY): Set it.
(LDEMUL_EXAMINE_STRTAB_FOR_CTF): Likewise.
* emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Add
emit_ctf_early and examine_strtab_for_ctf, NULL by default.
* emultempl/armcoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/beos.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/elf.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/generic.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/linux.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/msp430.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/pe.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/pep.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/ticoff.em (ld_${EMULATION_NAME}_emulation): Likewise.
* emultempl/vanilla.em (ld_vanilla_emulation): Likewise.
* Makefile.am: Pull in libctf (and zlib, a transitive requirement
for compressed CTF section emission). Pass it on to DejaGNU.
* configure.ac: Add AM_ZLIB.
* aclocal.m4: Added zlib.m4.
* Makefile.in: Regenerated.
* testsuite/ld-bootstrap/bootstrap.exp: Use it when relinking ld.
I was looking at the implementation of this script keyword today and
couldn't remember why we do what we do in get_init_priority, because
the comments explain how the init_priority is encoded but don't say
why it is necessary to extract the priority and sort on that. So
after figuring out why (again), I wrote some more comments.
Then I simplified get_init_priority a little, adding some sanity
checking on the strtoul result. This actually makes get_init_priority
support sorting by numerical suffix more generally, but I figure this
feature would be better as a new keyword (without the .ctors/.dtors
special case), so haven't documented the extension.
* ld.texi (SORT_BY_ALIGNMENT): Reword slightly.
(SORT_BY_INIT_PRIORITY): Elucidate.
* ldlang.c: Include limits.h.
(get_init_priority): Comment. Change param to a section,
return an int. Sanity check priority digits. Support sorting
more sections with trailing digits. Return -1 on error.
(compare_section): Adjust.
This one exposed a bug in tic6x gas, found with inline function
parameter type checking. struct bfd_section and struct bfd_symbol
both have a flags field, so bfd_is_com_section (symbol) compiled OK
when bfd_is_com_section was a macro but didn't special case common
symbols.
bfd/
* bfd-in.h (bfd_section_name, bfd_section_size, bfd_section_vma),
(bfd_section_lma, bfd_section_alignment, bfd_section_flags),
(bfd_section_userdata, bfd_is_com_section, discarded_section),
(bfd_get_section_limit_octets, bfd_get_section_limit): Delete macros.
* bfd.c (bfd_get_section_limit_octets, bfd_get_section_limit),
(bfd_section_list_remove, bfd_section_list_append),
(bfd_section_list_prepend, bfd_section_list_insert_after),
(bfd_section_list_insert_before, bfd_section_removed_from_list):
New inline functions.
* section.c (bfd_is_und_section, bfd_is_abs_section),
(bfd_is_ind_section, bfd_is_const_section, bfd_section_list_remove),
(bfd_section_list_append, bfd_section_list_prepend),
(bfd_section_list_insert_after, bfd_section_list_insert_before),
(bfd_section_removed_from_list): Delete macros.
(bfd_section_name, bfd_section_size, bfd_section_vma),
(bfd_section_lma, bfd_section_alignment, bfd_section_flags),
(bfd_section_userdata, bfd_is_com_section, bfd_is_und_section),
(bfd_is_abs_section, bfd_is_ind_section, bfd_is_const_section),
(discarded_section): New inline functions.
* bfd-in2.h: Regenerate.
gas/
* config/tc-tic6x.c (tc_gen_reloc): Correct common symbol check.
ld/
* emultempl/xtensaelf.em (xtensa_get_section_deps): Comment.
Use bfd_section_userdata.
(xtensa_set_section_deps): Use bfd_set_section_userdata.
* ldlang.c (lang_output_section_get): Use bfd_section_userdata.
(sort_def_symbol): Likewise, and bfd_set_section_userdata.
(init_os): Use bfd_set_section_userdata.
(print_all_symbols): Use bfd_section_userdata.
* ldlang.h (get_userdata): Delete.
I think this is safer than leaving an input_statement added during
open_input_bfds off the list. There are a number of places that
fiddle with various lists and might be confused by an off-list
statement, eg. orphan handling.
* ldlang.c (new_afile): Remove add_to_list parameter.
(lang_add_input_file): Update new_afile calls.
(lookup_name): Splice input_statement added by new_afile into
statement_list after current input_file_chain entry.
(lang_process): Update comment.
For some reason, commit 906e58cab5 2008-05-15 excluded input
statements with BFD_LINKER_CREATED BFDs from being printed to map
files. This isn't ideal since it loses claimed plugin BFDs.
* ldlang.c (print_input_statement): Do not exclude linker created
BFDs.
This fixes a problem with commit 128bf1fe60, a patch I made
2019-08-06. Apparently it is possible to trigger the assertion I
added during an LTO bootstrap, something I haven't reproduced.
However, I did find a case triggered by an odd linker script feature
that allows a file to be loaded from the script without specifying
that file on the command line. Regarding input sections:
"When you use a file name which is not an archive:file specifier
and does not contain any wild card characters, the linker will
first see if you also specified the file name on the linker command
line or in an INPUT command. If you did not, the linker will
attempt to open the file as an input file, as though it appeared on
the command line."
So putting
.foo : { foo.a(*) }
into a script supposedly extracts foo.a into .foo. Except it doesn't,
since this feature is meant for object files only. Well anyway,
assuming --whole-archive was given on the command line, foo.a contains
a -flto object and no other objects involved were -flto then we'll hit
the assert due to files added like foo.a here *not* having their input
statement put on the general statement list. Why these are not put on
the statement list isn't obvious but it has been that way since commit
193c5f93a1 in 1994.
PR 24981
* ldlang.c (lang_process): Remove assertion. Comment.
"next" and "next_real_file" in lang_input_statement_type always point
to another lang_input_statement_type, so it makes sense for these to
not be the generic lang_statement_union_type. This patch also updates
a number of variables in ldlang.c for the same reason, and modifies
lang_statement_append to reduce the need for casts.
* ldlang.h (lang_input_statement_type): Make next
and next_real_file a lang_input_statement_type pointer.
(lang_statement_append): Delete prototype.
(LANG_FOR_EACH_INPUT_STATEMENT): Update for lang_input_statement_type
change.
* ldmain.c (add_archive_element): Likewise.
* ldlang.c: Likewise throughout.
(lang_statement_append): Make static. Make element and field
void pointers. Remove casts in calls.
(lang_check): Use a lang_input_statement_type pointer for "file".
(find_rescan_insertion): Similarly for "iter" and return value.
(lang_process): Similarly for "insert", "iter" and "temp".
* emultempl/spuelf.em (embedded_spu_file): Likewise.
* emultempl/aix.em (gld${EMULATION_NAME}_before_allocation): Expand
lang_statment_append call.
This is a mostly cosmetic fix for cases like PR24873 where LTO
recompiled objects were supposed to be inserted inside a group. The
specific case handled by this patch is when the first file inside a
group is an archive, the first file claimed by the plugin. Prior to
this patch we would have inserted the recompiled objects before the
group, which doesn't matter really since the entire group will be
reloaded, but it looks a little wrong in map files.
PR 24873
* ldlang.c (find_replacements_insert_point): Return "before" flag.
(find_next_input_statement): New function.
(lang_process): When placing recompiled LTO objects before a
claimed archive, place them immediately before in the statement
list.
Reloading of archives (and checking --as-needed DSOs again) is
disabled until we hit the plugin insert point. It's necessary to do
that because in a case like lib1.a lto.o lib2.a where lib1.a and
lib2.a contain duplicate symbols, we want the lto.o recompiled object
to pull in objects from lib2.a as necessary, but not from lib1.a.
Unfortunately this heuristic fails when the insert point is inside a
group, because ld actually loads the symbols from the recompiled
object before running over the contours of the script, thus missing
the fact that new undefs appeared in the group.
PR 24873
* ldlang.c (plugin_undefs): New static var.
(open_input_bfds <lang_group_statement_enum>): Loop on
plugin_undefs and hitting plugin_insert point.
(lang_process <lto_plugin_active>): Set plugin_undefs.
This patch processes INSERT AFTER and INSERT BEFORE in a user -T
script when such a script is invoked on the command line inside
--start-group/--end-group. Also, ld now warns when the user simply
forgot --end-group.
PR 24806
* ldlang.c (process_insert_statements): Add start of list
parameter. Use rather than lang_os_list.head. Process insert
statements inside group statements with a recursive call.
(lang_process): Adjust process_insert_statements call.
* lexsup.c (parse_args): Warn when adding missing --end-group.
The idea is to make it a little easier to find uses of this list,
so searches don't hit occurrences of lang_output_section_statement_type
and lang_output_section_statement_enum.
* ldlang.h (lang_os_list): Rename from lang_output_section_statement.
* ldlang.c: Likewise throughout file.
* emultempl/alphaelf.em: Likewise.
* emultempl/elf32.em: Likewise.
* emultempl/mmo.em: Likewise.
* emultempl/pe.em: Likewise.
* emultempl/pep.em: Likewise.
* emultempl/ppc32elf.em: Likewise.
* emultempl/spuelf.em: Likewise.
This stops the first overlay section being ignored when empty,
losing its LMA assignment
PR 24786
* ldlang.h (enum section_type): Add first_overlay_section.
* ldlang.c (lang_add_section): Adjust switch statement.
(map_input_to_output_sections): Likewise.
(lang_size_sections_1): Always set last_os for first overlay section.
(lang_leave_overlay): Set sectype to first_overlay_section.
Add a new option to disable the listing of discarded sections
in map file output. The use case stems from a large application
built with -ffunction-sections --gc-sections where the list of
discarded sections blows up the map file output. The default
behaviour remains to print discarded sections, but the new option
allows us to disable it.
ld/
* NEWS: Mention new option --no-print-map-discarded.
* ld.h (ld_config_type) <print_map_discarded>: New field.
* ldlang.c (lang_map): Conditionally output discarded sections
in map files based on configuration option.
* ldlex.h (option_values) <OPTION_PRINT_MAP_DISCARDED,
OPTION_NO_PRINT_MAP_DISCARDED>: New.
* ldmain.c (main): Enabled print_map_discarded by default.
* lexsup.c (ld_options): Add new command-line options.
(parse_args) <OPTION_NO_PRINT_MAP_DISCARDED,
OPTION_PRINT_MAP_DISCARDED>: New cases.
* ld.texi: Document new options.
* testsuite/ld-gc/gc.exp: Add new test.
* testsuite/ld-gc/skip-map-discarded.s: New file.
* testsuite/ld-gc/skip-map-discarded.d: New file.
* testsuite/ld-gc/skip-map-discarded.map: New file.
The special case for .init and .fini in update_wild_statements is
ineffective for .init or .fini wildcards inside other output sections.
The special case needs to be on the wildcard, not the output section.
This patch is belt and braces, both fixing update_wild_statements and
the scripts.
* scripttempl/alpha.sc, * scripttempl/armbpabi.sc,
* scripttempl/crisaout.sc, * scripttempl/elf32cr16.sc,
* scripttempl/elf32crx.sc, * scripttempl/elf32xc16x.sc,
* scripttempl/elf32xc16xl.sc, * scripttempl/elf32xc16xs.sc,
* scripttempl/elf64hppa.sc, * scripttempl/elf_chaos.sc,
* scripttempl/elfarc.sc, * scripttempl/elfarcv2.sc,
* scripttempl/elfd30v.sc, * scripttempl/elfm68hc11.sc,
* scripttempl/elfm68hc12.sc, * scripttempl/elfm9s12z.sc,
* scripttempl/elfmicroblaze.sc, * scripttempl/elfxgate.sc,
* scripttempl/elfxtensa.sc, * scripttempl/epiphany_4x4.sc,
* scripttempl/ft32.sc, * scripttempl/i386beos.sc,
* scripttempl/iq2000.sc, * scripttempl/mcorepe.sc,
* scripttempl/mep.sc, * scripttempl/mips.sc, * scripttempl/moxie.sc,
* scripttempl/pe.sc, * scripttempl/pep.sc, * scripttempl/ppcpe.sc,
* scripttempl/tic4xcoff.sc, * scripttempl/tic80coff.sc,
* scripttempl/v850.sc, * scripttempl/v850_rh850.sc,
* scripttempl/visium.sc, * scripttempl/xstormy16.sc: Add KEEP and
SORT_NONE to .init and .fini wildcards.
* scripttempl/elf32xc16x.sc,
* scripttempl/elf32xc16xl.sc,
* scripttempl/elf32xc16xs.sc: Add .fini wildcard.
* scripttempl/elf_chaos.sc: Add .init output section.
* scripttempl/elfd30v.sc: Remove duplicate .init.
* scripttempl/elfm68hc11.sc, * scripttempl/elfm68hc12.sc,
* scripttempl/elfm9s12z.sc, * scripttempl/elfxgate.sc: Remove
duplicate .init, and add .fini wildcard.
* scripttempl/ppcpe.sc (INIT, FINI): Delete.
* ldlang.c (update_wild_statements): Special case .init and
.fini in the wildcard, not the output section.
Generic linker ELF targets using CREATE_OBJECT_SYMBOLS in their
scripts run into a problem. The file symbols are created by
_bfd_generic_link_output_symbols in each object file, in the section
corresponding to the CREATE_OBJECT_SYMBOLS section, typically .text.
If it so happens that the output .text section is stripped due to
being empty, then elf.c:assign_section_numbers won't assign an ELF
section number and swap_out_syms will report "unable to find
equivalent output section" for the object symbols. Fix this by
always keeping an output section with CREATE_OBJECT_SYMBOLS.
* ldlang.c (lang_size_sections_1): Set SEC_KEEP on
create_object_symbols_section.
* testsuite/ld-elf/pr22319.d: Don't xfail dlx.
PR 24008
* ldexp.h (lang_phase_type): Add lang_fixed_phase_enum.
* ldexp.c (fold_name): Move expld.assign_name check later to
avoid an extra lookup.
(exp_fold_tree_1): When lang_fixed_phase_enum, don't change symbol
values, and don't clear expld.assign_name.
* ldlang.c (lang_map): Set expld.phase to lang_fixed_phase_enum.
(print_assignment): Resolve entire assignment expression.
Don't access symbol u.def unless symbol is defined.
When discovering the statement lists via their header variable
statement_list, file_chain and input_file_chain it can be confusing to
figure out what they are for. They can point to the same initial
statement and the relation between the next field they use is not
obvious from the name.
This commit adds comment for each of those statement list header to
explain what they are for and what next field they use. It also rewrite
the comment for the next fields to simply redirect the reader to the
list header to avoid duplication of documentation.
2018-11-29 Thomas Preud'homme <thomas.preudhomme@linaro.org>
ld/
* ldlang.c (statement_list): Document purpose and what next field it
uses.
(file_chain): Likewise.
(input_file_chain): Likewise.
* ldlang.h (lang_statement_header_type): Document statement list header
the next pointer correspond to.
(lang_statement_header_type): Replace comment for next and
next_real_file field to refer the reader to their corresponding
statement list header.
The idea of this change is to make -t output useful for users wanting
to package all the object files involved in linking for a bug report.
Something like the following should do the trick.
gcc hello.c -save-temps -Wl,-t | xargs realpath | sort | uniq > files
tar cJf test.tar.xz `cat files`
* ldlang.c (load_symbols): When -t, print file names for script
files and archives.
* ldmain.c (trace_files): Make an int.
(add_archive_element): Print archive elements only with multiple
-t options, or when archive is thin.
* ldmain.h (trace_files): Update.
* ldmisc.c (vfinfo): Don't print both original path and path in
sysroot.
* lexsup.c (parse_args <t>): Increment trace_files.
A symbol root is not needed if --gc-keep-exported is also given.
* ldlang.c (lang_end): Don't error if no --entry or --undefined
is given with -r -gc-sections if --gc-keep-exported.
Properly group orphan note sections. When placing orphan note section
as the first note section, place it after the section before all note
sections.
PR ld/23658
* ldlang.c (lang_insert_orphan): Properly group and place orphan
note sections. Properly handle orphan note section before all
note sections.
* testsuite/ld-elf/pr23658-1.d: Renamed to ...
* testsuite/ld-elf/pr23658-1a.d: This. Updated.
* testsuite/ld-elf/pr23658-1b.d: New test.
* testsuite/ld-elf/pr23658-1c.d: Likewise.
Some time ago the pr19593 test was xfailed for alpha. This turned out
to be the wrong course of action since the test exposed a bug in
orphan section placement. On alpha, orphan sections were being
inserted before ". = SIZEOF_HEADERS" due to the test having two
assignments, and on alpha, an output section statement from
-Ttext-segment being passed to ld.
* ldlang.c (insert_os_after): Clear ignore_first on assignment to
dot, not any assignment. Clear ignore_first on output section
statement contents too.
* testsuite/ld-elf/pr19539.d: Remove alpha xfail.
To support putting all adjacent SHT_NOTE sections with the same section
alignment into a single PT_NOTE segment, lang_insert_orphan must group
and sort output note sections by section alignments in both output
section list as well as output section statement list.
PR ld/23658
* ldlang.c (lang_insert_orphan): Group and sort output note
sections by section alignments.
When there are more than one input sections with the same section name,
SECNAME, linker picks the first one to define __start_SECNAME and
__stop_SECNAME symbols. When the first input section is removed by
comdat group, we need to check if there is still an output section
with section name SECNAME.
PR ld/23591
* ldlang.c (undef_start_stop): Lookup section in output with
the same name.
* testsuite/ld-elf/pr23591.d: New file.
* testsuite/ld-elf/pr23591a.s: Likewise.
* testsuite/ld-elf/pr23591b.s: Likewise.
* testsuite/ld-elf/pr23591c.s: Likewise.
git commit 702d16713 broke expressions using CONSTANT(COMMONPAGESIZE)
in ALIGN or SUBALIGN of output section statements, because these
optional fields were evaluated at script parse time and the patch in
question delayed setting of config.commonpagesize. The right thing to
do is keep the tree representation of those fields for later
evaluation.
PR 23571
* ldlang.h (section_alignment): Make it an expression tree.
(subsection_alignment): Likewise.
* ldlang.c (topower): Delete.
(output_section_statement_newfunc): Adjust initialization.
(init_os): Evaluate section_alignment.
(lang_size_sections_1): Likewise.
(size_input_section): Evaluate subsection_alignment.
(lang_enter_output_section_statement): Don't evaluate here.
(lang_new_phdr): Use exp_get_vma rather than exp_get_value_int.
* ldexp.h (exp_get_value_int): Delete.
(exp_get_power): Declare.
* ldexp.c (exp_get_value_int): Delete.
(exp_get_power): New function.
* emultempl/pe.em (place_orphan): Build expression for section
alignment.
* emultempl/pep.em (place_orphan): Likewise.
* testsuite/ld-scripts/pr23571.d,
* testsuite/ld-scripts/pr23571.t: New test.
* testsuite/ld-scripts/align.exp: Run it.
Set non_ir_ref_regular to TRUE for symbols forced into the output file
so that they won't be removed by garbage collection with LTO.
PR ld/23309
* ldlang.c (insert_undefined): Set non_ir_ref_regular to TRUE.
* plugin.c (is_visible_from_outside): Don't scan entry_symbol.
* testsuite/ld-plugin/pr23309.c: New file.
* testsuite/ld-plugin/pr23309.d: Likewise.