2
0
mirror of https://sourceware.org/git/binutils-gdb.git synced 2024-12-09 04:21:49 +08:00
Commit Graph

113 Commits

Author SHA1 Message Date
Kaylee Blake
96cc7918c1 ELF: Strip section header in ELF objects
Section header isn't mandatory on ELF executable nor shared library.
This patch adds a new linker option, -z nosectionheader, to omit ELF
section header, a new objcopy and strip option, --strip-section-headers,
to remove ELF section headers.

bfd/

2023-06-06  H.J. Lu  <hongjiu.lu@intel.com>
	    Kaylee Blake  <klkblake@gmail.com>

	PR ld/25617
	* bfd.c (BFD_NO_SECTION_HEADER): New.
	(BFD_FLAGS_SAVED): Add BFD_NO_SECTION_HEADER.
	(BFD_FLAGS_FOR_BFD_USE_MASK): Likewise.
	* elfcode.h (elf_swap_ehdr_out): Omit section header with
	BFD_NO_SECTION_HEADER.
	(elf_write_shdrs_and_ehdr): Likewise.
	* elfxx-target.h (TARGET_BIG_SYM): Add BFD_NO_SECTION_HEADER
	to object_flags.
	(TARGET_LITTLE_SYM): Likewise.
	* bfd-in2.h: Regenerated.

binutils/

2023-06-06  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/25617
	* NEWS: Mention --strip-section-headers for objcopy and strip.
	* objcopy.c (strip_section_headers): New.
	(command_line_switch): Add OPTION_STRIP_SECTION_HEADERS.
	(strip_options): Add --strip-section-headers.
	(copy_options): Likewise.
	(copy_usage): Add --strip-section-headers.
	(strip_usage): Likewise.
	(copy_object): Handle --strip-section-headers for ELF files.
	(strip_main): Handle OPTION_STRIP_SECTION_HEADERS.
	(copy_main): Likewise.
	* doc/binutils.texi: Document --strip-section-headers for objcopy
	and strip.

ld/

2023-06-06  H.J. Lu  <hongjiu.lu@intel.com>
	    Kaylee Blake  <klkblake@gmail.com>

	PR ld/25617
	* NEWS: Mention -z nosectionheader.
	* emultempl/elf.em: Support -z sectionheader and
	-z nosectionheader.
	* ld.h (ld_config_type): Add no_section_header.
	* ld.texi: Document -z sectionheader and -z nosectionheader.
	* ldlang.c (ldlang_open_output): Handle
	config.no_section_header.
	* lexsup.c (parse_args): Enable --strip-all with
	-z nosectionheader.  Disallow -r with -z nosectionheader.
	(elf_static_list_options): Add -z sectionheader and
	-z nosectionheader.
2023-06-29 10:29:46 -07:00
Nick Clifton
fb221fba1a Add --remap-inputs option to the BFD linker.
PR 30374
  * ldfile.c (struct input_remap): New structure. (ldfile_add_remap): New function. (ldfile_remap_input_free): New function. (ldfile_add_remap_file): New function. (ldfile_possibly_remap_input): New function. (ldfile_print_input_remaps): New function. * ldfile.h: Add prototypes for new functions.
  * ldlang.c (new_afile): Call ldfile_possibly_remap_input. (lang_finish): Call ldfile_remap_input_free. (lang_map): Call ldfile_print_input_remaps.
  * ldlex.h (OPTION_REMAP_INPUTS, OPTION_REMAP_INPUTS_FILE): Define.
  * lexsup.c (ld_options): Add --remap-inputs-file and --remap-inputs. (parse_args): Handle new options.
  * NEWS: Mention the new feature.
  * ld.texi: Document the new options.
  * testsuite/ld-misc/input-remap.exp: New test driver.
  * testsuite/ld-misc/remaps.r: New file: Expected linker output.
  * testsuite/ld-misc/remaps.txt: New file.  Input remaps file.
2023-06-14 13:39:03 +01:00
Nick Clifton
35f8b0595f Slight wording improvement for the -Ur documentation 2023-05-30 16:12:18 +01:00
Jan Beulich
05d31a0b3f ld: drop stray blank from ld.texi
At least older makeinfo complains about it. Also fix an apparent typo
while touching that line.
2023-05-19 15:25:13 +02:00
Nick Clifton
d1792f72bf Document how to use the linker to create a resource only DLL.
PR 30359
  * ld.texi (WIN32): Document how to create a resource only DLL.
2023-05-16 16:04:58 +01:00
Nick Clifton
0a7dda4f7a -Ur option documentation
* ld.texi (-Ur): Clarify the actions of this option.
2023-05-16 11:20:55 +01:00
Alan Modra
31f1490158 PR28902, -T script with INSERT ordering
The answer to PR28902 may be deduced from the existing INSERT
documentation that says the default script is parsed after the -T
INSERT script, if you assume (correctly) that nothing special is done
when inserting into -T scripts overriding the default script.  In both
cases INSERT handling looks for the specified output section later on
the internal list of parsed script commands.  This isn't obvious
though, so make the ordering explicit, and mention that section
assignments are the same too.

	PR 28902
	* ld.texi (INSERT): Specify ordering when -T is used both to
	override the default script and to augment.
2023-05-13 15:12:48 +09:30
Nick Clifton
496917ce46 Add linker option to include local symbols in the linker map.
PR 16566
  * ldlang.c (ld_is_local_symbol): New function. (print_input_section): Add code to display local symbols in the section.
  * ldlex.h (enum option_values): Add OPTION_PRINT_MAP_LOCALS and OPTION_PRINT_MAP_LOCALS.
  * lexsup.c (ld_options[]): Add entries for --print-map-locals and --no-print-map-locals.
  * NEWS: Mention the new feature.
  * ld.h (struct ld_config_type): Add print_map_locals field.
  * ld.texi: Document the new command line option.
  * testsuite/ld-scripts/sizeof.s: Add a local symbol.
  * testsuite/ld-scripts/map-locals.d: New test control file.
  * testsuite/ld-scripts/map-address.exp: Run the new test.
2023-05-10 10:29:52 +01:00
Jan Beulich
3a117c5887 ld: add missing period after @xref
At least older versions of one of the doc generation tools complain
(warn) about it missing.
2023-04-21 07:54:19 +02:00
Nick Clifton
93cda40b4c Fix typos in the linker's documentation of the --enable-non-contiguous-regions option. 2023-04-12 09:54:48 +01:00
Roland McGrath
94ffdb5959 Fix typo in ld manual --enable-non-contiguous-regions example 2023-03-29 17:05:32 -07:00
Nick Clifton
2d5783fad7 Add --enable-linker-version option to bfd linker to add an entry in the .comment section.
PR 30187
  * NEWS: Mention the new feature. * ld.texi: Document the new feature. * ldgram.y: Handle LINKER_VERSION token. * ldlang.c (lang_add_version): New function. (enable_linker_version): New global variable. * ldlang.h (land_add_version): Prototype. (enable_linker_version): Export. * ldlex.h (OPTION_ENABLE_LINKER_VERSION): Define. (OPTION_DISABLE_LINKER_VERSION): Define. * ldlex.l (LINKER_VERSION): Add token. * lexsup.c (ld_options): Add --enable-linker-version and --disable-linker-version. (parse_args): Handle the new options. * scripttempl/arclinux.sc: Remove stabs and comment sections and replace with inclusion of misc-sections.sc * scripttempl/avr.sc: Likewise. * scripttempl/dlx.sc: Likewise. * scripttempl/elf.sc: Likewise. * scripttempl/elf32cr16.sc: Likewise. * scripttempl/elf32crx.sc: Likewise. * scripttempl/elf32msp430.sc: Likewise. * scripttempl/elf64bpf.sc: Likewise. * scripttempl/elf64hppa.sc: Likewise. * scripttempl/elf_chaos.sc: Likewise. * scripttempl/elfarc.sc: Likewise. * scripttempl/elfarcv2.sc: Likewise. * scripttempl/elfd10v.sc: Likewise. * scripttempl/elfd30v.sc: Likewise. * scripttempl/elfm68hc11.sc: Likewise. * scripttempl/elfm68hc12.sc: Likewise. * scripttempl/elfm9s12z.sc: Likewise. * scripttempl/elfmicroblaze.sc: Likewise. * scripttempl/elfxgate.sc: Likewise. * scripttempl/elfxtensa.sc: Likewise. * scripttempl/epiphany_4x4.sc: Likewise. * scripttempl/ft32.sc: Likewise. * scripttempl/ip2k.sc: Likewise. * scripttempl/iq2000.sc: Likewise. * scripttempl/mep.sc: Likewise. * scripttempl/nds32elf.sc: Likewise. * scripttempl/pru.sc: Likewise. * scripttempl/v850.sc: Likewise. * scripttempl/v850_rh850.sc: Likewise. * scripttempl/visium.sc: Likewise. * scripttempl/xstormy16.sc: Likewise. * scripttempl/z80.sc: Likewise. * testsuite/ld-scripts/script.exp: Run new tests. * scripttempl/misc-sections.sc: New file. * testsuite/ld-scripts/ld-version-2.d: New file. * testsuite/ld-scripts/ld-version.d: New file. * testsuite/ld-scripts/ld-version.t: New file.
2023-03-15 14:27:21 +00:00
Alan Modra
a4d5aec71e Revert ld ASCII support
Revert "Prevent the ASCII linker script directive from generating huge amounts of padding if the size expression is not a constant."
This reverts commit adbe951fc9.

Revert "ld test asciz and ascii fails"
This reverts the ascii.d part of commit 5f497256be.

Revert "Add support for the ASCII directive inside linker scripts."
This mostly reverts commit 9fe129a410
leaving the asciz.d and asciz.t changes in place.
2023-03-10 21:22:16 +10:30
Alan Modra
75bd292bea Revert ld DIGEST support
This is a hopefully temporary reversion of new ld features for
embedded processors by Ulf Samuelsson, plus some followup patches.

Squashed together from the following:

Revert "lddigest 32-bit support and gcc-4 compile errors"
This reverts commit d7ee19be87110a8f5342cec6e323d83d01c641d1.

Revert "ld: Use correct types for crc64 calculations"
This reverts commit 9a534b9f8e.

Revert "Re: DIGEST: testsuite"
This reverts commit c8e85484d8.

Revert "Regen potfiles"
This reverts commit 4d98c966f8.

Revert "DIGEST: Makefile.*"
This reverts commit 78ef6ab03f.

Revert "DIGEST: calculation"
This reverts commit 5243990191.

Revert "DIGEST: ldlang.*: add timestamp"
This reverts commit bd9466d4aa.

Revert "DIGEST: ldmain.c"
This reverts commit c8f8653fa7.

Revert "DIGEST: ldgram.y"
This reverts commit d73c01be26.

Revert "DIGEST: ldlex.l"
This reverts commit 48b5163a9d.

Revert "DIGEST: testsuite"
This reverts commit a4135d1a48.

Revert "DIGEST: Documentation"
This reverts commit 3ec28966c3.

Revert "DIGEST: NEWS"
This reverts commit 099bf2927d.

Revert "DIGEST: LICENSING"
This reverts commit 5c8a0c6654.
2023-03-10 21:22:16 +10:30
Alan Modra
bf0e353754 lddigest 32-bit support and gcc-4 compile errors
* ld.texi: Revert 2023-03-08 commit 9a534b9f8e.
	* testsuite/ld-scripts/crc64-poly.d: Likewise.
	* testsuite/ld-scripts/crc64-poly.t: Likewise.
	* lddigest.c: Formatting.
	(get_uint64_t): New function.
	(lang_add_digest): Take etree_type* args.  Replace "illegal" with
	"invalid" in error message.
	* lddigest.h (lang_add_digest): Update prototype.
	* lddigest_tab.c (algorithms): Work around gcc-4 errors.
	* ldgram.y (polynome): Adjust lang_add_digest call.
	* testsuite/ld-scripts/crc64-poly-size.d: Update expected error.
2023-03-09 16:02:57 +10:30
Nick Clifton
9a534b9f8e ld: Use correct types for crc64 calculations 2023-03-08 13:11:37 +00:00
Ulf Samuelsson
3ec28966c3 DIGEST: Documentation
Signed-off-by: Ulf Samuelsson <ulf@emagii.com>
2023-03-07 13:53:10 +00:00
Nick Clifton
3ac23310f2 Fix typo with my email address 2023-03-01 14:38:16 +00:00
Nick Clifton
9fe129a410 Add support for the ASCII directive inside linker scripts.
* ldlex.l: Add ASCII token.
 * ldgram.y: Add parsing of the ASCII command.
 * ldlang.c (lang_add_string): Add maximum size parameter.  Move escape character handling code into separate function.
 * ldlang.h (lang_add_string): Update prototype.
 * NEWS: Mention the new feature.
 * ld.texi (Output Section Data): Document the new directives.
 * testsuite/ld-scripts/asciz.t: Adjust to work on more architectures and to test more aspects of the ASCIZ directive.
 * testsuite/ld-scripts/asciz.d: Adjust to match the changes to the test linker script.
 * testsuite/ld-scripts/ascii.d: New test driver.
 * testsuite/ld-scripts/ascii.s: New test assembler source.
 * testsuite/ld-scripts/ascii.t: New test script.
 * testsuite/ld-scripts/script.exp: Run the new test.
2023-02-16 16:27:08 +00:00
Nick Clifton
9b38b85ec3 Mention that the -plugin command line option is used to load plugins. 2023-02-14 12:01:06 +00:00
Ulf Samuelsson
0d79a2a8e2 ASCIZ Command for output section
Adds a new directive to the linker script syntax: ASCIZ.
This inserts a zero-terminated string into the output at the place where it is used.
2023-02-14 10:13:28 +00:00
Indu Bhagat
1bd123bdf3 ld/doc: use "stack trace" instead of "unwind" for SFrame
SFrame format is meant for generating stack traces only.

ld/
	* ld.texi: Replace the use of "unwind" with "stack trace".
2023-02-02 00:49:44 -08:00
Alan Modra
d87bef3a7b Update year range in copyright notice of binutils files
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.
2023-01-01 21:50:11 +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
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
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
Nick Clifton
4b2e7a577c Add a -w option to the linker to suppress warning and error messages.
PR 29654
	* ld.h (struct ld_config_type): Add no_warnings field.
	* ldlex.h (enum option_values): Add OPTION_NO_WARNINGS.
	* lexsup.c (ld_options): Add --no-warnings.
	(parse_args): Add support for -w and --no-warnings.
	* ldmisc.c (vfinfo): Return early if the message is a warning and
	-w has been enabled.
	* ld.texi (options): Document new command line option.
	* NEWS: Mention the new feature.
2022-10-21 12:20:09 +01:00
Fangrui Song
2cac01e3ff binutils, gdb: support zstd compressed debug sections
PR29397 PR29563: Add new configure option --with-zstd which defaults to
auto.  If pkgconfig/libzstd.pc is found, define HAVE_ZSTD and support
zstd compressed debug sections for most tools.

* bfd: for addr2line, objdump --dwarf, gdb, etc
* gas: support --compress-debug-sections=zstd
* ld: support ELFCOMPRESS_ZSTD input and --compress-debug-sections=zstd
* objcopy: support ELFCOMPRESS_ZSTD input for
  --decompress-debug-sections and --compress-debug-sections=zstd
* gdb: support ELFCOMPRESS_ZSTD input.  The bfd change references zstd
  symbols, so gdb has to link against -lzstd in this patch.

If zstd is not supported, ELFCOMPRESS_ZSTD input triggers an error.  We
can avoid HAVE_ZSTD if binutils-gdb imports zstd/ like zlib/, but this
is too heavyweight, so don't do it for now.

```
% ld/ld-new a.o
ld/ld-new: a.o: section .debug_abbrev is compressed with zstd, but BFD is not built with zstd support
...

% ld/ld-new a.o --compress-debug-sections=zstd
ld/ld-new: --compress-debug-sections=zstd: ld is not built with zstd support

% binutils/objcopy --compress-debug-sections=zstd a.o b.o
binutils/objcopy: --compress-debug-sections=zstd: binutils is not built with zstd support

% binutils/objcopy b.o --decompress-debug-sections
binutils/objcopy: zstd.o: section .debug_abbrev is compressed with zstd, but BFD is not built with zstd support
...
```
2022-09-26 19:50:13 -07:00
Luca Boccassi
9e2bb0cb5e ld: add --package-metadata
Generate a .note.package FDO package metadata ELF note, following
the spec: https://systemd.io/ELF_PACKAGE_METADATA/

If the jansson library is available at build time (and it is explicitly
enabled), link ld to it, and use it to validate that the input is
correct JSON, to avoid writing garbage to the file. The
configure option --enable-jansson has to be used to explicitly enable
it (error out when not found). This allows bootstrappers (or others who
are not interested) to seamlessly skip it without issues.
2022-05-26 12:56:12 +09:30
Alan Modra
bd7d326deb Tidy warn-execstack handling
Make ld and bfd values consistent by swapping values 0 and 2 in
link_info.warn_execstack.  This has the benefit of making the value an
"extended" boolean, with 0 meaning no warning, 1 meaning warn, other
values a conditional warning.

Yes, this patch introduces fails on arm/aarch64.  Not a problem with
this patch but an arm/aarch64 before_parse problem.

bfd/
	* elflink.c (bfd_elf_size_dynamic_sections): Adjust
	warn_execstack test.
include/
	* bfdlink.h (warn_execstack): Swap 0 and 2 meaning.
ld/
	* configure.ac (DEFAULT_LD_WARN_EXECSTACK): Use values of 0,
	1, 2 consistent with link_info.warn_execstack.
	* ld.texi: Typo fixes.
	* lexsup.c (parse_args): Adjust setting of link_info.warn_execstack.
	(elf_static_list_options): Adjust help message conditions.
	* configure: Regenerate.
2022-05-20 16:11:25 +09:30
Nick Clifton
ba951afb99 Add a linker warning when creating potentially dangerous executable segments. Add tests, options to disabke and configure switches to choose defaults. 2022-05-03 11:42:24 +01:00
Nick Clifton
65daf5bed6 Add linker warning for when it creates an executable stack.
PR 29072
2022-04-20 13:39:05 +01:00
Roland McGrath
5c14cc552d Fix typo in ld.texi
ld/
	* ld.texi (Output Section Type): Fix typo in @code syntax.
2022-02-18 11:42:09 -08:00
Fangrui Song
c212f39d9a ld: Support customized output section type
bfd/
    PR ld/28841
    * bfd-in2.h (struct bfd_section): Add type.
    (discarded_section): Add field.
    * elf.c (elf_fake_sections): Handle bfd_section::type.
    * section.c (BFD_FAKE_SECTION): Add field.
    * mri.c (mri_draw_tree): Update function call.

ld/
    PR ld/28841
    * ld.texi: Document new output section type.
    * ldlex.l: Add new token TYPE.
    * ldgram.y: Handle TYPE=exp.
    * ldlang.h: Add type_section to list of section types.
    * ldlang.c (lang_add_section): Handle type_section.
    (map_input_to_output_sections): Handle type_section.
    * testsuite/ld-scripts/output-section-types.t: Add tests.
    * testsuite/ld-scripts/output-section-types.d: Update.
2022-02-16 17:41:23 +00:00
H.J. Lu
72aa81732b ld: Add glibc dependency for DT_RELR
When DT_RELR is enabled, to avoid random run-time crash with older glibc
binaries without DT_RELR support, add a GLIBC_ABI_DT_RELR symbol version,
which is provided by glibc with DT_RELR support, dependency on the shared
C library if it provides a GLIBC_2.XX symbol version.

bfd/

	* elflink.c (elf_link_add_dt_relr_dependency): New function.
	(bfd_elf_size_dynamic_sections): Call
	elf_link_add_dt_relr_dependency if DT_RELR is enabled.

ld/

	* ld.texi: Mention GLIBC_ABI_DT_RELR in -z pack-relative-relocs
	entry.
	* testsuite/ld-elf/dt-relr-glibc-1.c: New file.
	* testsuite/ld-elf/dt-relr-glibc-1a.rd: Likewise.
	* testsuite/ld-elf/dt-relr-glibc-1b.rd: Likewise.
	* testsuite/ld-elf/dt-relr.exp: Likewise.
2022-01-12 06:08:47 -08:00
H.J. Lu
6a91be8666 ld: Initial DT_RELR support
Add a -z pack-relative-relocs option to enable DT_RELR and create a
relr.dyn section for DT_RELR.  DT_RELR is implemented with the linker
relaxation infrastructure, but it doesn't require the --relax option
enabled.  -z pack-relative-relocs implies -z combreloc.  -z nocombreloc
implies -z nopack-relative-relocs.

-z pack-relative-relocs is chosen over the similar option in lld,
--pack-dyn-relocs=relr, to implement a glibc binary lockout mechanism
with a special glibc version symbol, to avoid random crashes of DT_RELR
binaries with the existing glibc binaries.

bfd/

	* elf-bfd.h (elf_link_hash_table): Add srelrdyn.
	* elflink.c (_bfd_elf_link_create_dynamic_sections): Create a
	.relr.dyn section for DT_RELR.

include/

	* bfdlink.h (bfd_link_info): Add enable_dt_relr.

ld/

	* News: Mention -z pack-relative-relocs and
	-z nopack-relative-relocs.
	* ld.texi: Document -z pack-relative-relocs and
	-z nopack-relative-relocs.
	* ldelf.c (ldelf_after_parse): Disable DT_RELR if not building
	PIE nor shared library.  Add 3 spare dynamic tags for DT_RELR,
	DT_RELRSZ and DT_RELRENT.
	* ldlang.c (lang_relax_sections): Also enable relaxation if
	DT_RELR is enabled.
	* emulparams/elf32_x86_64.sh: Source dt-relr.sh.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.
	* emulparams/dt-relr.sh: New file.
	* scripttempl/elf.sc: Support .relr.dyn.
2022-01-12 06:04:29 -08:00
Alan Modra
a2c5833233 Update year range in copyright notice of binutils files
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.
2022-01-02 12:04:28 +10:30
Alan Modra
b4ca801960 Correct ld script wildcard matching description
Goes with commit 68bbb9f788

	* ld.texi (Input Section Wildcards): Delete paragraph incorrectly
	saying '*' does not match '/'.
2021-11-08 08:19:34 +10:30
Nick Clifton
5226a6a892 Change the linker's heuristic for computing the entry point for binaries so that shared libraries default to an entry point of 0.
* ldlang.c (lang_end): When computing the entry point, only
	try the start address of the entry section when creating an
	executable.
	* ld.texi (Entry point): Update description of heuristic used to
	choose the entry point.
	testsuite/ld-alpha/tlspic.rd: Update expected entry point address.
	testsuite/ld-arm/tls-gdesc-got.d: Likewise.
	testsuite/ld-i386/tlsnopic.rd: Likewise.
	testsuite/ld-ia64/tlspic.rd: Likewise.
	testsuite/ld-sparc/gotop32.rd: Likewise.
	testsuite/ld-sparc/gotop64.rd: Likewise.
	testsuite/ld-sparc/tlssunnopic32.rd: Likewise.
	testsuite/ld-sparc/tlssunnopic64.rd: Likewise.
	testsuite/ld-sparc/tlssunpic32.rd: Likewise.
	testsuite/ld-sparc/tlssunpic64.rd: Likewise.
	testsuite/ld-tic6x/shlib-1.rd: Likewise.
	testsuite/ld-tic6x/shlib-1b.rd: Likewise.
	testsuite/ld-tic6x/shlib-1r.rd: Likewise.
	testsuite/ld-tic6x/shlib-1rb.rd: Likewise.
	testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
	testsuite/ld-x86-64/pr14207.d: Likewise.
	testsuite/ld-x86-64/tlsdesc.rd: Likewise.
	testsuite/ld-x86-64/tlspic.rd: Likewise.
	testsuite/ld-x86-64/tlspic2.rd: Likewise.
2021-09-21 13:21:41 +01:00
Alan Modra
b325429b2f ld script lower-case absolute and sizeof_headers
I think these happened by accident, so let's see what breaks if they
are removed.

	* ldlex.l: Remove lower case "absolute" and "sizeof_headers"
	in non-mri mode.
	* ld.texi: Remove sizeof_headers index.
	* testsuite/ld-mmix/mmohdr1.ld: Use SIZEOF_HEADERS.
2021-08-13 22:44:36 +09:30
Alan Modra
fb0afe4cca Mention whitespace in script expressions
Inside an output section statement, ld's parser can't tell whether a
line
    .+=4;
is an assignment to dot or a file named ".+=4".

	* ld.texi (expressions): Mention need for whitespace.
2021-08-11 19:41:01 +09:30
Alan Modra
010e444b2f PR28155, Superfluous "the" in the man page
PR 28155
	* ld.texi (Options <runtime library name>): Correct grammar.
2021-08-04 13:14:29 +09:30
Luca Boccassi
6b86da53d5 Allows linker scripts to set the SEC_READONLY flag.
* ld.texi: Document new output section type.
* ldgram.y: Add new token.
* ldlang.c: Handle the new flag.
* ldlang.h: Add readonly_section to list of section types.
* ldlex.l: Add a new identifier.
* testsuite/ld-scripts/output-section-types.t: New example linker script.
* testsuite/ld-scripts/output-section-types.d: Test driver.
* testsyute/ld-scripts/script.exp: Run the new test.
2021-07-21 14:36:02 +01:00
H.J. Lu
6f365fda85 elf: Add GNU_PROPERTY_1_NEEDED check
If GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS is set on any input
relocatable files:

1. Don't generate copy relocations.
2. Turn off extern_protected_data since it implies
GNU_PROPERTY_NO_COPY_ON_PROTECTED.
3. Treate reference to protected symbols with indirect external access
as local.
4. Set GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS on output.
5. When generating executable, clear this bit when there are non-GOT or
non-PLT relocations in input relocatable files without the bit set.
6. Add -z [no]indirect-extern-access to control indirect external access.

bfd/

	* elf-bfd (elf_obj_tdata): Add has_indirect_extern_access.
	(elf_has_indirect_extern_access): New.
	* elf-properties.c (_bfd_elf_parse_gnu_properties): Set
	elf_has_indirect_extern_access and elf_has_no_copy_on_protected
	when seeing GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS.
	(elf_write_gnu_propertie): Add an argument to pass link_info.
	Set needed_1_p for GNU_PROPERTY_1_NEEDED in memory.
	(_bfd_elf_link_setup_gnu_properties): Handle
	GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS for
	-z indirect-extern-access.  Set nocopyreloc to true and
	extern_protected_data to false for indirect external access.
	(_bfd_elf_convert_gnu_properties): Updated.
	* elf32-i386.c (elf_i386_check_relocs): Set
	non_got_ref_without_indirect_extern_access on legacy non-GOT or
	non-PLT references.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elflink.c (_bfd_elf_symbol_refs_local_p): Return true for
	STV_PROTECTED symbols with indirect external access.
	* elfxx-x86.c (_bfd_x86_elf_adjust_dynamic_symbol): Clear
	indirect_extern_access for legacy non-GOT/non-PLT references.
	* elfxx-x86.h (elf_x86_link_hash_entry): Add
	non_got_ref_without_indirect_extern_access.

include/

	* bfdlink.h (bfd_link_info): Add indirect_extern_access and
	needed_1_p.  Change nocopyreloc to int.

ld/

	* NEWS: Mention -z [no]indirect-extern-access
	* ld.texi: Document -z [no]indirect-extern-access
	* ldmain.c (main): Initialize link_info.indirect_extern_access
	to -1.
	* emulparams/extern_protected_data.sh: Support
	-z [no]indirect-extern-access.
	* testsuite/ld-elf/indirect-extern-access-1.rd: New file
	* testsuite/ld-elf/indirect-extern-access-1a.c: Likewise.
	* testsuite/ld-elf/indirect-extern-access-1b.c: Likewise.
	* testsuite/ld-elf/indirect-extern-access-2.rd: Likewise.
	* testsuite/ld-elf/indirect-extern-access-2a.c: Likewise.
	* testsuite/ld-elf/indirect-extern-access-2b.c: Likewise.
	* testsuite/ld-elf/indirect-extern-access-3.rd: Likewise.
	* testsuite/ld-elf/indirect-extern-access.S: Likewise.
	* testsuite/ld-elf/property-1_needed-1b.d: Likewise.
	* testsuite/ld-elf/property-1_needed-1c.d: Likewise.
	* testsuite/ld-x86-64/indirect-extern-access.rd: Likewise.
	* testsuite/ld-x86-64/protected-data-1.h: Likewise.
	* testsuite/ld-x86-64/protected-data-1a.c: Likewise.
	* testsuite/ld-x86-64/protected-data-1b.c: Likewise.
	* testsuite/ld-x86-64/protected-data-2a.S: Likewise.
	* testsuite/ld-x86-64/protected-data-2b.S: Likewise.
	* testsuite/ld-x86-64/protected-func-2a.S: Likewise.
	* testsuite/ld-x86-64/protected-func-2b.S: Likewise.
	* testsuite/ld-x86-64/protected-func-2c.c: Likewise.
	* testsuite/ld-elf/linux-x86.exp: Run test with
	GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS.
	* testsuite/ld-x86-64/x86-64.exp: Run tests for protected
	function and data with indirect external access.
2021-07-08 18:14:31 -07:00
H.J. Lu
a8dde0a211 ld: Limit cache size and add --max-cache-size=SIZE
When link_info.keep_memory is true, linker caches the relocation
information and symbol tables of input files in memory.  When there
are many input files with many relocations, we may run out of memory.
Add --max-cache-size=SIZE to set the maximum cache size.

bfd/

	PR ld/18028
	* bfd.c (bfd): Add alloc_size.
	* elf-bfd.h (_bfd_elf_link_info_read_relocs): New.
	* elf32-i386.c (elf_i386_check_relocs): Use _bfd_link_keep_memory.
	Update cache_size.
	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
	* elflink.c (_bfd_elf_link_read_relocs): Renamed to ...
	(_bfd_elf_link_info_read_relocs): This.  Update cache_size.
	(_bfd_elf_link_read_relocs): New.
	(_bfd_elf_link_check_relocs): Call _bfd_elf_link_info_read_relocs
	instead of _bfd_elf_link_read_relocs.
	(elf_link_add_object_symbols): Likewise.
	(elf_link_input_bfd): Likewise.
	(init_reloc_cookie_rels): Likewise.
	(init_reloc_cookie): Update cache_size.  Call
	_bfd_elf_link_info_read_relocs instead of
	_bfd_elf_link_read_relocs.
	(link_info_ok): New.
	(elf_gc_smash_unused_vtentry_relocs): Updated.  Call
	_bfd_elf_link_info_read_relocs instead of
	_bfd_elf_link_read_relocs.
	(bfd_elf_gc_sections): Use link_info_ok.  Pass &link_info_ok
	to elf_gc_smash_unused_vtentry_relocs.
	* libbfd-in.h (_bfd_link_keep_memory): New.
	* linker.c (_bfd_link_keep_memory): New.
	* opncls.c (bfd_alloc): Update alloc_size.
	* bfd-in2.h: Regenerated.
	* libbfd.h: Likewise.

include/

	PR ld/18028
	* bfdlink.h (bfd_link_info): Add cache_size and max_cache_size.

ld/

	PR ld/18028
	* NEWS: Mention --max-cache-size=SIZE.
	* ld.texi: Document --max-cache-size=SIZE.
	* ldlex.h (option_values): Add OPTION_MAX_CACHE_SIZE.
	* ldmain.c: (main): Set link_info.max_cache_size to -1.
	* lexsup.c (ld_options): Add --max-cache-size=SIZE.
	(parse_args): Support OPTION_MAX_CACHE_SIZE.
	* testsuite/ld-bootstrap/bootstrap.exp: Add test for
	--max-cache-size=-1.
2021-07-08 09:59:28 -07:00
H.J. Lu
2d95647bdd ld.texi: Move -z unique-symbol after -z undefs.
* ld.texi: Move -z unique-symbol after -z undefs.
2021-06-18 07:33:30 -07:00
Fangrui Song
e8f6c2a5ba ld: Add -no-pie
gold has had this option for many years. Not having this option caused
some confusion to users.  The help message clarifies the default state.

ld/
    * ldlex.h (enum option_values): Add OPTION_NO_PIE.
    * lexsup.c (struct ld_options): Add -no-pie.
    (parse_args): Handle -no-pie.
    * ld.texi: Document -no-pie.
2021-06-17 09:57:40 -07:00
Alan Modra
364d772977 PR2589, ld vs. ld.so
PR 2589
	* ld.texi (link-time runtime library search path): Mention
	plugin library path.  Correct order of search.
2021-06-03 18:32:30 +09:30
Fangrui Song
cf893b0ef7 ld: Add -Bno-symbolic
PR 27834
	* ldlex.h (enum option_values): Add OPTION_NO_SYMBOLIC.
	* lexsup.c (ld_options): Add -Bno-symbolic.
	(parse_args): Handle -Bno-symbolic.
	* ld.texi: Document -Bno-symbolic.
	* NEWS: Mention -Bno-symbolic.
	* testsuite/ld-elf/shared.exp: Add a test.
2021-05-13 12:53:49 +09:30
Nick Clifton
6418520e7f Document the effect of --as-needed on --rpath on Linux based systems.
* ld.texi (Options): Add note about the effect of --as-needed on
	the --rpath and --rpath-link options on Linux based systems.
2021-04-13 14:37:06 +01:00