Commit Graph

7279 Commits

Author SHA1 Message Date
Nick Clifton
96e786d198 Update version number and regenerate files 2022-12-31 12:23:00 +00:00
Nick Clifton
a72b07181d Add markers for 2.40 branch 2022-12-31 12:05:28 +00:00
Mark Harmstone
a667697f36 ld/testsuite: Don't add index to sizes in pdb.exp 2022-12-31 19:26:23 +10:30
Mark Harmstone
5c9e42e0e9 ld: Handle LF_VFTABLE types in PDBs 2022-12-31 19:26:23 +10:30
Mark Harmstone
fdf591c4c6 ld: Handle extended-length data structures in PDB types
A few fixes to minor issues I've discovered in my PDB patches.

* If sizes or offsets are greater than 0x8000, they get encoded as
extended values in the same way as for enum values - e.g. a LF_ULONG
.short followed by a .long.

* I've managed to coax MSVC to produce another type, LF_VFTABLE, which
is seen when dealing with COM. I don't think LLVM emits this. Note that
we can't just implement everything in Microsoft's header files, as most
of it is obsolete.

* Fixes a stupid bug in the test program, where I was adding an index to
a size. The index was hard-coded to 0, so this didn't cause any actual
issues.
2022-12-31 19:26:23 +10:30
H.J. Lu
9eb71a53bf x86-64: Allocate input section memory if needed
When --no-keep-memory is used, the input section memory may not be cached.
Allocate input section memory for -z pack-relative-relocs if needed.

bfd/

	PR ld/29939
	* elfxx-x86.c (elf_x86_size_or_finish_relative_reloc): Allocate
	input section memory if needed.

ld/

	PR ld/29939
	* testsuite/ld-elf/dt-relr-2i.d: New test.
2022-12-27 11:46:30 -08:00
Flavio Cruz
aac7ae599a Add support for x86_64-*-gnu-* targets to build x86_64 gnumach/hurd 2022-12-26 22:50:24 +10:30
Mark Harmstone
8d25f5ef2c ld: Write linker symbols in PDB 2022-12-23 21:10:09 +10:30
Mark Harmstone
5d9c033689 ld: Copy other symbols into PDB file 2022-12-23 21:02:21 +10:30
Mark Harmstone
81814b6f5b ld: Write globals stream in PDB 2022-12-23 20:54:40 +10:30
Mark Harmstone
817840046a ld: Parse LF_UDT_SRC_LINE records when creating PDB file 2022-12-23 20:45:30 +10:30
Mark Harmstone
fca9096a94 ld: Write types into IPI stream of PDB 2022-12-23 20:13:31 +10:30
Mark Harmstone
d5b4c0ddb9 ld: Write types into TPI stream of PDB 2022-12-23 20:05:48 +10:30
Mark Harmstone
598c1ae610 ld: Write DEBUG_S_LINES entries in PDB file 2022-12-23 19:57:56 +10:30
Mark Harmstone
8b182dc3c6 ld: Fix segfault in populate_publics_stream 2022-12-23 19:49:47 +10:30
Mark Harmstone
803561cb74 ld: Write DEBUG_S_FILECHKSMS entries in PDBs 2022-12-23 19:37:57 +10:30
Mark Harmstone
f559276dc5 ld: Generate PDB string table 2022-12-23 19:37:44 +10:30
Alan Modra
f27d07a1c2 pdb build fixes
Enable compilation of ld/pdb.c just for x86, as is done for bfd/pdb.c.
This reduces the size of ld and is necessary with the following
patches that call a COFF-only bfd function from ld/pdb.c.  Without it
we'd break every non-COFF target build.
2022-12-23 19:20:31 +10:30
Alan Modra
160a943ff8 COFF build-id writes uninitialised data to file
1) The first write in write_build_id wrote rubbish past the struct
external_IMAGE_DEBUG_DIRECTORY, which was later overwritten with
correct data.  No user visible problem there, except that tools like
valgrind complain.
2) The size for the pdb name was incorrectly calculated.

	* emultempl/pe.em (write_build_id): Write the debug directory,
	not the entire section contents.
	(setup_build_id): Add size for the base name of pdb_name, not
	the full path.
	* emultempl/pep.em: Likewise.
	* testsuite/ld-pe/pdb2-section-contrib.d: Update.
2022-12-23 10:35:38 +10:30
Nick Clifton
a7a32d588f Keep the .drectve section when performing a relocateable link.
PR 29900
	* scripttempl/pe.sc: Keep the .drectve section when performing a
	relocateable link.
	* scripttempl/pep.sc: Likewise.
2022-12-21 10:23:08 +00:00
Alan Modra
c63d486281 enable-non-contiguous-regions warnings
The warning about discarded sections in elf_link_input_bfd doesn't
belong there since the code is dealing with symbols.  Multiple symbols
in a discarded section will result in multiple identical warnings
about the section.  Move the warning to a new function in ldlang.c.

The patch also tidies the warning quoting of section and file names,
consistently using `%pA' and `%pB'.  I'm no stickler for one style of
section and file name quoting, but they ought to be consistent within
a warning, eg. see the first one fixed in ldlang.c, and when a warning
is emitted for multiple targets they all ought to use exactly the same
format string to reduce translation work.  elf64-ppc.c loses the
build_one_stub errors since we won't get there before hitting the
fatal errors in size_one_stub.

bfd/
	* elflink.c (elf_link_input_bfd): Don't warn here about
	discarded sections.
	* elf32-arm.c (arm_build_one_stub): Use consistent style in
	--enable-non-contiguous-regions error.
	* elf32-csky.c (csky_build_one_stub): Likewise.
	* elf32-hppa.c (hppa_build_one_stub): Likewise.
	* elf32-m68hc11.c (m68hc11_elf_build_one_stub): Likewise.
	* elf32-m68hc12.c (m68hc12_elf_build_one_stub): Likewise.
	* elf32-metag.c (metag_build_one_stub): Likewise.
	* elf32-nios2.c (nios2_build_one_stub): Likewise.
	* elfnn-aarch64.c (aarch64_build_one_stub): Likewise.
	* xcofflink.c (xcoff_build_one_stub): Likewise.
	* elf64-ppc.c (ppc_size_one_stub): Likewise.
	(ppc_build_one_stub): Delete dead code.
ld/
	* ldlang.c (lang_add_section): Use consistent style in
	--enable-non-contiguous-regions warnings.
	(size_input_section): Likewise.
	(warn_non_contiguous_discards): New function.
	(lang_process): Call it.
	* testsuite/ld-arm/non-contiguous-arm.d: Update.
	* testsuite/ld-arm/non-contiguous-arm4.d: Update.
	* testsuite/ld-arm/non-contiguous-arm7.d: Add
	--enable-non-contiguous-regions-warnings.
	* testsuite/ld-arm/non-contiguous-arm7.err: New.
	* testsuite/ld-powerpc/non-contiguous-powerpc.d: Update.
	* testsuite/ld-powerpc/non-contiguous-powerpc64.d: Update.
2022-12-21 17:56:27 +10:30
Torbjörn SVENSSON
106791196f bfd: Discard symbol regardless of warning flag
The discard of symbols should be performed whether the warning for
the discard is enabled or not.
Without this patch, ld would segfault in bfd_section_removed_from_list,
called in the if-statement right after this block, as the argument
isec->output_section can be NULL.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
2022-12-20 11:37:22 +01:00
Alan Modra
3bbdb440d0 ld bootstrap test in build dir with path containing symlinks
This allows the bootstrap test to run if you have a symlink somewhere
in the build path directory.  $ld depends on $base_dir which is set
via tcl [pwd], collapsing the symlink like /usr/bin/pwd, while $objdir
contains the symlink.

	* testsuite/ld-bootstrap/bootstrap.exp: Normalize paths when
	checking for ld build directory.
2022-12-18 19:11:32 +10:30
Alan Modra
d1da8dd5bd Fix haiku ld dependencies
I noticed after commit 8ad93045ed, "ld, gold: remove support for -z
bndplt (MPX prefix)", that some of my builds were failing with

eelf_x86_64_haiku.c:650:9: error: no member named 'bndplt' in 'struct elf_linker_x86_params'
        params.bndplt = true;
        ~~~~~~ ^

	* emulparams/aarch64haiku.sh: Use "source_sh" rather than ".".
	* emulparams/armelf_haiku.sh: Likewise.
	* emulparams/elf32ppchaiku.sh: Likewise.
	* emulparams/elf_mipsel_haiku.sh: Likewise.
	* emulparams/elf_x86_64_haiku.sh: Likewise.
2022-12-14 21:45:04 +10:30
Martin Liska
8ad93045ed ld, gold: remove support for -z bndplt (MPX prefix)
bfd/ChangeLog:

	* elf-linker-x86.h (struct elf_linker_x86_params): Remove
	bndplt.
	* elf64-x86-64.c (elf_x86_64_scan_relocs): Ignore
        R_X86_64_PLT32_BND.
	(elf_x86_64_relocate_section): Similarly here.
	(elf_x86_64_link_setup_gnu_properties): Ignore bndplt.
	* elfxx-x86.c: Likewise.
	* elfxx-x86.h: Likewise.

gold/ChangeLog:

	* NEWS: Document -z bndplt.
	* options.h (class General_options): Remove bndplt option.
	* x86_64.cc (class Output_data_plt_x86_64_bnd): Remove.
	(Target_x86_64::do_make_data_plt): Do not use
	Output_data_plt_x86_64_bnd.
	(Target_x86_64::Scan::get_reference_flags): Likewise.
	(Target_x86_64::Scan::check_non_pic): Likewise.
	(Target_x86_64::Scan::local): Likewise.
	(Target_x86_64::Scan::global): Likewise.

ld/ChangeLog:

	* NEWS: Document -z bndplt.
	* emulparams/elf_x86_64.sh: Remove bndplt option.
	* ld.texi: Likewise.
	* testsuite/ld-x86-64/x86-64.exp:
	* testsuite/ld-x86-64/bnd-branch-1-now.d: Removed.
	* testsuite/ld-x86-64/bnd-branch-1.d: Removed.
	* testsuite/ld-x86-64/bnd-branch-1.s: Removed.
	* testsuite/ld-x86-64/bnd-ifunc-1-now.d: Removed.
	* testsuite/ld-x86-64/bnd-ifunc-1.d: Removed.
	* testsuite/ld-x86-64/bnd-ifunc-1.s: Removed.
	* testsuite/ld-x86-64/bnd-ifunc-2-now.d: Removed.
	* testsuite/ld-x86-64/bnd-ifunc-2.d: Removed.
	* testsuite/ld-x86-64/bnd-ifunc-2.s: Removed.
	* testsuite/ld-x86-64/bnd-plt-1-now.d: Removed.
	* testsuite/ld-x86-64/bnd-plt-1.d: Removed.
	* testsuite/ld-x86-64/mpx.exp: Removed.
	* testsuite/ld-x86-64/mpx1.out: Removed.
	* testsuite/ld-x86-64/mpx1a.c: Removed.
	* testsuite/ld-x86-64/mpx1a.rd: Removed.
	* testsuite/ld-x86-64/mpx1b.c: Removed.
	* testsuite/ld-x86-64/mpx1c.c: Removed.
	* testsuite/ld-x86-64/mpx1c.rd: Removed.
	* testsuite/ld-x86-64/mpx2.out: Removed.
	* testsuite/ld-x86-64/mpx2a.c: Removed.
	* testsuite/ld-x86-64/mpx2a.rd: Removed.
	* testsuite/ld-x86-64/mpx2b.c: Removed.
	* testsuite/ld-x86-64/mpx2c.c: Removed.
	* testsuite/ld-x86-64/mpx2c.rd: Removed.
	* testsuite/ld-x86-64/mpx3.dd: Removed.
	* testsuite/ld-x86-64/mpx3a.s: Removed.
	* testsuite/ld-x86-64/mpx3b.s: Removed.
	* testsuite/ld-x86-64/mpx3n.dd: Removed.
	* testsuite/ld-x86-64/mpx4.dd: Removed.
	* testsuite/ld-x86-64/mpx4a.s: Removed.
	* testsuite/ld-x86-64/mpx4b.s: Removed.
	* testsuite/ld-x86-64/mpx4n.dd: Removed.
	* testsuite/ld-x86-64/pr20800a.S: Removed.
	* testsuite/ld-x86-64/pr20800b.S: Removed.
	* testsuite/ld-x86-64/pr21038a-now.d: Removed.
	* testsuite/ld-x86-64/pr21038a.d: Removed.
	* testsuite/ld-x86-64/pr21038a.s: Removed.
	* testsuite/ld-x86-64/pr21038b-now.d: Removed.
	* testsuite/ld-x86-64/pr21038b.d: Removed.
	* testsuite/ld-x86-64/pr21038b.s: Removed.
	* testsuite/ld-x86-64/pr21038c-now.d: Removed.
	* testsuite/ld-x86-64/pr21038c.d: Removed.
	* testsuite/ld-x86-64/pr21038c.s: Removed.
2022-12-14 08:48:13 +01:00
H.J. Lu
e9c11d58b9 x86-64: Remove BND from 64-bit IBT PLT
Since MPX support has been removed from x86-64 psABI, remove BND from
64-bit IBT PLT by using x32 IBT PLT.

bfd/

	PR ld/29851
	* elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Also check
	x32 IBT PLT for 64-bit.
	(elf_x86_64_link_setup_gnu_properties): Always use x32 IBT PLT.

ld/

	PR ld/29851
	* testsuite/ld-x86-64/ibt-plt-1.d: Updated.
	* testsuite/ld-x86-64/ibt-plt-2a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2b.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-2d.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3a.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3b.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3c.d: Likewise.
	* testsuite/ld-x86-64/ibt-plt-3d.d: Likewise.
	* testsuite/ld-x86-64/plt-main-ibt-x32.dd: Moved to ...
	* testsuite/ld-x86-64/plt-main-ibt.dd: This.
	* testsuite/ld-x86-64/x86-64.exp: Don't use plt-main-ibt-x32.dd.
2022-12-08 08:05:45 -08:00
Nick Clifton
dcb53d93eb Update the description of the linker script's TYPE directive.
PR 29861
	* ld.texi (Output Section Type): Note that setting the output
	section type only works if the section contains untyped data.
2022-12-08 13:06:31 +00:00
Alan Modra
c3620d6d56 Compression tidy and fixes
Tidies:
- Move stuff from bfd-in.h and libbfd.c to compress.c
- Delete COMPRESS_DEBUG from enum compressed_debug_section_type
- Move compress_debug field out of link_info to ld_config.
Fixes:
- Correct test in bfd_convert_section_setup to use obfd flags,
  not ibfd.
- Apply bfd_applicable_file_flags to compression bfd flags added
  by gas and ld to the output bfd.

bfd/
	* bfd-in.h (enum compressed_debug_section_type),
	(struct compressed_type_tuple),
	(bfd_get_compression_algorithm),
	(bfd_get_compression_algorithm_name),
	* libbfd.c (compressed_debug_section_names),
	(bfd_get_compression_algorithm),
	(bfd_get_compression_algorithm_name): Move..
	* compress.c: ..to here, deleting COMPRESS_DEBUG from
	enum compressed_debug_section_type.
	(bfd_convert_section_setup): Test obfd flags not ibfd for
	compression flags.
	* elf.c (elf_fake_sections): Replace link_info->compress_debug
	test with abfd->flags test.
	* bfd-in2.h: Regenerate.
binutils/
	* objcopy.c (copy_file): Tidy setting of bfd compress flags.
	Expand comment.
gas/
	* write.c (compress_debug): Test bfd compress flags rather than
	flag_compress_debug.
	(write_object_file): Apply bfd_applicable_file_flags to compress
	debug flags added to output bfd.
include/
	* bfdlink.h (struct bfd_link_info): Delete compress_debug.
ld/
	* ld.h (ld_config_type): Add compress_debug.
	* emultempl/elf.em: Replace references to link_info.compress_debug
	with config.compress_debug.
	* lexsup.c (elf_static_list_options): Likewise.
	* ldmain.c (main): Likewise.  Apply bfd_applicable_file_flags
	to compress debug flags added to output bfd.
2022-12-07 13:15:29 +10:30
Nick Clifton
3bf5bf547a Prevent an illegal memory access when comparing the prefix of a section name regexp.
PR 29849
	* ldlang.c (spec_match): Check that there is sufficient length in
	the target name to match the spec's prefix.
2022-12-05 14:57:17 +00:00
H.J. Lu
fb699bafb5 Revert "ld: Add .note.GNU-stack to ld-plugin/dummy.s"
This reverts commit 44e59b5a7d.

It works only for ELF targets.
2022-12-03 10:43:29 -08:00
H.J. Lu
44e59b5a7d ld: Add .note.GNU-stack to ld-plugin/dummy.s
* testsuite/ld-plugin/dummy.s: Add .note.GNU-stack.
2022-12-03 09:41:31 -08:00
Michael Matz
885d86436c section-select: Fix exclude-file-3
this testcase wasn't correctly testing everything, it passed, even
though sections from an excluded file were included.  Fixing this
reveals a problem in the new section selector.  This fixes that as
well.
2022-11-30 17:15:08 +01:00
Michael Matz
d779149912 section-select: Remove unused code
walk_wild_file, hence walk_wild_section and walk_wild_section_handler
aren't called with the prefix tree.  Hence initialization of the latter
and all potential special cases for it aren't used anymore.  That also
removes the need to handler_data[] and some associated helper functions.
So, remove all of that.
2022-11-30 17:15:08 +01:00
Michael Matz
b1eecf6f66 section-select: Implement a prefix-tree
Now that we have a list of potentially matching sections per wild
statement we can actually pre-fill that one by going once over all input
sections and match their names against a prefix-tree that points to the
potentially matching wild statements.

So instead of looking at all sections names for each glob for each wild
statement we now look at the sections only once and then only check
against those globs that have a possibility of a match at all (usually
only one or two).

This pushes the whole section selection off the profiles.
2022-11-30 17:15:08 +01:00
Michael Matz
50be5d1128 section-select: Completely rebuild matches
The check_relocs callback (and others) might have created new
section behind our back and some of them (e.g. on powerpc the
"linker stubs" .got) need to come in front of all others, despite
being created late (a symptom would be "TOC opt*" failing on powerpc).

This resets all section matches before updating for newly created
sections (i.e. completely rebuilds the matches).
2022-11-30 17:15:08 +01:00
Michael Matz
43ae96e94a section-select: Lazily resolve section matches
and remember the results.  Before this the order of section matching
is basically:

  foreach script-wild-stmt S
    foreach pattern P of S
      foreach inputfile I
        foreach section S of I
	  match S against P
	    if match: do action for S

And this process is done three or four times: for each top-level call to
walk_wild() or wild(), that is: check_input_sections, lang_gc_sections,
lang_find_relro_sections and of course map_input_to_output_sections.

So we iterate over all sections of all files many many times (for each
glob).  Reality is a bit more complicated (some special glob types don't
need the full iteration over all sections, only over all files), but
that's the gist of it.

For future work this shuffles the whole ordering a bit by lazily doing
the matching process and memoizing results, trading a little memory for
a 75% speedup of the overall section selection process.

This lazy resolution introduces a problem with sections added late
that's corrected in the next patch.
2022-11-30 17:15:07 +01:00
Alan Modra
6bd454ca03 Correct ordering problem in comm-data.exp
* testsuite/ld-elf/comm-data.exp: Build libcomm-data.so before
	attempting to read it to set ELF64.
2022-11-30 18:41:40 +10:30
Max Filippov
d0a2cfbd31 xtensa: allow dynamic configuration
Import include/xtensa-dynconfig.h that defines XCHAL_* macros as fields
of a structure returned from the xtensa_get_config_v<x> function call.
Define that structure and fill it with default parameter values
specified in the include/xtensa-config.h.
Define reusable function xtensa_load_config that tries to load
configuration and return an address of an exported object from it.
Define functions xtensa_get_config_v{1,2} that use xtensa_load_config
to get structures xtensa_config_v{1,2}, either dynamically configured
or the default.

bfd/
	* Makefile.am (BFD32_BACKENDS, BFD32_BACKENDS_CFILES): Append
	xtensa-dynconfig.c.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* configure.ac (xtensa_elf32_be_vec, xtensa_elf32_le_vec): Add
	xtensa-dynconfig.lo to the tb.
	* elf32-xtensa.c (xtensa-config.h): Replace #include with
	xtensa-dynconfig.h.
	(XSHAL_ABI, XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0): Remove
	definitions.
	* xtensa-dynconfig.c: New file.
	* xtensa-isa.c (xtensa-dynconfig.h): New #include.
	(xtensa_get_modules): New function.
	(xtensa_isa_init): Call xtensa_get_modules instead of taking
	address of global xtensa_modules.

gas/
	* config/tc-xtensa.c (xtensa-config.h): Replace #include with
	xtensa-dynconfig.h.
	(XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0, XTENSA_MARCH_EARLIEST):
	Remove definitions.
	* config/tc-xtensa.h (xtensa-config.h): Replace #include with
	xtensa-dynconfig.h.
	* config/xtensa-relax.c (xtensa-config.h): Replace #include with
	xtensa-dynconfig.h.
	(XCHAL_HAVE_WIDE_BRANCHES): Remove definition.

include/
	* xtensa-dynconfig.h: New file.

ld/
	* emultempl/xtensaelf.em (xtensa-config.h): Replace #include
	with xtensa-dynconfig.h.
	(XTHAL_ABI_WINDOWED, XTHAL_ABI_CALL0): Remove definitions.
2022-11-28 18:16:12 -08:00
Michael Matz
af31506c31 Only use wild_sort_fast
there's no reason why the tree-based variant can't always be used
when sorting is required, it merely needs to also support filename
sorting and have a fast path for insertion at end (aka rightmost tree
leaf).

The filename sorting isn't tested anywhere and the only scripttempl
that uses it is avr (for 'SORT(*)(.ctors)'), and I believe even there it
was a mistake.  Either way, this adds a testcase for filename sorting as
well.

Then the non-BST based sorting can be simplified to only support
the fast case of no sorting required at all (at the same time renaming
the two variants to _sort and _nosort).
2022-11-28 16:30:18 +01:00
Michael Matz
049522cae9 Special case more simple patterns
fnmatch is slow, so avoiding it in more cases is good.  This implements
a more generic version of match_simple_wild which needs some
pre-processing of patterns.  In particular it supports patterns of the
form PREFIX*SUFFIX (where all parts are optional), i.e. a super set of
what's handled now.  Most section matchers of this form and hence don't
need any calls to fnmatch anymore.

We retain the implementation of match_simple_wild for the filename
matchers (they aren't called often enough to matter).
2022-11-28 16:30:08 +01:00
Alan Modra
e7d942e014 Use bfd_rename_section in msp430.em
* emultempl/msp430.em (add_region_prefix <REGION_EITHER>): Use
	bfd_rename_section.
	* testsuite/ld-msp430-elf/msp430-tiny-rom.ld: Handle varian data
	and bss input sections.
2022-11-28 17:29:11 +10:30
Mark Harmstone
e2a1b0a0d1 ld: Add section contributions substream to PDB files 2022-11-23 01:13:35 +00:00
H.J. Lu
04ad71937f x86: Don't define _TLS_MODULE_BASE_ for ld -r
bfd/

	PR ld/29820
	* elfxx-x86.c (_bfd_x86_elf_always_size_sections): Don't define
	 _TLS_MODULE_BASE_ for ld -r.

ld/

	PR ld/29820
	* testsuite/ld-x86-64/pr29820.d: New file.
	* testsuite/ld-x86-64/pr29820.s: Likewise.
	* testsuite/ld-x86-64/x86-64.ex: Run pr29820.
2022-11-22 14:03:16 -08:00
H.J. Lu
25d17459e3 ld: Always call elf_backend_output_arch_local_syms
Always call elf_backend_output_arch_local_syms since only the backend
knows if elf_backend_output_arch_local_syms is needed when all symbols
are striped.  elf_backend_output_arch_local_syms is defined only for
x86, ARM and AARCH64.  On x86, elf_backend_output_arch_local_syms must
be called to handle local IFUNC symbols even if all symbols are striped.
Update ARM and AARCH64 to skip elf_backend_output_arch_local_syms when
symbols aren't needed.

bfd/

	PR ld/29797
	* elf32-arm.c (elf32_arm_output_arch_local_syms): Skip if symbols
	aren't needed.
	* elfnn-aarch64.c (elfNN_aarch64_output_arch_local_syms):
	Likewise.
	* elflink.c (bfd_elf_final_link): Always call
	elf_backend_output_arch_local_syms if available.

ld/

	PR ld/29797
	* testsuite/ld-elf/linux-x86.exp: Run PR ld/29797 test.
	* testsuite/ld-elf/pr29797.c: New file.
2022-11-17 08:13:37 -08:00
Indu Bhagat
cf0e0a0ba9 bfd: linker: merge .sframe sections
The linker merges all the input .sframe sections.  When merging, the
linker verifies that all the input .sframe sections have the same
abi/arch.

The linker uses libsframe library to perform key actions on the
.sframe sections - decode, read, and create output data.  This
implies buildsystem changes to make and install libsframe before
libbfd.

The linker places the output .sframe section in a new segment of its
own: PT_GNU_SFRAME.  A new segment is not added, however, if the
generated .sframe section is empty.

When a section is discarded from the final link, the corresponding
entries in the .sframe section for those functions are also deleted.

The linker sorts the SFrame FDEs on start address by default and sets
the SFRAME_F_FDE_SORTED flag in the .sframe section.

This patch also adds support for generation of SFrame unwind
information for the .plt* sections on x86_64.  SFrame unwind info is
generated for IBT enabled PLT, lazy/non-lazy PLT.

The existing linker option --no-ld-generated-unwind-info has been
adapted to include the control of whether .sframe unwind information
will be generated for the linker generated sections like PLT.

Changes to the linker script have been made as necessary.

ChangeLog:

	* Makefile.def: Add install dependency on libsframe for libbfd.
	* Makefile.in: Regenerated.
	* bfd/Makefile.am: Add elf-sframe.c
	* bfd/Makefile.in: Regenerated.
	* bfd/bfd-in2.h (SEC_INFO_TYPE_SFRAME): Regenerated.
	* bfd/configure: Regenerate.
	* bfd/configure.ac: Add elf-sframe.lo.
	* bfd/elf-bfd.h (struct sframe_func_bfdinfo): New struct.
	(struct sframe_dec_info): Likewise.
	(struct sframe_enc_info): Likewise.
	(struct elf_link_hash_table): New member for encoded .sframe
	object.
	(struct output_elf_obj_tdata): New member.
	(elf_sframe): New access macro.
	(_bfd_elf_set_section_sframe): New declaration.
	* bfd/elf.c (get_segment_type): Handle new segment
	PT_GNU_SFRAME.
	(bfd_section_from_phdr): Likewise.
	(get_program_header_size): Likewise.
	(_bfd_elf_map_sections_to_segments): Likewise.
	* bfd/elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Add
	contents to the .sframe sections or .plt* entries.
	* bfd/elflink.c (elf_section_ignore_discarded_relocs): Handle
	SEC_INFO_TYPE_SFRAME.
	(_bfd_elf_default_action_discarded): Handle .sframe section.
	(elf_link_input_bfd): Merge .sframe section.
	(bfd_elf_final_link): Write the output .sframe section.
	(bfd_elf_discard_info): Handle discarding .sframe section.
	* bfd/elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Create
	.sframe section for .plt and .plt.sec.
	(_bfd_x86_elf_finish_dynamic_sections): Handle .sframe from
	.plt* sections.
	* bfd/elfxx-x86.h (PLT_SFRAME_FDE_START_OFFSET): New
	definition.
	(SFRAME_PLT0_MAX_NUM_FRES): Likewise.
	(SFRAME_PLTN_MAX_NUM_FRES): Likewise.
	(struct elf_x86_sframe_plt): New structure.
	(struct elf_x86_link_hash_table): New member.
	(struct elf_x86_init_table): New members for .sframe
	creation.
	* bfd/section.c: Add new definition SEC_INFO_TYPE_SFRAME.
	* binutils/readelf.c (get_segment_type): Handle new segment
	PT_GNU_SFRAME.
	* ld/ld.texi: Update documentation for
	--no-ld-generated-unwind-info.
	* ld/scripttempl/elf.sc: Support .sframe sections.
	* ld/Makefile.am (TESTSFRAMELIB): Use it.
	(check-DEJAGNU): Likewise.
	* ld/Makefile.in: Regenerated.
	* ld/configure.ac (TESTSFRAMELIB): Set to the .so or .a like TESTBFDLIB.
	* ld/configure: Regenerated.
	* bfd/elf-sframe.c: New file.

include/ChangeLog:

	* elf/common.h (PT_GNU_SFRAME): New definition.
	* elf/internal.h (struct elf_segment_map): Handle new segment
	type PT_GNU_SFRAME.

ld/testsuite/ChangeLog:

	* ld/testsuite/ld-bootstrap/bootstrap.exp: Add SFRAMELIB.
	* ld/testsuite/ld-aarch64/aarch64-elf.exp: Add new test
	  sframe-simple-1.
	* ld/testsuite/ld-aarch64/sframe-bar.s: New file.
	* ld/testsuite/ld-aarch64/sframe-foo.s: Likewise.
	* ld/testsuite/ld-aarch64/sframe-simple-1.d: Likewise.
	* ld/testsuite/ld-sframe/sframe-empty.d: New test.
	* ld/testsuite/ld-sframe/sframe-empty.s: New file.
	* ld/testsuite/ld-sframe/sframe.exp: New testsuite.
	* ld/testsuite/ld-x86-64/sframe-bar.s: New file.
	* ld/testsuite/ld-x86-64/sframe-foo.s: Likewise.
	* ld/testsuite/ld-x86-64/sframe-simple-1.d: Likewise.
	* ld/testsuite/ld-x86-64/sframe-plt-1.d: Likewise.
	* ld/testsuite/ld-x86-64/sframe-simple-1.d: Likewise.
	* ld/testsuite/ld-x86-64/x86-64.exp: Add new tests -
	  sframe-simple-1, sframe-plt-1.
	* ld/testsuite/lib/ld-lib.exp: Add new proc to check if
	  assembler supports SFrame section.
	* ld/testsuite/ld-sframe/discard.d: New file.
	* ld/testsuite/ld-sframe/discard.ld: Likewise.
	* ld/testsuite/ld-sframe/discard.s: Likewise.
2022-11-15 15:49:47 -08:00
Dimitar Dimitrov
36f779c063 pru: bfd: Correct default to no execstack
Data and instruction memories are strictly separated, so it is not
possible to execute instructions from the stack memory on PRU.

I don't see any difference in testsuite results with or without this
change.

bfd/ChangeLog:

	* elf32-pru.c (elf_backend_default_execstack): Define as 0.

ld/ChangeLog:

	* testsuite/ld-elf/elf.exp (target_defaults_to_execstack):
	Return 0 for pru.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2022-11-14 17:42:22 +02:00
Clément Chigot
1b377e4960 ld/testsuite: skip ld-size when -shared is not supported
ld/ChangeLog:

        * testsuite/ld-size/size.exp: Skip when -shared is not
	supported.
2022-11-10 13:19:15 +01:00
Mark Harmstone
5967ca921c ld: Add module information substream to PDB files 2022-11-10 04:50:43 +00:00
Christophe Lyon
200164d467 configure: require libzstd >= 1.4.0
gas uses ZSTD_compressStream2 which is only available with libzstd >=
1.4.0, leading to build errors when an older version is installed.

This patch updates the check libzstd presence to check its version is
>= 1.4.0. However, since gas seems to be the only component requiring
such a recent version this may imply that we disable ZSTD support for
all components although some would still benefit from an older
version.

I ran 'autoreconf -f' in all directories containing a configure.ac
file, using vanilla autoconf-2.69 and automake-1.15.1. I noticed
several errors from autoheader in readline, as well as warnings in
intl, but they are unrelated to this patch.

This should fix some of the buildbots.

OK for trunk?

Thanks,

Christophe
2022-11-07 14:32:10 +01:00
Clément Chigot
8bfb6941c3 ld/testsuite: skip tests related to -shared when disabled
Call the helper function "check_shared_lib_support" to ensure -shared
is enabled before launching ld-shared, ld-elfweak and ld-elfvers.
This allows to catch custom targets explicitly disabling it.

ld/ChangeLog:

	* testsuite/ld-elfvers/vers.exp: Call check_shared_lib_support.
	* testsuite/ld-elfweak/elfweak.exp: Likewise.
	* testsuite/ld-shared/shared.exp: Likewise.
2022-11-07 13:16:41 +01:00