Age | Commit message (Collapse) | Author | Files | Lines |
|
The newer update-copyright.py fixes file encoding too, removing cr/lf
on binutils/bfdtest2.c and ld/testsuite/ld-cygwin/exe-export.exp, and
embedded cr in binutils/testsuite/binutils-all/ar.exp string match.
|
|
A number of targets use assignments like:
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 12 ? 12 : 0, .);
(from i386) in linker scripts to put the end of the relro segment past
the header in .got.plt. Examination of testcases like those edited by
this patch instead sees the end of the relro segment being placed at
the start of .got.plt. For the i386 pie1 test:
[ 9] .got.plt PROGBITS 00002000 001000 00000c 04 WA 0 0 4
GNU_RELRO 0x000f90 0x00001f90 0x00001f90 0x00070 0x00070 R 0x1
A map file shows:
.dynamic 0x0000000000001f90 0x70
*(.dynamic)
.dynamic 0x0000000000001f90 0x70 tmpdir/pie1.o
0x0000000000001f90 _DYNAMIC
.got 0x0000000000002000 0x0
*(.got)
.got 0x0000000000002000 0x0 tmpdir/pie1.o
*(.igot)
0x0000000000002ff4 . = DATA_SEGMENT_RELRO_END (., (SIZEOF (.got.plt) >= 0xc)?0xc:0x0)
.got.plt 0x0000000000002000 0xc
*(.got.plt)
.got.plt 0x0000000000002000 0xc tmpdir/pie1.o
0x0000000000002000 _GLOBAL_OFFSET_TABLE_
The DATA_SEGMENT_RELRO_END value in the map file is weird too. All of
this is triggered by SIZEOF (.got.plt) being evaluated wrongly as
zero. Fix it by taking into account the action of
lang_reset_memory_regions during relaxation.
* ldexp.c (fold_name <SIZEOF>): Use rawsize if size has been reset.
* ldlang.c (lang_size_sections_1): Don't reset processed_vma here.
* testsuite/ld-i386/pie1.d: Adjust to suit.
* testsuite/ld-x86-64/pr20830a.d: Likewise.
* testsuite/ld-x86-64/pr20830b.d: Likewise.
* testsuite/ld-x86-64/pr21038a.d: Likewise.
* testsuite/ld-x86-64/pr21038b.d: Likewise.
* testsuite/ld-x86-64/pr21038c.d: Likewise.
|
|
This reverts commit 31b4d3a16f200bf04db8439a63b72bba7af4e1be.
|
|
The better to see any code that accesses expld.dataseg.
* ldexp.c (fold_segment_end): Remove seg parameter. Adjust calls.
(fold_segment_align, fold_segment_relro_end): Likewise.
* ldlang.c (lang_size_segment): Likewise.
(lang_size_relro_segment_1, lang_find_relro_sections_1): Likewise.
|
|
x86 treats MAXPAGESIZE as a memory optimisation parameter, actual
hardware paging is always COMMPAGESIZE of 4k. Use COMMONPAGESIZE for
the end of the relro segment alignment.
The previous patch regresses pr18176, increasing the testcase file
size from 322208 to 2099872 bytes. Fixing this on x86 will require
introducing a gap after the end of the relro segment (of up to
relropagesize-1 bytes).
PR 28824
PR 18176
* ld.h (ld_config_type): Add relro_use_commonpagesize field.
* ldexp.c (fold_segment_align): Set relropagesize depending on
relro_use_commonpagesize.
* emultempl/elf-x86.em (elf_x86_create_output_section_statements):
Set relro_use_commonpagesize.
* testsuite/ld-x86-64/pr18176.d: xfail.
|
|
Background
==========
There are constraints on layout of binaries to meet demand paging and
memory protection requirements. Demand paged binaries must have file
offset mod pagesize equal to vma mod pagesize. Memory protection
(executable, read, write status) can only change at page boundaries.
The linker's MAXPAGESIZE variable gives the page size for these layout
constraints.
In a typical basic executable with two memory segments, text (RE) and
data (RW), the data segment must start on a different page to the
last text segment page. For example, with 64k pages and a small
executable of 48k text and 1k data, the text segment might start at
address 0x10000 and data at 0x20000 for a total of two 64k memory
pages. Demand paging would require the image on disk to be 64k+1k
in size. We can do better than that. If the data segment instead
starts at 0x2c000 (the end of the text segment plus one 64k page) then
there are still only two memory pages, but the disk image is now
smaller, 48k+1k in size. This is why the linker normally starts the
data segment at the end of the text segment plus one page. That
simple heuristic isn't ideal in all cases. Changing our simple
example to one with 64k-1 text size, following that heuristic would
result in data starting at 0x2ffff. Now we have two 64k memory data
pages for a data segment of 1k! If the data segment instead started
at 0x30000 we'd get a single data segment page at the cost of 1 byte
extra in the disk image, which is likely a good trade-off. So the
linker does adjust the simple heuristic. Just how much disk image
size increase is allowed is controlled by the linker's COMMONPAGESIZE
variable.
A PT_GNU_RELRO segment overlays the initial part of the data segment,
saying that those pages should be made read-only after relocation by
the dynamic loader. Page granularity for memory protection means that
the end of the relro segment must be at a page boundary.
The problem
===========
Unfortunately most targets currently only align the end of the relro
segment to COMMONPAGESIZE. That results in only partial relro
protection if an executable is running with MAXPAGESIZE pages, since
any part of the relro segment past the last MAXPAGESIZE boundary can't
be made read-only without also affecting sections past the end of the
relro segment. I believe this problem arose because x86 always runs
with 4k (COMMPAGESIZE) memory pages, and therefore using a larger
MAXPAGESIZE on x86 is for reasons other than the demand paging and
memory page protection boundary requirements.
The solution
============
Always end the relro segment on a MAXPAGESIZE boundary, except for
x86. Note that the relro segment, comprising of sections at the start
of the data segment, is sized according to how those sections are laid
out. That means the start of the relro segment is fixed relative to
its end. Which also means the start of the data segment must be at a
fixed address mod MAXPAGESIZE. So for relro the linker can't play
games with the start of the data segment to save disk space. At
least, not without introducing gaps between the relro sections. In
fact, because the linker was starting layout using its simple
heuristic of starting the data segment at the end of the text segment
plus one page, it was sometimes introducing page gaps for no reason.
See pr28743.
PR 28824
PR 28734
* ldexp.c (fold_segment_align): When relro, don't adjust up by
offset within page. Set relropagesize.
(fold_segment_relro_end): Align to relropagesize.
* ldexp.h (seg_align_type): Rename pagesize to commonpagesize.
Add relropagesize. Comment.
* ldlang.c (lang_size_segment): Adjust to suit field renaming.
(lang_size_relro_segment_1): Align relro_end using relropagesize.
|
|
The result of running etc/update-copyright.py --this-year, fixing all
the files whose mode is changed by the script, plus a build with
--enable-maintainer-mode --enable-cgen-maint=yes, then checking
out */po/*.pot which we don't update frequently.
The copy of cgen was with commit d1dd5fcc38ead reverted as that commit
breaks building of bfp opcodes files.
|
|
In commit 89753bbf81 I enabled a warning for scripts redefining
symbols. The idea was to not warn for symbols defined by shared
libraries (the h->u.def.section->output_section != NULL test), but the
test failed to take into account absolute symbols. Absolute symbols
defined in shared libraries are currently indistinguishable from
absolute symbols defined in relocatable objects, at least when only
looking at struct bfd_link_hash_entry. So, don't warn for any
absolute symbols.
* ldexp.c (update_definedness): Don't return false for absolute
symbols.
* ldmain.c (multiple_definition): Print "warning: " in message
when not a hard error.
|
|
* sysdep.h (POISON_BFD_BOOLEAN): Define.
* configure.ac (elf_list_options, elf_shlib_list_options=false),
(elf_plt_unwind_list_options=false): Replace FALSE with false,
and TRUE with true.
* emulparams/call_nop.sh, * emulparams/cet.sh,
* emulparams/dynamic_undefined_weak.sh,
* emulparams/elf32b4300.sh, * emulparams/elf32lm32.sh,
* emulparams/elf32lr5900.sh, * emulparams/elf32lr5900n32.sh,
* emulparams/elf32visium.sh, * emulparams/elf_x86_64.sh,
* emulparams/extern_protected_data.sh, * emulparams/plt_unwind.sh,
* emulparams/reloc_overflow.sh, * emulparams/static.sh,
* emulparams/x86-64-lam.sh, * emultempl/aarch64elf.em,
* emultempl/aix.em, * emultempl/alphaelf.em,
* emultempl/armcoff.em, * emultempl/armelf.em,
* emultempl/avrelf.em, * emultempl/beos.em, * emultempl/bfin.em,
* emultempl/cr16elf.em, * emultempl/crxelf.em,
* emultempl/cskyelf.em, * emultempl/elf.em, * emultempl/genelf.em,
* emultempl/hppaelf.em, * emultempl/linux.em,
* emultempl/m68hc1xelf.em, * emultempl/metagelf.em,
* emultempl/mipself.em, * emultempl/mmix-elfnmmo.em,
* emultempl/mmixelf.em, * emultempl/mmo.em, * emultempl/msp430.em,
* emultempl/nios2elf.em, * emultempl/pdp11.em, * emultempl/pe.em,
* emultempl/pep.em, * emultempl/ppc32elf.em,
* emultempl/ppc64elf.em, * emultempl/rxelf.em,
* emultempl/rxlinux.em, * emultempl/scoreelf.em,
* emultempl/solaris2.em, * emultempl/spuelf.em,
* emultempl/ticoff.em, * emultempl/v850elf.em, * emultempl/vms.em,
* emultempl/xtensaelf.em, * emultempl/z80.em, * ld.h,
* ldbuildid.c, * ldbuildid.h, * ldcref.c, * ldctor.c, * ldctor.h,
* ldelf.c, * ldelf.h, * ldelfgen.c, * ldelfgen.h, * ldemul.c,
* ldemul.h, * ldexp.c, * ldexp.h, * ldfile.c, * ldfile.h,
* ldgram.y, * ldlang.c, * ldlang.h, * ldmain.c, * ldmain.h,
* ldmisc.c, * ldmisc.h, * ldwrite.c, * lexsup.c, * mri.c,
* pe-dll.c, * pe-dll.h, * pep-dll.h, * plugin.c, * plugin.h,
* testplug.c, * testplug2.c, * testplug3.c, * testplug4.c: Replace
bfd_boolean with bool, FALSE with false, and TRUE with true.
* configure: Regenerate.
|
|
It is the very nature of absolute symbols that they don't change even
if the loader decides to put the image at other than its link-time base
address. Of the linker-defined (and PE-specific) symbols __image_base__
(and its alias) needs special casing, as it'll still appear to be
absolute at this point.
A new inquiry function in ldexp.c is needed because PE base relocations
get generated before ldexp_finalize_syms() runs, yet whether a
relocation is needed depends on the ultimate property of a symbol.
|
|
Note that we don't even warn if scripts adjust a symbol as in
ld-elf/var1 and ld-scripts/pr14962.
include/
* bfdlink.h (struct bfd_link_info): Add warn_multiple_definition.
ld/
* ldexp.c (exp_fold_tree_1): Warn on script defining a symbol
defined in an object file.
* ldmain.c (multiple_definition): Heed info->warn_multiple_definition.
* testsuite/ld-scripts/defined5.d: Expect a warning.
|
|
|
|
elfNN_bed was made writable as an expedient means of communicating
ld -z max-page-size and ld -z common-page-size values to BFD linker
code, and even for objcopy to communicate segment alignment between
copy_private_bfd_data, rewrite_elf_program_header and
assign_file_positions_for_load_sections. Some time later elfNN_bed
elf_osabi was written by gas. It turns out none of these
modifications to elfNN_bed was necessary, so make it const again.
include/
* bfdlink.h (struct bfd_link_info): Add maxpagesize and
commonpagesize.
bfd/
* elfxx-target.h (elfNN_bed): Constify.
* bfd.c (bfd_elf_set_pagesize): Delete.
(bfd_emul_set_maxpagesize, bfd_emul_set_commonpagesize): Delete.
* elf.c (get_program_header_size): Get commonpagesize from
link info.
(_bfd_elf_map_sections_to_segments): Get maxpagesize from link info.
(assign_file_positions_for_load_sections): Likewise.
(assign_file_positions_for_non_load_sections): Likewise.
(rewrite_elf_program_header): Add maxpagesize param. Set map_p_align.
(copy_private_bfd_data): Don't call bfd_elf_set_maxpagesize.
Instead pass maxpagesize to rewrite_elf_program_header.
* elf32-nds32.c (relax_range_measurement): Add link_info param.
Get maxpagesize from link_info. Adjust caller.
* bfd-in2.h: Regenerate.
gas/
* config/obj-elf.c (obj_elf_section): Don't set elf_osabi here.
(obj_elf_type): Likewise.
ld/
* ld.h (ld_config_type): Delete maxpagesize and commonpagesize.
* emultempl/elf.em: Use link_info rather than config
for maxpagesize and commonpagesize.
* emultempl/ppc32elf.em: Likewise.
* ldexp.c (fold_binary, fold_name): Likewise.
* ldemul.c (after_parse_default): Likewise.
(set_output_arch_default): Don't call bfd_emul_set_maxpagesize
or bfd_emul_set_commonpagesize.
|
|
We need to set non_ir_ref_regular on the source for assignment to get
the correct LTO resolution:
190 a27be7f4ad90c5ce PREVAILING_DEF real_g
instead of
190 30c3b2d8f967f5ea PREVAILING_DEF_IRONLY real_g
PR ld/26163
* ldexp.c (exp_fold_tree_1): Set non_ir_ref_regular on the source
for assignment.
* testsuite/ld-plugin/lto.exp: Run ld/26163 test.
* testsuite/ld-plugin/pr26163a.c: New file.
* testsuite/ld-plugin/pr26163b.c: Likewise.
|
|
When converting between addresses in ELF headers [octets] and bfd
LMA/VMA [bytes], the number of octets per byte needs to be
incorporated.
In ld, the SIZEOF_HEADERS linker script statement must be resolved to
bytes instead of octets.
include/
* elf/internal.h (struct elf_internal_phdr): Add unit (octets)
to several member field comments.
(Elf_Internal_Shdr): likewise.
bfd/
* elf.c (_bfd_elf_make_section_from_shdr): Introduce new temp
opb. Divide Elf_Internal_Shdr::sh_addr by opb when setting
section LMA/VMA.
(_bfd_elf_make_section_from_phdr): Similarly.
(elf_fake_sections): Fix calculation of
Elf_Internal_shdr::sh_addr from section VMA.
(_bfd_elf_map_sections_to_segments): Fix mixup between octets
and bytes.
(assign_file_positions_for_load_sections): Fix calculations of
Elf_Internal_shdr::p_vaddr and p_paddr from section LMA/VMA. Fix
comparison between program header address and section LMA.
(assign_file_positions_for_non_load_sections): Likewise.
(rewrite_elf_program_header): Likewise. Introduce new temp opb.
(IS_CONTAINED_BY_VMA): Add parameter opb.
(IS_CONTAINED_BY_LMA,IS_SECTION_IN_INPUT_SEGMENT,
INCLUDE_SECTION_IN_SEGMENT): Likewise.
(copy_elf_program_header): Update call to ELF_SECTION_IN_SEGMENT.
Fix calculations of p_addr_valid and p_vaddr_offset.
* elflink.c (elf_link_add_object_symbols): Multiply section VMA
with octets per byte when comparing against p_vaddr.
ld/
* ldexp.c (fold_name): Return SIZEOF_HEADERS in bytes.
|
|
This reverts commit 91114f7583fac8fdf57c58a1f632839da62e43da.
|
|
PR 25570
* ldlang.c (lang_size_sections_1): Delay emitting non-fatal
errors/warnings until final pass.
* ldexp.c (fold_name): Likewise.
|
|
Until the symbol table is created, symbols can't be created.
* ldexp.c (fold_name): Don't print bfd_link_hash_lookup failed
in first phase.
|
|
|
|
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.
|
|
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.
|
|
Casts from a void* just clutter the source.
* ldexp.c (exp_intop, exp_bigintop, exp_relop, exp_binop, exp_trinop),
(exp_unop, exp_nameop, exp_assop, exp_assert): Remove casts of
stat_alloc return value.
* ldlang.c (new_statement, new_afile, sort_def_symbol),
(lang_memory_region_lookup, lang_memory_region_alias),
(ldlang_add_undef, ldlang_add_require_defined, insert_pad),
(lang_add_gc_name, lang_new_phdr): Likewise.
* lexsup.c (set_segment_start): Likewise.
|
|
MEMORY regions.
PR 24289
* ldexp.c (fold_name): Allow lookups of the LENGTH and ORIGIN
attributes during the first phase.
|
|
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.
|
|
|
|
This patch, along with previous patches in the series, supports
putting the ELF file header and program headers in a PT_LOAD without
sections.
Logic governing whether headers a loaded has changed a little: The
primary reason to include headers is now the presence of
SIZEOF_HEADERS in a linker script. However, to support scripts that
may have reserved space for headers by hand, we continue to add
headers whenever the first section address is past the end of headers
modulo page size.
include/
* bfdlink.h (struct bfd_link_info): Add load_phdrs field.
bfd/
* elf-nacl.c (nacl_modify_segment_map): Cope with header PT_LOAD
lacking sections.
* elf.c (_bfd_elf_map_sections_to_segments): Assume file and
program headers are required when info->load_phdrs. Reorganize
code handling program headers. Generate a mapping without
sections just for file and program headers when -z separate-code
would indicate they should be on a different page to the first
section.
ld/
* ldexp.c (fold_name <SIZEOF_HEADERS>): Set link_info.load_phdrs.
* testsuite/ld-elf/loadaddr1.d: Pass -z noseparate-code.
* testsuite/ld-elf/loadaddr2.d: Likewise.
* testsuite/ld-i386/vxworks2.sd: Adjust expected output.
* testsuite/ld-powerpc/vxworks2.sd: Likewise.
* testsuite/ld-elf/overlay.d: Remove spu xfail.
* testsuite/ld-spu/ovl.lnk: Don't use SIZEOF_HEADERS.
* testsuite/ld-tic6x/dsbt-be.ld: Likewise.
* testsuite/ld-tic6x/dsbt-inrange.ld: Likewise.
* testsuite/ld-tic6x/dsbt-overflow.ld: Likewise.
* testsuite/ld-tic6x/dsbt.ld: Likewise.
|
|
Fix an issue with the SEGMENT_START builtin function where its result is
absolute when taken from the default supplied, and section-relative when
taken from a `-T' command-line override. This is against documentation,
inconsistent and unexpected, and with PIE executables gives an incorrect
result with the `__executable_start' symbol.
Make the result of SEGMENT_START always section-relative then.
ld/
* ldexp.c (fold_binary): Always make the result of SEGMENT_START
section-relative.
* testsuite/ld-scripts/segment-start.d: New test.
* testsuite/ld-scripts/segment-start.ld: New test linker script.
* testsuite/ld-scripts/segment-start.s: New test source.
* testsuite/ld-scripts/script.exp: Run the new test.
|
|
Avoid a division by zero and thus a linker crash in SEGMENT_START script
builtin function handling, by not checking the value supplied with a
`-T' command-line override against the maximum page size if that has not
been set.
ld/
* ldexp.c (fold_binary): Check that `config.maxpagesize' is
non-zero before using it as a divisor.
|
|
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.
|
|
It is usually possible to tell absolute and ordinary symbols apart in
BFD throughout the link, by checking whether the section that owns the
symbol is absolute or not.
That however does not work for ordinary symbols defined in a linker
script outside an output section statement. Initially such symbols are
entered into to the link hash as absolute symbols, owned by the absolute
section. A flag is set in the internal linker expression defining such
symbols to tell the linker to convert them to section-relative ones in
the final phase of the link. That flag is however not accessible to BFD
linker code, including BFD target code in particular.
Add a flag to the link hash then to copy the information held in the
linker expression. Define a macro, `bfd_is_abs_symbol', for BFD code to
use where determining whether a symbol is absolute or ordinary is
required before the final link phase.
This macro will correctly identify the special `__ehdr_start' symbol as
ordinary throughout link, for example, even though early on it will be
assigned to the absolute section. Of course this does not let BFD code
identify what the symbol's ultimate section will be before the final
link phase has converted this symbol (in `update_definedness').
include/
* bfdlink.h (bfd_link_hash_entry): Add `rel_from_abs' member.
bfd/
* linker.c (bfd_is_abs_symbol): New macro.
* bfd-in2.h: Regenerate.
ld/
* ldexp.c (exp_fold_tree_1) <etree_assign, etree_provide>
<etree_provided>: Copy expression's `rel_from_abs' flag to the
link hash.
|
|
There should be no difference in output for symbols defined by HIDDEN
or PROVIDE_HIDDEN assignments whether they are explicitly marked as
hidden or not. This patch adds a new BFD function, bfd_link_hide_symbol,
to hide symbols defined by HIDDEN and PROVIDE_HIDDEN assignments.
bfd
PR ld/23201
* aout-target.h (MY_bfd_link_hide_symbol): New.
* aout-tic30.c (MY_bfd_link_hide_symbol): Likewise.
* binary.c (binary_bfd_link_hide_symbol): Likewise.
* coff-alpha.c (_bfd_ecoff_bfd_link_hide_symbol): Likewise.
* coff-mips.c (_bfd_ecoff_bfd_link_hide_symbol): Likewise.
* coff-rs6000.c (_bfd_xcoff_bfd_link_hide_symbol): Likewise.
* coffcode.h (coff_bfd_link_hide_symbol): Likewise.
* elf-bfd.h (_bfd_elf_link_hide_symbol): Likewise.
* elfxx-target.h (bfd_elfNN_bfd_link_hide_symbol): Likewise.
* i386msdos.c (msdos_bfd_link_hide_symbol): Likewise.
* ihex.c (ihex_bfd_link_hide_symbol): Likewise.
* libbfd-in.h (_bfd_nolink_bfd_link_hide_symbol): Likewise.
* linker.c (_bfd_generic_link_hide_symbol): Likewise.
(bfd_link_hide_symbol): Likewise.
* mach-o-target.c (bfd_mach_o_bfd_link_hide_symbol): Likewise.
* mmo.c (mmo_bfd_link_hide_symbol): Likewise.
* pef.c (bfd_pef_bfd_link_hide_symbol): Likewise.
* plugin.c (bfd_plugin_bfd_link_hide_symbol): Likewise.
* ppcboot.c (ppcboot_bfd_link_hide_symbol): Likewise.
* som.c (som_bfd_link_hide_symbol): Likewise.
* srec.c (srec_bfd_link_hide_symbol): Likewise.
* tekhex.c (tekhex_bfd_link_hide_symbol): Likewise.
* vms-alpha.c (vms_bfd_link_hide_symbol): Likewise.
(alpha_vms_bfd_link_hide_symbol): Likewise.
* xsym.c (bfd_sym_bfd_link_hide_symbol): Likewise.
* coff64-rs6000.c (rs6000_xcoff64_vec): Add
_bfd_generic_link_hide_symbol.
(rs6000_xcoff64_aix_vec): Likewise.
* elflink.c (bfd_elf_record_link_assignment): Don't make forced
local symbol dynamic.
(_bfd_elf_link_hide_symbol): New function.
* elfxx-x86.c (_bfd_x86_elf_link_symbol_references_local): Don't
check root.ldscript_def.
* targets.c (bfd_target): Add _bfd_link_hide_symbol.
(BFD_JUMP_TABLE_LINK): Add NAME##_bfd_link_hide_symbol.
* bfd-in2.h: Regenerated.
* libbfd.h: Likewise.
ld/
PR ld/23201
* ldexp.c (exp_fold_tree_1): Call bfd_link_hide_symbol to hide
a symbol.
* testsuite/ld-elf/provide-hidden-dynabs.nd: Removed.
* testsuite/ld-elf/provide-hidden-dynsec.nd: Likewise.
* testsuite/ld-elf/provide-hidden.exp: Replace
provide-hidden-dynsec.nd with provide-hidden-sec.nd and
provide-hidden-dyn.nd. Replace provide-hidden-dynabs.nd with
provide-hidden-abs.nd and provide-hidden-dyn.nd.
* testsuite/ld-i386/pr23189.d: Expect no dynamic relocation.
* testsuite/ld-x86-64/pr23189.d: Likewise.
|
|
This patch standardizes messages in ld, to better conform to the GNU
coding standard. Besides issues of capitalization and full-stops,
I've
- Split up help messages for target options, so that adding a new
option does not mean loss of translation for all the others.
- Embedded tabs have been removed, since a user might have tab stops
set at other than 8 char intervals.
- Added missing program name (%P). ld isn't the compiler.
- Put %F and %X first (and removed %X if %F was present). These can
go anywhere, but look silly in the m%Fiddle of a message, and
choosing "%P%F:" in some messages but "%F%P:" in others leads to the
likelihood of duplication in ld.pot. Besides, the colon belongs
with %P.
* emulparams/call_nop.sh, * emulparams/cet.sh,
* emulparams/elf32mcore.sh, * emultempl/aarch64elf.em
* emultempl/aix.em, * emultempl/alphaelf.em, * emultempl/armcoff.em,
* emultempl/armelf.em, * emultempl/avrelf.em, * emultempl/beos.em,
* emultempl/bfin.em, * emultempl/cr16elf.em, * emultempl/elf32.em,
* emultempl/elf-generic.em, * emultempl/hppaelf.em,
* emultempl/linux.em, * emultempl/lnk960.em,
* emultempl/m68hc1xelf.em, * emultempl/m68kcoff.em,
* emultempl/m68kelf.em, * emultempl/metagelf.em,
* emultempl/mipself.em, * emultempl/mmix-elfnmmo.em,
* emultempl/mmo.em, * emultempl/msp430.em, * emultempl/nds32elf.em,
* emultempl/nios2elf.em, * emultempl/pe.em, * emultempl/pep.em,
* emultempl/ppc32elf.em, * emultempl/ppc64elf.em,
* emultempl/scoreelf.em, * emultempl/sh64elf.em,
* emultempl/spuelf.em, * emultempl/sunos.em, * emultempl/tic6xdsbt.em,
* emultempl/ticoff.em, * emultempl/v850elf.em, * emultempl/vms.em,
* emultempl/vxworks.em, * emultempl/xtensaelf.em, * ldcref.c,
* ldctor.c, * ldexp.c, * ldfile.c, * ldgram.y, * ldlang.c,
* ldmain.c, * ldmisc.c, * ldwrite.c, * lexsup.c, * mri.c, * pe-dll.c,
* plugin.c: Standardize error/warning messages.
* testsuite/ld-arc/jli-overflow.err,
* testsuite/ld-arm/cmse-implib-errors.out,
* testsuite/ld-arm/cmse-new-earlier-later-implib.out,
* testsuite/ld-arm/cmse-new-implib-not-sg-in-implib.out,
* testsuite/ld-arm/cmse-new-wrong-implib.out,
* testsuite/ld-arm/cmse-veneers-no-gnu_sgstubs.out,
* testsuite/ld-arm/cmse-veneers-wrong-entryfct.out,
* testsuite/ld-arm/vxworks1-static.d,
* testsuite/ld-cris/tls-err-20x.d, * testsuite/ld-cris/tls-err-29.d,
* testsuite/ld-cris/tls-err-31.d, * testsuite/ld-cris/tls-err-33.d,
* testsuite/ld-cris/tls-err-35.d, * testsuite/ld-cris/tls-err-37.d,
* testsuite/ld-cris/tls-err-39.d, * testsuite/ld-cris/tls-err-41.d,
* testsuite/ld-cris/tls-err-43.d, * testsuite/ld-cris/tls-err-45.d,
* testsuite/ld-cris/tls-err-47.d, * testsuite/ld-cris/tls-err-49.d,
* testsuite/ld-cris/tls-err-51.d, * testsuite/ld-cris/tls-err-67.d,
* testsuite/ld-elf/dwarf2.err, * testsuite/ld-elf/dwarf3.err,
* testsuite/ld-elf/orphan-5.l, * testsuite/ld-elf/orphan-6.l,
* testsuite/ld-i386/vxworks1-static.d,
* testsuite/ld-mips-elf/bal-jalx-pic-micromips-n32.d,
* testsuite/ld-mips-elf/bal-jalx-pic-micromips-n64.d,
* testsuite/ld-mips-elf/bal-jalx-pic-micromips.d,
* testsuite/ld-mips-elf/bal-jalx-pic-n32.d,
* testsuite/ld-mips-elf/bal-jalx-pic-n64.d,
* testsuite/ld-mips-elf/bal-jalx-pic.d,
* testsuite/ld-mips-elf/jal-global-overflow-1.d,
* testsuite/ld-mips-elf/jal-local-overflow-1.d,
* testsuite/ld-mips-elf/mode-change-error-1.d,
* testsuite/ld-mips-elf/unaligned-branch-2.d,
* testsuite/ld-mips-elf/unaligned-branch-ignore-2.d,
* testsuite/ld-mips-elf/unaligned-branch-ignore-micromips.d,
* testsuite/ld-mips-elf/unaligned-branch-ignore-mips16.d,
* testsuite/ld-mips-elf/unaligned-branch-ignore-r6-1.d,
* testsuite/ld-mips-elf/unaligned-branch-micromips.d,
* testsuite/ld-mips-elf/unaligned-branch-mips16.d,
* testsuite/ld-mips-elf/unaligned-branch-r6-1.d,
* testsuite/ld-mips-elf/unaligned-branch-r6-2.d,
* testsuite/ld-mips-elf/unaligned-branch.d,
* testsuite/ld-mips-elf/unaligned-jalx-1.d,
* testsuite/ld-mips-elf/unaligned-jalx-3.d,
* testsuite/ld-mips-elf/unaligned-jalx-addend-1.d,
* testsuite/ld-mips-elf/unaligned-jalx-addend-3.d,
* testsuite/ld-mips-elf/unaligned-jalx-addend-micromips-1.d,
* testsuite/ld-mips-elf/unaligned-jalx-addend-mips16-1.d,
* testsuite/ld-mips-elf/unaligned-jalx-micromips-1.d,
* testsuite/ld-mips-elf/unaligned-jalx-mips16-1.d,
* testsuite/ld-mips-elf/unaligned-jump-micromips.d,
* testsuite/ld-mips-elf/unaligned-jump-mips16.d,
* testsuite/ld-mips-elf/unaligned-jump.d,
* testsuite/ld-mips-elf/unaligned-ldpc-1.d,
* testsuite/ld-mips-elf/unaligned-lwpc-1.d,
* testsuite/ld-mips-elf/undefined.d,
* testsuite/ld-mips-elf/vxworks1-static.d,
* testsuite/ld-mmix/bpo-20.d, * testsuite/ld-mmix/bpo-20m.d,
* testsuite/ld-mmix/bpo-7.d, * testsuite/ld-mmix/bpo-7m.d,
* testsuite/ld-mmix/bpo-8.d, * testsuite/ld-mmix/bpo-8m.d,
* testsuite/ld-mmix/greg-17.d, * testsuite/ld-mmix/greg-18.d,
* testsuite/ld-mmix/greg-8.d, * testsuite/ld-mmix/greg-9.d,
* testsuite/ld-plugin/plugin-14.d, * testsuite/ld-plugin/plugin-15.d,
* testsuite/ld-plugin/plugin-16.d, * testsuite/ld-plugin/plugin-20.d,
* testsuite/ld-plugin/plugin-21.d, * testsuite/ld-plugin/plugin-22.d,
* testsuite/ld-plugin/plugin-23.d, * testsuite/ld-plugin/plugin-6.d,
* testsuite/ld-plugin/plugin-7.d, * testsuite/ld-plugin/plugin-8.d,
* testsuite/ld-powerpc/aix-weak-3-32.d,
* testsuite/ld-powerpc/aix-weak-3-64.d,
* testsuite/ld-powerpc/vxworks1-static.d,
* testsuite/ld-sh/vxworks1-static.d,
* testsuite/ld-sparc/vxworks1-static.d,
* testsuite/ld-undefined/undefined.exp,
* testsuite/ld-x86-64/pie1.d: Update for changed errors and warnings.
* testsuite/ld-elf/warn1.d, * testsuite/ld-elf/warn2.d: Correct regex.
|
|
bfd/
* elf32-arm.c, * elf32-hppa.c, * elf32-lm32.c, * elf32-m32r.c,
* elf32-metag.c, * elf32-nds32.c, * elf32-or1k.c, * elf32-ppc.c,
* elf32-s390.c, * elf32-sh.c, * elf32-tic6x.c, * elf32-tilepro.c,
* elf64-ppc.c, * elf64-s390.c, * elflink.c, * elfnn-aarch64.c,
* elfnn-riscv.c, * elfxx-sparc.c, * elfxx-tilegx.c, * elfxx-x86.c,
* reloc.c: Replace use of %R and %T in format strings passed to
einfo and friends by %pR and %pT.
ld/
* ldmisc.c (vfinfo) Handle %pI, %pR, %pS and %pT in place of
%I, %R, %S and %T.
* ldcref.c, * ldctor.c, * ldemul.c, * ldexp.c, * ldgram.y,
* ldlang.c, * ldlex.l, * ldmain.c, * ldmisc.c, * pe-dll.c,
* emultempl/sh64elf.em: Replace use of of %I, %R, %S and %T in
format strings passed to einfo and friends by %pI, %pR, %pS and %pT.
|
|
First step towards compiler verification of _bfd_error_handler
arguments, and better verification of translated messages.
bfd/
* bfd.c (_bfd_doprnt, _bfd_doprnt_scan): Handle %pA and %pB in place
of %A and %B.
* aout-adobe.c: Update all messages using %A and %B.
* aout-cris.c: Likewise.
* aoutx.h: Likewise.
* archive.c: Likewise.
* binary.c: Likewise.
* cache.c: Likewise.
* coff-alpha.c: Likewise.
* coff-arm.c: Likewise.
* coff-i860.c: Likewise.
* coff-mcore.c: Likewise.
* coff-ppc.c: Likewise.
* coff-rs6000.c: Likewise.
* coff-sh.c: Likewise.
* coff-tic4x.c: Likewise.
* coff-tic54x.c: Likewise.
* coff-tic80.c: Likewise.
* coff64-rs6000.c: Likewise.
* coffcode.h: Likewise.
* coffgen.c: Likewise.
* cofflink.c: Likewise.
* coffswap.h: Likewise.
* compress.c: Likewise.
* cpu-arm.c: Likewise.
* ecoff.c: Likewise.
* elf-attrs.c: Likewise.
* elf-eh-frame.c: Likewise.
* elf-ifunc.c: Likewise.
* elf-m10300.c: Likewise.
* elf-properties.c: Likewise.
* elf-s390-common.c: Likewise.
* elf.c: Likewise.
* elf32-arc.c: Likewise.
* elf32-arm.c: Likewise.
* elf32-avr.c: Likewise.
* elf32-bfin.c: Likewise.
* elf32-cr16.c: Likewise.
* elf32-cr16c.c: Likewise.
* elf32-cris.c: Likewise.
* elf32-crx.c: Likewise.
* elf32-d10v.c: Likewise.
* elf32-d30v.c: Likewise.
* elf32-epiphany.c: Likewise.
* elf32-fr30.c: Likewise.
* elf32-frv.c: Likewise.
* elf32-gen.c: Likewise.
* elf32-hppa.c: Likewise.
* elf32-i370.c: Likewise.
* elf32-i386.c: Likewise.
* elf32-i960.c: Likewise.
* elf32-ip2k.c: Likewise.
* elf32-iq2000.c: Likewise.
* elf32-lm32.c: Likewise.
* elf32-m32c.c: Likewise.
* elf32-m32r.c: Likewise.
* elf32-m68hc11.c: Likewise.
* elf32-m68hc12.c: Likewise.
* elf32-m68hc1x.c: Likewise.
* elf32-m68k.c: Likewise.
* elf32-mcore.c: Likewise.
* elf32-mep.c: Likewise.
* elf32-metag.c: Likewise.
* elf32-microblaze.c: Likewise.
* elf32-moxie.c: Likewise.
* elf32-msp430.c: Likewise.
* elf32-mt.c: Likewise.
* elf32-nds32.c: Likewise.
* elf32-nios2.c: Likewise.
* elf32-or1k.c: Likewise.
* elf32-pj.c: Likewise.
* elf32-ppc.c: Likewise.
* elf32-rl78.c: Likewise.
* elf32-rx.c: Likewise.
* elf32-s390.c: Likewise.
* elf32-score.c: Likewise.
* elf32-score7.c: Likewise.
* elf32-sh-symbian.c: Likewise.
* elf32-sh.c: Likewise.
* elf32-sh64.c: Likewise.
* elf32-sparc.c: Likewise.
* elf32-spu.c: Likewise.
* elf32-tic6x.c: Likewise.
* elf32-tilepro.c: Likewise.
* elf32-v850.c: Likewise.
* elf32-vax.c: Likewise.
* elf32-visium.c: Likewise.
* elf32-wasm32.c: Likewise.
* elf32-xgate.c: Likewise.
* elf32-xtensa.c: Likewise.
* elf64-alpha.c: Likewise.
* elf64-gen.c: Likewise.
* elf64-hppa.c: Likewise.
* elf64-ia64-vms.c: Likewise.
* elf64-mmix.c: Likewise.
* elf64-ppc.c: Likewise.
* elf64-s390.c: Likewise.
* elf64-sh64.c: Likewise.
* elf64-sparc.c: Likewise.
* elf64-x86-64.c: Likewise.
* elfcode.h: Likewise.
* elfcore.h: Likewise.
* elflink.c: Likewise.
* elfnn-aarch64.c: Likewise.
* elfnn-ia64.c: Likewise.
* elfnn-riscv.c: Likewise.
* elfxx-mips.c: Likewise.
* elfxx-sparc.c: Likewise.
* elfxx-tilegx.c: Likewise.
* elfxx-x86.c: Likewise.
* hpux-core.c: Likewise.
* ieee.c: Likewise.
* ihex.c: Likewise.
* libbfd.c: Likewise.
* linker.c: Likewise.
* mach-o.c: Likewise.
* merge.c: Likewise.
* mmo.c: Likewise.
* oasys.c: Likewise.
* pdp11.c: Likewise.
* pe-mips.c: Likewise.
* peXXigen.c: Likewise.
* peicode.h: Likewise.
* reloc.c: Likewise.
* rs6000-core.c: Likewise.
* srec.c: Likewise.
* stabs.c: Likewise.
* vms-alpha.c: Likewise.
* xcofflink.c: Likewise.
ld/
* ldmisc.c (vfinfo): Handle %pA and %pB in place of %A and %B.
* ldcref.c: Update all messages using %A and %B.
* ldexp.c: Likewise.
* ldlang.c: Likewise.
* ldmain.c: Likewise.
* ldmisc.c: Likewise.
* pe-dll.c: Likewise.
* plugin.c: Likewise.
* emultempl/beos.em: Likewise.
* emultempl/cr16elf.em: Likewise.
* emultempl/elf32.em: Likewise.
* emultempl/m68kcoff.em: Likewise.
* emultempl/m68kelf.em: Likewise.
* emultempl/mmo.em: Likewise.
* emultempl/nds32elf.em: Likewise.
* emultempl/pe.em: Likewise.
* emultempl/pep.em: Likewise.
* emultempl/spuelf.em: Likewise.
* emultempl/sunos.em: Likewise.
* emultempl/xtensaelf.em: Likewise.
|
|
bfdI would like to fix instances of the following warning, when building
with clang with no special CFLAGS other than -g3 -O0.
/home/emaisin/src/binutils-gdb/bfd/elflink.c:5425:45: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
return (struct elf_link_hash_entry *) 0 - 1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
Replacing those with "(struct elf_link_hash_entry *) -1" gets rid of the
warning. I wanted to check that it didn't change the resulting code, so
I tried to build this:
$ cat test.c
int *before()
{
return (int *) 0 - 1;
}
int *after()
{
return (int *) - 1;
}
$ gcc -c test.c -g
$ objdump -d test.o
test.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <before>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 c7 c0 fc ff ff ff mov $0xfffffffffffffffc,%rax
b: 5d pop %rbp
c: c3 retq
000000000000000d <after>:
d: 55 push %rbp
e: 48 89 e5 mov %rsp,%rbp
11: 48 c7 c0 ff ff ff ff mov $0xffffffffffffffff,%rax
18: 5d pop %rbp
19: c3 retq
This shows that the previous code doesn't actually return -1 as the
function documentation says, but the new one does, so it's kind of a
bugfix.
bfd * elf64-ppc.c (ppc64_elf_archive_symbol_lookup): Avoid pointer
arithmetic on NULL pointer.
* elflink.c (_bfd_elf_archive_symbol_lookup,
elf_link_add_archive_symbols): Likewise.
ld * ldexp.c (fold_name, exp_fold_tree_1): Avoid pointer arithmetic
on NULL pointer.
|
|
Previous commit removed all uses of the defsym field within the linker
expression union. This commit cleans up the now redundant state.
ld/ChangeLog:
* ldexp.h (union etree_union): Remove defsym field.
* ldexp.c (exp_assop): Remove defsym parameter, and use of defsym
parameter.
(exp_assign): Remove passing of defsym parameter.
(exp_defsym): Likewise.
(exp_provide): Likewise.
|
|
In a linker script, a sequence like this:
foo = ADDR (.some_section);
bar = foo;
PROVIDE (foo = 0);
will result in 'bar = ADDR (.some_section)' and 'foo = 0', which seems
like incorrect behaviour, foo is clearly defined elsewhere, and so the
PROVIDE should not trigger.
The problem is that an expression like this:
foo = ADDR (.some_section);
can't be evaluated until a late phase of the linker, due to the need
for the section '.some_section' to have been placed, then the PROVIDE
was being marked as being used during an earlier phase. At the end of
the link, both lines:
foo = ADDR (.some_section);
PROVIDE (foo = 0);
are active, and this causes the final value of 'foo' to be 0.
The solution proposed in this commit is that, during earlier phases of
the linker, when we see the expression 'foo = ADDR (.some_section);',
instead of ignoring the expression, we create a "fake" definition of
'foo'. The existence of this "fake" definition prevents the PROVIDE
from being marked used, and during the final phase the real definition
of 'foo' will replace the "fake" definition.
The new test provide-6 covers the exact case described above. The
provide-7 test is similar to the above, but using constant
expressions, this was never broken, but is added here to increase
coverage.
The provide-8 case also didn't fail before this commit, but I did
manage to break this case during development of this patch. This case
was only covered by a mmix test before, so I've added this here to
increase coverage.
ld/ChangeLog:
* ldexp.c (exp_fold_tree_1): Rework condition underwhich provide
nodes are ignored in the tree walk, and move the location at which
we change provide nodes into provided nodes.
(exp_init_os): Add etree_provided.
* testsuite/ld-scripts/provide-6.d: New file.
* testsuite/ld-scripts/provide-6.t: New file.
* testsuite/ld-scripts/provide-7.d: New file.
* testsuite/ld-scripts/provide-7.t: New file.
* testsuite/ld-scripts/provide-8.d: New file.
* testsuite/ld-scripts/provide-8.t: New file.
|
|
Currently when recording a PROVIDE statement in a linker map file we
display something like:
PROVIDE (SYMBOL, VALUE)
However, in a linker script we write these statements like this:
PROVIDE (SYMBOL = VALUE);
This commit changes the output in the map file to be closer to linker
script format, the map file now contains:
PROVIDE (SYMBOL = VALUE)
The ';' is still missing from the end, but map files are not intended
to be valid linker script input, so adding the ';' just seems like
clutter.
ld/ChangeLog:
* ldexp.c (exp_print_tree): Use '=' instead of ',' when printing
PROVIDE statements.
* testsuite/ld-scripts/provide-4.map: Update expected output.
* testsuite/ld-scripts/provide-5.map: Likewise.
|
|
|
|
This patch processes linker script assignment statements before ld
opens DT_NEEDED libraries, in order to define symbols like __bss_start
that might also be defined by a library, falsely triggering an error
about "DSO missing from command line".
The initial value won't be correct when assigning a symbol from dot,
and I make no attempt to handle all expressions. For example, an
assignment like "_start_foo = ADDR (.foo)" isn't valid until sections
are laid out, so won't define _start_foo early. What's here should be
enough for most common scripts, and hopefully won't perturb fragile
scripts.
bfd/
PR 22471
* elflink.c (_bfd_elf_merge_symbol): Allow weak symbols to override
early passes over linker script symbols.
* linker.c (_bfd_generic_link_add_one_symbol): Allow symbols to
override early passes over linker script symbols. Clear ldscript_def
on symbol definitions.
ld/
PR 22471
* ldexp.c (struct definedness_hash_entry): Delete "by_script". Make
"iteration" an 8-bit field, and update mask in all uses.
(definedness_newfunc): Don't init "by_script".
(update_definedness): Test ldscript_def rather than by_script.
(is_sym_value): Likewise.
(fold_name <DEFINED>): Return a result for first phase. Test
ldscript_def.
(fold_name <NAME>): Return a result for first phase.
* ldlang.c (open_input_bfds): Process all assignments, not just
defsym.
(lang_process): Increment lang_statement_iteration before
open_input_bfds.
* testsuite/ld-mips-elf/tlsdyn-o32-1.d: Adjust for larger .dynsym.
* testsuite/ld-mips-elf/tlsdyn-o32-1.got: Likewise.
* testsuite/ld-mips-elf/tlsdyn-o32-2.d: Likewise.
* testsuite/ld-mips-elf/tlsdyn-o32-2.got: Likewise.
* testsuite/ld-mips-elf/tlsdyn-o32-3.d: Likewise.
* testsuite/ld-mips-elf/tlsdyn-o32-3.got: Likewise.
|
|
There is a call to update_definedness between code that evaluates an
assignment expression value and code that transfers symbol
attributes. When script assignment expressions contain DEFINED, that
can mean the wrong symbol type is copied. This patch tracks symbols
read during expression evaluation, rather than examining the
expression and re-evaluating conditionals. Not only does this
simplify the code, it also means ld can now copy symbol types in more
complex expressions.
An unfortunate side effect of copying symbol type for more complex
expressions affects mmix, which uses
PROVIDE (Main = DEFINED (Main) ? Main : (DEFINED (_start) ? _start : _start.));
in a default script. So now _start or _start. symbol type may be
copied, losing the function type specially set up for Main. This can
be avoided by making bfd_copy_link_hash_symbol_type do nothing for
mmix.
bfd/
* elf64-mmix.c (bfd_elf64_bfd_copy_link_hash_symbol_type): Define.
ld/
* ldexp.h (struct ldexp_control): Add "assign_src".
* ldexp.c (fold_trinary): Save and restore assign_src around
condition evaluation.
(fold_name <NAME>): Set expld.assign_src.
(try_copy_symbol_type): Delete.
(exp_fold_tree_1): Set symbol type using expld.assign_src.
|
|
Extract DATA_SEGMENT_END/DATA_SEGMENT_ALIGN/DATA_SEGMENT_RELRO_END cases
for GNU_RELRO segment into separate functions so that they can also be
used for text-only LOAD segment.
* ldexp.c (fold_unary): Extract the DATA_SEGMENT_END case to ...
(fold_segment_end): New function.
(fold_binary): Extract the DATA_SEGMENT_ALIGN case to ...
(fold_segment_align): New function.
(fold_binary): Extract the DATA_SEGMENT_RELRO_END case to ...
(fold_segment_relro_end): New function.
|
|
Update GNU_RELRO date type so that they can also be used for text-only
LOAD segment.
* ldexp.h (phase_enum): Rename exp_dataseg_none,
exp_dataseg_align_seen, exp_dataseg_relro_seen,
exp_dataseg_end_seen, exp_dataseg_relro_adjust,
exp_dataseg_adjust and exp_dataseg_done to exp_seg_none,
exp_seg_align_seen, exp_seg_relro_seen, exp_seg_end_seen,
exp_seg_relro_adjust, exp_seg_adjust and exp_seg_done.
(relro_enum): Rename exp_dataseg_relro_none,
exp_dataseg_relro_start and exp_dataseg_relro_end to
exp_seg_relro_none, exp_seg_relro_start and exp_seg_relro_end.
(seg_align_type): New struct type.
(ldexp_control): Use seg_align_type.
* ldexp.c (fold_unary): Updated.
(fold_binary): Likewise.
* ldlang.c (strip_excluded_output_sections): Likewise.
(lang_size_sections_1): Likewise.
(lang_size_sections): Likewise.
|
|
|
|
* ldexp.c (try_copy_symbol_type): Remove unnecessary check.
|
|
See https://sourceware.org/ml/binutils/2016-07/msg00091.html
This patch stop --gc-sections elf_gc_sweep_symbol localizing symbols
that ought to remain global.
The difficulty with always descending into output section statements
is that symbols defined by the script in such statements don't have
a bfd section when lang_do_assignments runs early in the link process.
There are two approaches to curing this problem. Either we can
create the bfd section early, or we can use a special section. This
patch takes the latter approach and uses bfd_und_section. (Creating
bfd sections early results in changed output section order, and thus
lots of testsuite failures. You can't create all output sections
early to ensure proper ordering as KEEP then stops empty sections
from being stripped.)
The wrinkle with this approach is that some code that runs at
gc-sections time needs to be made aware of the odd defined symbols
using bfd_und_section.
bfd/
* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Handle symbols
defined temporarily with bfd_und_section.
* elflink.c (_bfd_elf_gc_keep): Don't set SEC_KEEP for bfd_und_section.
* elfxx-mips.c (mips_elf_local_pic_function_p): Exclude defined
symbols with bfd_und_section.
ld/
* ldlang.c (lang_do_assignments_1): Descend into output section
statements that do not yet have bfd sections. Set symbol section
temporarily for symbols defined in such statements to the undefined
section. Don't error on data or reloc statements until final phase.
* ldexp.c (exp_fold_tree_1 <etree_assign>): Handle bfd_und_section
in expld.section.
* testsuite/ld-mmix/bpo-10.d: Adjust.
* testsuite/ld-mmix/bpo-11.d: Adjust.
|
|
* ldexp.c (MAX): Define.
(exp_unop, exp_binop, exp_trinop): Alloc at least enough for
etree_type.value.
|
|
Changes the result of ld expressions that were previously plain
numbers to be an absolute address, in the same circumstances where
numbers are treated as absolute addresses.
* ld.texinfo (Expression Section): Update result of arithmetic
expressions.
* ldexp.c (arith_result_section): New function.
(fold_binary): Use it.
|
|
Commit b751e639 regressed arm linux kernel builds, that have an
ASSERT (((__hyp_idmap_text_end - (__hyp_idmap_text_start
& ~ (((0x1 << 0xc) - 0x1))))
<= (0x1 << 0xc)), HYP init code too big or misaligned)
Due to some insanity in ld expression evaluation, the integer values
0x1 and 0xc above are treated as absolute addresses (ie. they have an
associated section, *ABS*, see exp_fold_tree_1 case etree_value) while
the expression (0x1 << 0xc) has a plain number result. The left hand
side of the inequality happens to evaluate to a "negative" .text
section relative value. Comparing a section relative value against an
absolute value works since the section relative value is first
converted to absolute. Comparing a section relative value against a
number just compares the offsets, which fails since the "negative"
offset is really a very large positive number.
This patch works around the problem by folding integer expressions, so
the assert again becomes
ASSERT (((__hyp_idmap_text_end - (__hyp_idmap_text_start
& 0xfffffffffffff000))
<= 0x1000), HYP init code too big or misaligned)
* ldexp.c (exp_value_fold): New function.
(exp_unop, exp_binop, exp_trinop): Use it.
|