Commit Graph

248 Commits

Author SHA1 Message Date
Nick Clifton
057a2b4c4b Revert: 35fd2ddeb1
PR 20814
2024-06-26 13:17:25 +01:00
H.J. Lu
65e513dc95 ld: Align --no-error-execstack help output
* lexsup.c (elf_static_list_options): Align --no-error-execstack
	help output.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-06-14 13:29:04 -07:00
Nick Clifton
e8e10743f7 Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only segments.
PR 30907
2024-06-13 15:10:15 +01:00
Nick Clifton
6e8376fa56 Add --section-ordering command line option to the bfd linker. 2024-05-10 16:59:05 +01:00
H.J. Lu
d9511b64b8 ld: Add -plugin-save-temps
Add -plugin-save-temps to store plugin intermediate files permanently.
It can be used to exam the final input object files generated from IR
inputs.

	* NEWS: Mention -plugin-save-temps.
	* ld.h (ld_config_type): Add plugin_save_temps.
	* ld.texi: Document -plugin-save-temps.
	* ldlex.h (option_values): Add OPTION_PLUGIN_SAVE_TEMPS.
	* lexsup.c (ld_options): Add -plugin-save-temps.
	(parse_args): Handle OPTION_PLUGIN_SAVE_TEMPS.
	* plugin.c (plugin_call_cleanup): Don't call plugin
	cleanup_handler for -plugin-save-temps.
2024-02-16 05:03:06 -08:00
Alan Modra
fd67aa1129 Update year range in copyright notice of binutils files
Adds two new external authors to etc/update-copyright.py to cover
bfd/ax_tls.m4, and adds gprofng to dirs handled automatically, then
updates copyright messages as follows:

1) Update cgen/utils.scm emitted copyrights.
2) Run "etc/update-copyright.py --this-year" with an extra external
   author I haven't committed, 'Kalray SA.', to cover gas testsuite
   files (which should have their copyright message removed).
3) Build with --enable-maintainer-mode --enable-cgen-maint=yes.
4) Check out */po/*.pot which we don't update frequently.
2024-01-04 22:58:12 +10:30
Nick Clifton
b2a6584d75 Fix another linker command line option that was not being recognised in its long form.
PR 28910
  * lexsup.c (ld_options): Ensure that the --mri-script option is correctly recognised.
2023-11-14 11:24:58 +00:00
Nick Clifton
b0dfd7427b GNU-ld: ARM: Issues when trying to set target output architecture
PR 28910
  * lexsup.c (ld_options): Ensure that the --format option is correctly recognised.
2023-11-13 16:24:19 +00:00
Nick Clifton
e922d1eaa3 Add ability to change linker warning messages into errors when reporting executable stacks and/or executable segments.
include
  * bfdlink.h (struct bfd_link_info): Update descriptions of the 'execstack', 'noexecstack' and 'warn_execstack' fields. Add 'error_exectack' and 'warn_is_error_for_rwx_segments' fields.

  bfd
  * elf.c (assign_file_positions_except_relocs): Turn warnings about executable segments into errors if so requested.
  * elflink.c (bfd_elf_size_dynamic_sections): Turn warnings about executable stacks into errors if so requested.

  ld
  * ldlex.h (enum option_values): Add OPTION_ERROR_EXECSTACK, OPTION_NO_ERROR_EXECSTACK, OPTION_WARN_EXECSTACK_OBJECTS, OPTION_ERROR_RWX_SEGMENTS and OPTION_NO_ERROR_RWX_SEGMENTS. (struct ld_option): Add new long options. (parse_args): Parse new long options. (elf_static_list_options): Display the new options.
  * ld.texi: Document the new command line options.
  * configure.ac (error-execstack): New configuration option. (error-rwx-segments): New configuration option.
  * emultempl/elf.em (_before_parse): Initialse the new linkinfo fields.
  * NEWS: Mention the new features.
  * config.in: Regenerate.
  * configure: Regenerate.
  * testsuite/ld-elf/commonpage2.d: Disable errors for RWX segments and/or executable stacks.
  * testsuite/ld-elf/elf.exp: Likewise.
  * testsuite/ld-elf/header.d: Likewise.
  * testsuite/ld-elf/loadaddr1.d: Likewise.
  * testsuite/ld-elf/loadaddr2.d: Likewise.
  * testsuite/ld-elf/maxpage4.d: Likewise.
  * testsuite/ld-elf/nobits-1.d: Likewise.
  * testsuite/ld-elf/note-1.d: Likewise.
  * testsuite/ld-elf/orphan-10.d: Likewise.
  * testsuite/ld-elf/orphan-11.d: Likewise.
  * testsuite/ld-elf/orphan-12.d: Likewise.
  * testsuite/ld-elf/orphan-5.d: Likewise.
  * testsuite/ld-elf/orphan-7.d: Likewise.
  * testsuite/ld-elf/orphan-8.d: Likewise.
  * testsuite/ld-elf/orphan-9.d: Likewise.
  * testsuite/ld-elf/orphan-region.d: Likewise.
  * testsuite/ld-elf/orphan.d: Likewise.
  * testsuite/ld-elf/pr19539.d: Likewise.
  * testsuite/ld-elf/pr26256-1a.d: Likewise.
  * testsuite/ld-elf/pr26907.d: Likewise.
  * testsuite/ld-elf/pr28597.d: Likewise.
  * testsuite/ld-elf/retain2.d: Likewise.
  * testsuite/ld-elf/shared.exp: Likewise.
  * testsuite/ld-elf/size-1.d: Likewise.
  * testsuite/ld-elf/textaddr7.d: Likewise.
  * testsuite/ld-elf/warn1.d: Likewise.
  * testsuite/ld-elf/warn2.d: Likewise.
  * testsuite/ld-i386/discarded1.d: Likewise.
  * testsuite/ld-i386/pr19175.d: Likewise.
  * testsuite/ld-i386/pr19539.d: Likewise.
  * testsuite/ld-i386/pr23189.d: Likewise.
  * testsuite/ld-plugin/lto-3r.d: Likewise.
  * testsuite/ld-plugin/lto-5r.d: Likewise.
  * testsuite/ld-plugin/lto.exp: Likewise.
  * testsuite/ld-powerpc/ppc476-shared.d: Likewise.
  * testsuite/ld-powerpc/ppc476-shared2.d: Likewise.
  * testsuite/ld-powerpc/pr28827-2.d: Likewise.
  * testsuite/ld-s390/s390.exp: Likewise.
  * testsuite/ld-scripts/align2a.d: Likewise.
  * testsuite/ld-scripts/align2b.d: Likewise.
  * testsuite/ld-scripts/align5.d: Likewise.
  * testsuite/ld-scripts/alignof.exp: Likewise.
  * testsuite/ld-scripts/crossref.exp: Likewise.
  * testsuite/ld-scripts/defined2.d: Likewise.
  * testsuite/ld-scripts/defined3.d: Likewise.
  * testsuite/ld-scripts/defined5.d: Likewise.
  * testsuite/ld-scripts/pr14962.d: Likewise.
  * testsuite/ld-scripts/pr18963.d: Likewise.
  * testsuite/ld-scripts/pr20302.d: Likewise.
  * testsuite/ld-scripts/print-memory-usage.exp: Likewise.
  * testsuite/ld-scripts/rgn-at1.d: Likewise.
  * testsuite/ld-scripts/rgn-at10.d: Likewise.
  * testsuite/ld-scripts/rgn-at4.d: Likewise.
  * testsuite/ld-scripts/rgn-at6.d: Likewise.
  * testsuite/ld-scripts/rgn-at8.d: Likewise.
  * testsuite/ld-scripts/rgn-at9.d: Likewise.
  * testsuite/ld-scripts/rgn-over1.d: Likewise.
  * testsuite/ld-scripts/rgn-over2.d: Likewise.
  * testsuite/ld-scripts/rgn-over4.d: Likewise.
  * testsuite/ld-scripts/rgn-over5.d: Likewise.
  * testsuite/ld-scripts/rgn-over6.d: Likewise.
  * testsuite/ld-scripts/script.exp: Likewise.
  * testsuite/ld-scripts/sizeof.exp: Likewise.
  * testsuite/ld-scripts/sort-file.d: Likewise.
  * testsuite/ld-x86-64/discarded1.d: Likewise.
  * testsuite/ld-x86-64/pr19175.d: Likewise.
  * testsuite/ld-x86-64/pr19539a.d: Likewise.
  * testsuite/ld-x86-64/pr19539b.d: Likewise.
  * testsuite/ld-x86-64/pr23189.d: Likewise.
2023-11-10 11:37:27 +00:00
Nick Clifton
a79e9a07a0 Fix: GNU-ld: ARM: Issues when trying to set target output architecture
PR 28910
  * lexsup.c (ld_options): Require that the --architecture option is given exactly two dashes, so that it does not become confused with the -a option.
2023-10-16 15:48:26 +01:00
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
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
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
8478900290 ppc32 and "LOAD segment with RWX permissions"
When using a bss-plt we'll always trigger the RWX warning, which
disturbs gcc test results.  On the other hand, there may be reason to
want the warning when gcc is configured with --enable-secureplt.
So turning off the warning entirely for powerpc might not be the best
solution.  Instead, we'll turn off the warning whenever a bss-plt is
generated, unless the user explicitly asked for the warning.

bfd/
	* elf32-ppc.c (ppc_elf_select_plt_layout): Set
	no_warn_rwx_segments on generating a bss plt, unless explicity
	enabled by the user.  Also show the bss-plt warning when
	--warn-rwx-segments is given without --bss-plt.
include/
	* bfdlink.h (struct bfd_link_info): Add user_warn_rwx_segments.
ld/
	* lexsup.c (parse_args): Set user_warn_rwx_segments.
	* testsuite/ld-elf/elf.exp: Pass --secure-plt for powerpc to
	the rwx tests.
2023-02-06 23:06:44 +10:30
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
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
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
27fb6a1a7f ld: Add --undefined-version
This cancels a previous --no-undefined-version.
gold has had --undefined-version for a long time.
2022-10-13 19:06:43 -07:00
Martin Liska
857bddbe73 refactor usage of compressed_debug_section_type
bfd/ChangeLog:

	* bfd-in.h (bfd_hash_set_default_size): Add COMPRESS_UNKNOWN
	  enum value.
	(struct compressed_type_tuple): New.
	* bfd-in2.h (bfd_hash_set_default_size): Regenerate.
	(struct compressed_type_tuple): Likewise.
	* libbfd.c (ARRAY_SIZE): New macro.
	(bfd_get_compression_algorithm): New function.
	(bfd_get_compression_algorithm_name): Likewise.

gas/ChangeLog:

	* as.c: Do not special-case, use the new functions.

ld/ChangeLog:

	* emultempl/elf.em: Do not special-case, use the new functions.
	* lexsup.c (elf_static_list_options): Likewise.
2022-10-11 14:13:26 +02: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
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
Mike Frysinger
ef91306693 ld: fix --disable-multiple-abs-defs alignment in help 2021-11-25 22:26:50 -05: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
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
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
Alan Modra
f38a2680c2 Use bool in ld
* 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.
2021-03-31 10:49:23 +10:30
Alan Modra
63b4cc53dc TRUE/FALSE simplification
There is really no need to write code like "foo != 0 ? TRUE : FALSE"
unless we had stupidly defined FALSE as something other than 0 or TRUE
as something other than 1.  The simpler "foo != 0" does just as well.
Similarly "(condition == TRUE)" or "(condition == FALSE) can be
simplified to "(condition)" and "(!condition)" respectively.

I'll note that there is reason to use "integer_expression != 0" when
assigning a bfd_boolean rather than the simpler "integer_expression",
if you expect the variable to have 0 or 1 value.  It's probably even a
good idea to not rely on implicit conversion if bfd_boolean were _Bool.

bfd/
	* aoutx.h (aout_link_write_symbols): Don't cast boolean expression
	to bfd_boolean.
	* elf32-or1k.c (or1k_set_got_and_rela_sizes): Dont compare booleans
	against FALSE.
	* elf32-arc.c (name_for_global_symbol): Don't compare boolean to TRUE.
	(is_reloc_PC_relative): Don't use "boolean_condition ? TRUE : FALSE".
	(is_reloc_SDA_relative, is_reloc_for_GOT): Likewise.
	(is_reloc_for_PLT, is_reloc_for_TLS): Likewise.
	* elf32-arm.c (stm32l4xx_need_create_replacing_stub): Likewise.
	* elf32-nds32.c (insert_nds32_elf_blank): Likewise.
	* elf32-rx.c (rx_set_section_contents): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_final_link_relocate): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_ignore_undef_symbol): Likewise.
	* mach-o.c (bfd_mach_o_read_command): Likewise.
	* targets.c (bfd_get_target_info): Likewise.
binutils/
	* dlltool.c (main): Don't use "boolean_condition ? TRUE : FALSE".
	* dwarf.c (read_and_display_attr_value): Likewise.
	(display_debug_str_offsets): Likewise.
	* objdump.c (dump_bfd): Likewise.
	* readelf.c (dump_section_as_strings): Likewise.
	(dump_section_as_bytes): Likewise.
gas/
	* atof-generic.c (FALSE, TRUE): Don't define.
	* config/obj-elf.h (FALSE, TRUE): Don't define.
	* config/obj-som.h (FALSE, TRUE): Don't define.
	* config/tc-hppa.h (FALSE, TRUE): Don't define.
	* config/tc-pdp11.c (FALSE, TRUE): Don't define.
	* config/tc-iq2000.h (obj_fix_adjustable): Delete.
	* config/tc-m32r.h (TC_FIX_ADJUSTABLE): Delete.
	* config/tc-mt.h (obj_fix_adjustable): Delete.
	* config/tc-nds32.h (TC_FIX_ADJUSTABLE): Delete.
	* config/tc-arc.c (parse_opcode_flags): Simplify boolean expression.
	(relaxable_flag, relaxable_operand, assemble_insn): Likewise.
	(tokenize_extregister): Likewise.
	* config/tc-csky.c (parse_opcode, get_operand_value): Likewise.
	(parse_operands_op, parse_operands, md_assemble): Likewise.
	* config/tc-d10v.c (build_insn): Likewise.
	* config/tc-score.c (s3_gen_insn_frag): Likewise.
	* config/tc-score7.c (s7_gen_insn_frag, s7_relax_frag): Likewise.
	* config/tc-tic6x.c (tic6x_update_features, md_assemble): Likewise.
	* config/tc-z80.c (emit_byte): Likewise.
include/
	* opcode/aarch64.h (alias_opcode_p): Simplify boolean expression.
	(opcode_has_alias, pseudo_opcode_p, optional_operand_p): Likewise.
	(opcode_has_special_coder): Likewise.
ld/
	* emultempl/aix.em (gld${EMULATION_NAME}_before_allocation): Simplify
	boolean expression.
	* lexsup.c (parse_args): Likewise.
	* pe-dll.c (pe_dll_id_target): Likewise.
opcodes/
	* aarch64-opc.c (vector_qualifier_p): Simplify boolean expression.
	(fp_qualifier_p, get_data_pattern): Likewise.
	(aarch64_get_operand_modifier_from_value): Likewise.
	(aarch64_extend_operator_p, aarch64_shift_operator_p): Likewise.
	(operand_variant_qualifier_p): Likewise.
	(qualifier_value_in_range_constraint_p): Likewise.
	(aarch64_get_qualifier_esize): Likewise.
	(aarch64_get_qualifier_nelem): Likewise.
	(aarch64_get_qualifier_standard_value): Likewise.
	(get_lower_bound, get_upper_bound): Likewise.
	(aarch64_find_best_match, match_operands_qualifier): Likewise.
	(aarch64_print_operand): Likewise.
	* aarch64-opc.h (operand_has_inserter, operand_has_extractor): Likewise.
	(operand_need_sign_extension, operand_need_shift_by_two): Likewise.
	(operand_need_shift_by_four, operand_maybe_stack_pointer): Likewise.
	* arm-dis.c (print_insn_mve, print_insn_thumb32): Likewise.
	* tic6x-dis.c (tic6x_check_fetch_packet_header): Likewise.
	(print_insn_tic6x): Likewise.
2021-03-29 11:22:22 +10:30
Martin Liska
08dedd6631 Add startswith function and use it instead of CONST_STRNEQ.
bfd/ChangeLog:

	* bfd-in.h (startswith): Add startswith function.
	(CONST_STRNEQ): Remove.
	* bfd-in2.h (startswith): Regenerate with make headers.
	* archive.c (bfd_slurp_armap): Replace usage of CONST_STRNEQ with startswith.
	(_bfd_slurp_extended_name_table): Likewise.
	* archive64.c (_bfd_archive_64_bit_slurp_armap): Likewise.
	* bfd.c (bfd_get_sign_extend_vma): Likewise.
	(bfd_convert_section_size): Likewise.
	(bfd_convert_section_contents): Likewise.
	* coff-stgo32.c (go32exe_create_stub): Likewise.
	(go32exe_check_format): Likewise.
	* coffcode.h (styp_to_sec_flags): Likewise.
	(GNU_DEBUGALTLINK): Likewise.
	* coffgen.c (_bfd_coff_section_already_linked): Likewise.
	(coff_gc_sweep): Likewise.
	(bfd_coff_gc_sections): Likewise.
	* cofflink.c (coff_link_add_symbols): Likewise.
	(process_embedded_commands): Likewise.
	* compress.c (bfd_is_section_compressed_with_header): Likewise.
	(bfd_init_section_decompress_status): Likewise.
	* dwarf2.c (find_debug_info): Likewise.
	(place_sections): Likewise.
	* ecoff.c (_bfd_ecoff_slurp_armap): Likewise.
	* elf-m10300.c (_bfd_mn10300_elf_size_dynamic_sections): Likewise.
	* elf.c (_bfd_elf_make_section_from_shdr): Likewise.
	(assign_section_numbers): Likewise.
	(elfcore_grok_win32pstatus): Likewise.
	* elf32-arm.c (cmse_scan): Likewise.
	(elf32_arm_gc_mark_extra_sections): Likewise.
	(elf32_arm_size_dynamic_sections): Likewise.
	(is_arm_elf_unwind_section_name): Likewise.
	* elf32-bfin.c (bfin_size_dynamic_sections): Likewise.
	* elf32-cr16.c (_bfd_cr16_elf_size_dynamic_sections): Likewise.
	* elf32-cris.c (elf_cris_size_dynamic_sections): Likewise.
	* elf32-csky.c (csky_elf_size_dynamic_sections): Likewise.
	* elf32-hppa.c (elf32_hppa_size_dynamic_sections): Likewise.
	* elf32-iq2000.c (iq2000_elf_check_relocs): Likewise.
	* elf32-lm32.c (lm32_elf_size_dynamic_sections): Likewise.
	* elf32-m32r.c (m32r_elf_size_dynamic_sections): Likewise.
	* elf32-m68k.c (elf_m68k_size_dynamic_sections): Likewise.
	* elf32-metag.c (elf_metag_size_dynamic_sections): Likewise.
	* elf32-msp430.c (msp430_elf_relax_delete_bytes): Likewise.
	* elf32-nios2.c (nios2_elf32_size_dynamic_sections): Likewise.
	* elf32-or1k.c (or1k_elf_size_dynamic_sections): Likewise.
	* elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise.
	* elf32-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elf32-score.c (s3_bfd_score_elf_size_dynamic_sections): Likewise.
	* elf32-score7.c (s7_bfd_score_elf_size_dynamic_sections): Likewise.
	* elf32-sh.c (sh_elf_size_dynamic_sections): Likewise.
	* elf32-tic6x.c (is_tic6x_elf_unwind_section_name): Likewise.
	(elf32_tic6x_size_dynamic_sections): Likewise.
	* elf32-vax.c (elf_vax_size_dynamic_sections): Likewise.
	* elf32-xtensa.c (elf_xtensa_size_dynamic_sections): Likewise.
	(xtensa_is_insntable_section): Likewise.
	(xtensa_is_littable_section): Likewise.
	(xtensa_is_proptable_section): Likewise.
	(xtensa_property_section_name): Likewise.
	(xtensa_callback_required_dependence): Likewise.
	* elf64-alpha.c (elf64_alpha_size_dynamic_sections): Likewise.
	* elf64-hppa.c (elf64_hppa_size_dynamic_sections): Likewise.
	* elf64-ia64-vms.c (is_unwind_section_name): Likewise.
	(get_reloc_section): Likewise.
	(elf64_ia64_size_dynamic_sections): Likewise.
	(elf64_ia64_object_p): Likewise.
	* elf64-mmix.c (mmix_elf_add_symbol_hook): Likewise.
	* elf64-ppc.c (ppc64_elf_size_dynamic_sections): Likewise.
	* elf64-s390.c (elf_s390_size_dynamic_sections): Likewise.
	* elflink.c (elf_link_add_object_symbols): Likewise.
	(_bfd_elf_gc_mark_extra_sections): Likewise.
	(bfd_elf_parse_eh_frame_entries): Likewise.
	(_bfd_elf_section_already_linked): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_size_dynamic_sections): Likewise.
	* elfnn-ia64.c (is_unwind_section_name): Likewise.
	(elfNN_ia64_size_dynamic_sections): Likewise.
	(elfNN_ia64_object_p): Likewise.
	* elfxx-mips.c (FN_STUB_P): Likewise.
	(CALL_STUB_P): Likewise.
	(CALL_FP_STUB_P): Likewise.
	(_bfd_mips_elf_section_from_shdr): Likewise.
	(_bfd_mips_elf_fake_sections): Likewise.
	(_bfd_mips_elf_size_dynamic_sections): Likewise.
	(_bfd_mips_final_write_processing): Likewise.
	(_bfd_mips_elf_final_link): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_size_dynamic_sections): Likewise.
	* elfxx-x86.c (elf_i386_is_reloc_section): Likewise.
	(elf_x86_64_is_reloc_section): Likewise.
	* hpux-core.c (thread_section_p): Likewise.
	* libcoff.h (bfd_pei_p): Likewise.
	* linker.c (REAL): Likewise.
	(unwrap_hash_lookup): Likewise.
	(_bfd_generic_link_add_one_symbol): Likewise.
	* mmo.c (mmo_internal_write_section): Likewise.
	* osf-core.c (osf_core_core_file_p): Likewise.
	* pef.c (bfd_pef_print_symbol): Likewise.
	* pei-x86_64.c (pex64_print_all_pdata_sections): Likewise.
	* som.c (som_slurp_symbol_table): Likewise.
	(som_slurp_armap): Likewise.
	* wasm-module.c (wasm_compute_custom_section_file_position): Likewise.

binutils/ChangeLog:

	* dlltool.c (scan_drectve_symbols): Replace usage of CONST_STRNEQ with startswith.
	* emul_aix.c (ar_emul_aix_parse_arg): Likewise.
	* objcopy.c (is_mergeable_note_section): Likewise.
	* objdump.c (dump_dwarf_section): Likewise.
	* prdbg.c (pr_method_type): Likewise.
	(pr_class_baseclass): Likewise.
	(tg_class_baseclass): Likewise.
	* readelf.c (process_lto_symbol_tables): Likewise.
	* stabs.c (ULLHIGH): Likewise.
	(parse_stab_argtypes): Likewise.
	(stab_demangle_function_name): Likewise.

gas/ChangeLog:

	* config/tc-i386.c (md_parse_option): Replace usage of CONST_STRNEQ with startswith.
	(x86_64_section_word): Likewise.
	* config/tc-sparc.c (md_parse_option): Likewise.

gdb/ChangeLog:

	* arm-tdep.c (show_disassembly_style_sfunc): Replace usage of CONST_STRNEQ with startswith.
	(_initialize_arm_tdep): Likewise.

ld/ChangeLog:

	* emultempl/aix.em: Replace usage of CONST_STRNEQ with startswith.
	* emultempl/beos.em: Likewise.
	* emultempl/elf.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/pep.em: Likewise.
	* emultempl/xtensaelf.em: Likewise.
	* ldctor.c (ctor_prio): Likewise.
	* ldelf.c (ldelf_try_needed): Likewise.
	(ldelf_parse_ld_so_conf): Likewise.
	(ldelf_after_open): Likewise.
	(output_rel_find): Likewise.
	(ldelf_place_orphan): Likewise.
	* ldfile.c (ldfile_add_library_path): Likewise.
	* ldlang.c (lang_add_input_file): Likewise.
	* ldmain.c (get_sysroot): Likewise.
	(get_emulation): Likewise.
	(add_archive_element): Likewise.
	* ldwrite.c (unsplittable_name): Likewise.
	(clone_section): Likewise.
	* lexsup.c (parse_args): Likewise.
	* pe-dll.c (is_import): Likewise.
	(pe_implied_import_dll): Likewise.

opcodes/ChangeLog:

	* aarch64-dis.c (parse_aarch64_dis_option): Replace usage of CONST_STRNEQ with startswith.
	* arc-dis.c (parse_option): Likewise.
	* arm-dis.c (parse_arm_disassembler_options): Likewise.
	* cris-dis.c (print_with_operands): Likewise.
	* h8300-dis.c (bfd_h8_disassemble): Likewise.
	* i386-dis.c (print_insn): Likewise.
	* ia64-gen.c (fetch_insn_class): Likewise.
	(parse_resource_users): Likewise.
	(in_iclass): Likewise.
	(lookup_specifier): Likewise.
	(insert_opcode_dependencies): Likewise.
	* mips-dis.c (parse_mips_ase_option): Likewise.
	(parse_mips_dis_option): Likewise.
	* s390-dis.c (disassemble_init_s390): Likewise.
	* wasm32-dis.c (parse_wasm32_disassembler_options): Likewise.
2021-03-22 11:01:43 +01:00
Alan Modra
8ee10e8609 PR27451, -z start_stop_gc
When --gc-sections is in effect, a reference from a retained section
to __start_SECNAME or __stop_SECNAME causes all input sections named
SECNAME to also be retained, if SECNAME is representable as a C
identifier and either __start_SECNAME or __stop_SECNAME is synthesized
by the linker.  Add an option to disable that feature, effectively
ignoring any relocation that references a synthesized linker defined
__start_ or __stop_ symbol.

	PR 27451
include/
	* bfdlink.h (struct bfd_link_info): Add start_stop_gc.
bfd/
	* elflink.c (_bfd_elf_gc_mark_rsec): Ignore synthesized linker
	defined start/stop symbols when start_stop_gc.
	(bfd_elf_gc_mark_dynamic_ref_symbol): Likewise.
	(bfd_elf_define_start_stop): Don't modify ldscript_def syms.
	* linker.c (bfd_generic_define_start_stop): Likewise.
ld/
	* emultempl/elf.em: Handle -z start-stop-gc and -z nostart-stop-gc.
	* lexsup.c (elf_static_list_options): Display help for them.  Move
	help for -z stack-size to here from elf_shlib_list_options. Add
	help for -z start-stop-visibility and -z undefs.
	* ld.texi: Document -z start-stop-gc and -z nostart-stop-gc.
	* NEWS: Mention -z start-stop-gc.
	* testsuite/ld-gc/start2.s,
	* testsuite/ld-gc/start2.d: New test.
	* testsuite/ld-gc/gc.exp: Run it.
2021-03-01 17:28:03 +10:30
Alan Modra
250d07de5c Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
Vivek Das Mohapatra
c3805e4cef Document -z unique/-z nounique in the ld man page and help output
* ld.texi (Options): Document -z unique and -z nounique.
	* lexsup.c (elf_shlib_list_options): Likewise.
2020-12-15 18:45:03 +10:30
Alan Modra
8da4f428d1 PR26836, memory leak in parse_args
PR 26836
	* lexsup.c (parse_args): Free really_longopts, longopts and
	shortopts.
2020-12-14 23:36:09 +10:30
Nick Clifton
3991c7acb2 Fix a use of an uninitialised variable in the bfd linker.
PR 27050
	* lexsup.c (parse_args): Ensure that the longind local variable is
	set.
2020-12-14 12:40:13 +00:00
Nick Clifton
2c72361c81 Extend ld's -Map=<dir> functionality by allowing '%' to be replaced with the output file path.
* lexsup.c (parse_args): Add more checks of the mapfile.  If it is
	a directory use the basename of the output file as the file
	component.  If the % character is present, replace it with the
	full output filepath.
	* testsuite/ld-scripts/map-address.exp: Add test of %
	functionality.
	* ld.texi: Document the new behaviour.
2020-11-06 14:36:45 +00:00
Nick Clifton
23ae20f5e3 Add a new option to the linker: --error-handling-script=<NAME>. Run the script <NAME> if an undefined symbol or unfound library error is encountered.
PR 26626
	* ldmain.c (undefined_symbol): If an error handlign script is
	available, call it.
	* ldfile.c  (error_handling_script): Declare.
	(ldfile_open_file): If a library cannot be found and an error
	handling script is available, call it.
	* ldmain.h  (error_handling_script): Prototype.
	* ldlex.h (OPTION_ERROR_HANDLING_SCRIPT): Define.
	* lexsup.c (ld_options): Add --error-handling-script.
	(parse_args): Add support for --errror-handling-script.
	* ld.texi: Document the new feature.
	* configure.ac: Add --error-handling-script option to disable
	support for the new feature.
	* NEWS: Mention the new feature.
	* config.in: Regenerate.
	* configure: Regenerate.
2020-10-16 11:37:26 +01:00
Nick Clifton
983d925db6 Update the BFD linker so that it deprecates grouped short options.
* lexsup.c (parse_args): Generate an error or warning message when
	multiple short options are used together.
2020-10-05 13:53:59 +01:00
H.J. Lu
496afd1705 elf: Add -z unique-symbol to avoid duplicated local symbol names
The symbol string table in the .symtab section is optional and cosmetic.
The contents of the .symtab section have no impact on run-time execution.
The symbol names in the symbol string table help distinguish addresses at
different locations.  Add a linker option, -z unique-symbol, to avoid
duplicated local symbol names in the symbol string table.

This feature was well received by the livepatch maintainers.  It not only
solves the duplicated local symbol name problem, but also would allow
livepatch to more precisely locate duplicate symbols in general for
patching.

bfd/

	PR ld/26391
	* elflink.c (elf_final_link_info): Add local_hash_table.
	(local_hash_entry): New.
	(local_hash_newfunc): Likewise.
	(elf_link_output_symstrtab): Append ".COUNT" to duplicated local
	symbols.
	(bfd_elf_final_link): Initialize and free local_hash_table for
	"-z unique-symbol".

include/

	PR ld/26391
	* bfdlink.h (bfd_link_info): Add unique_symbol.

ld/

	PR ld/26391
	* NEWS: Mention "-z unique-symbol".
	* emultempl/elf.em (gld${EMULATION_NAME}_handle_option): Handle
	"-z unique-symbol" and "-z nounique-symbol".
	* ld.texi: Document "-z unique-symbol" and "-z nounique-symbol".
	* lexsup.c (elf_static_list_options): Add "-z unique-symbol" and
	"-z nounique-symbol".
	* testsuite/ld-elf/elf.exp: Add PR ld/26391 tests.
	* testsuite/ld-elf/pr26391.nd: New file.
	* testsuite/ld-elf/pr26391.out: Likewise.
	* testsuite/ld-elf/pr26391a.c: Likewise.
	* testsuite/ld-elf/pr26391b.c: Likewise.
	* testsuite/ld-elf/pr26391c.c: Likewise.
	* testsuite/ld-elf/pr26391d.c: Likewise.
2020-09-12 05:37:43 -07:00
Alan Modra
ee44c2ac7b Use xmalloc rather than malloc
As far as I can tell, the following comment is false nowadays.
/* Calls to m-alloc get turned by sed into xm-alloc.  */

Remove it, and call xmalloc.

	* ldlex.l (yy_create_string_buffer): Use xmalloc rather than malloc.
	* lexsup.c (parse_args): Likewise.
2020-08-03 10:59:38 +09:30
Nick Alcock
5dba6f05b7 ld: new options --ctf-variables and --ctf-share-types
libctf recently changed to make it possible to not emit the CTF
variables section.  Make this the default for ld: the variables section
is a simple name -> type mapping, and the names can be quite voluminous.
Nothing in the variables section appears in the symbol table, by
definition, so GDB cannot make use of them: special-purpose projects
that implement their own analogues of symbol table lookup can do so, but
they'll need to tell the linker to emit the variables section after all.

The new --ctf-variables option does this.

The --ctf-share-types option (valid values "share-duplicated" and
"share-unconflicted") allow the caller to specify the CTF link mode.
Most users will want share-duplicated, since it allows for more
convenient debugging: but very large projects composed of many decoupled
components may want to use share-unconflicted mode, which places types
that appear in only one TU into per-TU dicts.  (They may also want to
relink the CTF using the ctf_link API and cu-mapping, to make their
"components" larger than a single TU.  Right now the linker does not
expose the CU-mapping machinery.  Perhaps it should in future to make
this use case easier.)

For now, giving the linker the ability to emit share-duplicated CTF lets
us add testcases for that mode to the testsuite.

ld/
	* ldlex.h (option_values) <OPTION_CTF_VARIABLES,
	OPTION_NO_CTF_VARIABLES, OPTION_CTF_SHARE_TYPES>: New.
	* ld.h (ld_config_type) <ctf_variables, ctf_share_duplicated>:
	New fields.
	* ldlang.c (lang_merge_ctf): Use them.
	* lexsup.c (ld_options): Add ctf-variables, no-ctf-variables,
	ctf-share-types.
	(parse_args) <OPTION_CTF_VARIABLES, OPTION_NO_CTF_VARIABLES,
	OPTION_CTF_SHARE_TYPES>: New cases.
	* ld.texi: Document new options.
	* NEWS: Likewise.
2020-07-22 18:03:57 +01:00
Nick Clifton
ddc73fa987 Fix spelling mistakes in some of the binutils sub-directories.
PR 26204
gas	* config/tc-arm.c: Fix spelling mistake.
	* config/tc-riscv.c: Likewise.
	* config/tc-z80.c: Likewise.
	* po/gas.pot: Regenerate.

ld	* lexsup.c: Fix spelling mistake.
	* po/ld.pot: Regenerate.

opcodes	* arc-dis.c: Fix spelling mistake.
	* po/opcodes.pot: Regenerate.
2020-07-06 10:54:36 +01:00
H.J. Lu
4bf05d4a90 ld: Correct --dependency-file order
Change ld --help output to

  -d, -dc, -dp                Force common symbols to be defined
  --dependency-file FILE      Write dependency file

instead of

  -d, -dc                     Force common symbols to be defined
  --dependency-file FILE, -dp Write dependency file

	PR ld/26165
	* lexsup.c (ld_options): Correct --dependency-file order.
2020-06-24 06:39:03 -07:00
Alan Modra
a5aae5087c ld --help output
It's best if help message output does not contain tabs, since we don't
know tab stop settings or even if tabs are handled by the output
device.  This reverts some 2020-06-23 changes and fixes the csky help
message.

	* lexsup.c (elf_shlib_list_options): Properly format help message.
	(elf_plt_unwind_list_options): Likewise.
	* emultempl/cskyelf.em (PARSE_AND_LIST_OPTIONS): Likewise.
2020-06-24 20:00:08 +09:30
Roland McGrath
f37b21b481 PR 22843: ld, gold: Add --dependency-file option.
gold/
	* options.h (class General_options): Add --dependency-file option.
	* fileread.cc (File_read::files_read): New static variable.
	(File_read::open): Add the file to the files_read list.
	(File_read::record_file_read): New static member function.
	(File_read::write_dependency_file): New static member function.
	* fileread.h (class File_read): Declare them.
	* layout.cc (Layout::read_layout_from_file): Call record_file_read.
	(Close_task_runner::run): Call write_dependency_file if
	--dependency-file was passed.

ld/
	* NEWS: Note --dependency-file.
	* ld.texi (Options): Document --dependency-file.
	* ldlex.h (enum option_values): Add OPTION_DEPENDENCY_FILE.
	* ld.h (ld_config_type): New member dependency_file.
	* lexsup.c (ld_options, parse_args): Parse --dependency-file.
	* ldmain.c (struct dependency_file): New type.
	(dependency_files, dependency_files_tail): New static variables.
	(track_dependency_files): New function.
	(write_dependency_file): New function.
	(main): Call it when --dependency-file was passed.
	* ldfile.c (ldfile_try_open_bfd): Call track_dependency_files.
	(ldfile_open_command_file_1): Likewise.
	* ldelf.c (ldelf_try_needed): Likewise.
	* pe-dll.c (pe_implied_import_dll): Likewise.
2020-06-23 12:01:24 -07:00
Alan Modra
0381901e62 Do without ld ENABLE_PLUGINS
Instead, use BFD_SUPPORTS_PLUGINS.

	* ldfile.c: Replace uses of ENABLE_PLUGINS with BFD_SUPPORTS_PLUGINS.
	* ldlang.c: Likewise.
	* ldlang.h: Likewise.
	* ldlex.h: Likewise.
	* ldmain.c: Likewise.
	* lexsup.c: Likewise.
	* plugin.c: Wrap body of file in #if BFD_SUPPORTS_PLUGINS.
	* testplug.c: Likewise.
	* testplug2.c: Likewise.
	* testplug3.c: Likewise.
	* testplug4.c: Likewise.
	* configure.ac (ENABLE_PLUGINS): Don't define AM_CONTITIONAL.
	* Makefile.am: Remove ENABLE_PLUGINS conditionals.
	(PLUGIN_CFLAGS): Don't define.
	(PLUGIN_C, PLUGIN_H, PLUGIN_OBJECT): Likewise.  Substitute all
	uses with plugin file name.
	* configure: Regenerate.
	* Makefile.in: Regenerate.
2020-06-21 22:16:10 +09:30
Alan Modra
070558eb0d ld -plugin options when plugins are disabled
This patch makes ld accept and ignore -plugin options when configured
with --disable-plugins.  The idea is to allow using a linker built
without plugin support with a gcc built with plugin support.  Quite
obviously such a combination won't work if using LTO, but gcc has a
habit of passing a bunch of -plugin and -plugin-opt arguments to ld
even when not generating or linking LTO objects.

Why do I want to do this?  Well, it lets me and other binutils
developers answer the question as to whether plugin support breaks
binutils in some areas.  Which it does for some targets.

	* lexsup.c (ld_options): Accept -plugin and -plugin-opt when
	!ENABLE_PLUGINS.
	* testsuite/lib/ld-lib.exp (check_plugin_api_available): Adjust.
2020-06-06 11:28:08 +09:30