Commit Graph

6765 Commits

Author SHA1 Message Date
Nick Alcock
ffeece6ac2 libctf, ld: prohibit getting the size or alignment of forwards
C allows you to do only a very few things with entities of incomplete
type (as opposed to pointers to them): make pointers to them and give
them cv-quals, roughly. In particular you can't sizeof them and you
can't get their alignment.

We cannot impose all the requirements the standard imposes on CTF users,
because the deduplicator can transform any structure type into a forward
for the purposes of breaking cycles: so CTF type graphs can easily
contain things like arrays of forward type (if you want to figure out
their size or alignment, you need to chase down the types this forward
might be a forward to in child TU dicts: we will soon add API functions
to make doing this much easier).

Nonetheless, it is still meaningless to ask for the size or alignment of
forwards: but libctf didn't prohibit this and returned nonsense from
internal implementation details when you asked (it returned the kind of
the pointed-to type as both the size and alignment, because forwards
reuse ctt_type as a type kind, and ctt_type and ctt_size overlap).  So
introduce a new error, ECTF_INCOMPLETE, which is returned when you try
to get the size or alignment of forwards: we also return it when you try
to do things that require libctf itself to get the size or alignment of
a forward, notably using a forward as an array index type (which C
should never do in any case) or adding forwards to structures without
specifying their offset explicitly.

The dumper will not emit size or alignment info for forwards any more.

(This should not be an API break since ctf_type_size and ctf_type_align
could both return errors before now: any code that isn't expecting error
returns is already potentially broken.)

include/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-api.h (ECTF_INCOMPLETE): New.
	(ECTF_NERR): Adjust.

ld/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/conflicting-cycle-1.parent.d: Adjust for dumper
	changes.
	* testsuite/ld-ctf/cross-tu-cyclic-conflicting.d: Likewise.
	* testsuite/ld-ctf/forward.c: New test...
	* testsuite/ld-ctf/forward.d: ... and results.

libctf/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-types.c (ctf_type_resolve): Improve comment.
	(ctf_type_size): Yield ECTF_INCOMPLETE when applied to forwards.
	Emit errors into the right dict.
	(ctf_type_align): Likewise.
	* ctf-create.c (ctf_add_member_offset): Yield ECTF_INCOMPLETE
	when adding a member without explicit offset when this member, or
	the previous member, is incomplete.
	* ctf-dump.c (ctf_dump_format_type): Do not try to print the size of
	forwards.
	(ctf_dump_member): Do not try to print their alignment.
2021-01-05 14:53:39 +00:00
Nick Alcock
91e7ce2fd7 libctf, ld: more dumper improvements
Dump more details about the types found in data object and function info
sections (the type ID and recursive info on the type itself, but not on
its members).  Before now, this was being dumped for entries in the
variable section, but not for the closely-related function info and data
object sections, which is inconsistent and makes finding the
corresponding types in the type section unnecessarily hard.  (This also
gets rid of code in which bugs have already been found in favour of the
same code everything else in the dumper uses to dump types.)

While we're doing that, change the recursive type dumper in question to
recursively dump info on arrays' element type, just as we do for all
types that reference other types. (Arrays are not a kind of reference
type in libctf, but perhaps we should change that in future and make
ctf_type_reference return the element type.)

ld/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/array.d: Adjust for dumper changes.
	* testsuite/ld-ctf/data-func-conflicted.d: Likewise.
	* testsuite/ld-ctf/diag-cttname-null.d: Likewise.
	* testsuite/ld-ctf/diag-cuname.d: Likewise.
	* testsuite/ld-ctf/diag-parlabel.d: Likewise.
	* testsuite/ld-ctf/function.d: Likewise.
	* testsuite/ld-ctf/slice.d: Likewise.

libctf/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-dump.c (ctf_dump_objts): Dump by calling ctf_dump_format_type.
	(ctf_dump_format_type): Don't emit the size for function objects.
	Dump the element type of arrays like we dump the pointed-to type of
	pointers, etc.
2021-01-05 14:53:39 +00:00
Nick Alcock
57f97d0e6d libctf, ld: CTF dumper changes for consistency
In most places in CTF dumper output, we emit 0x... for hex strings, but
in three places (top-level type IDs, string table offsets, and the file
magic number) we don't emit the 0x.

This is very confusing if by chance there are no hex digits in the
output.  Add 0x consistently to everything, and adjust tests
accordingly.  While we're at it, improve the indentation of the output
so that subsequent lines in aggregate output are indented by at least as
many columns as the colon in the type output.  (Subsequent indentation
is still 4 spaces at a time.)

ld/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/array.d: Adjust for dumper changes.
	* testsuite/ld-ctf/conflicting-cycle-1.B-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-1.B-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-1.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.A-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.A-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.C-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.C-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-enums.d: Likewise.
	* testsuite/ld-ctf/conflicting-typedefs.d: Likewise.
	* testsuite/ld-ctf/cross-tu-cyclic-conflicting.d: Likewise.
	* testsuite/ld-ctf/cross-tu-cyclic-nonconflicting.d: Likewise.
	* testsuite/ld-ctf/cross-tu-into-cycle.d: Likewise.
	* testsuite/ld-ctf/cross-tu-noncyclic.d: Likewise.
	* testsuite/ld-ctf/cycle-1.d: Likewise.
	* testsuite/ld-ctf/cycle-2.A.d: Likewise.
	* testsuite/ld-ctf/cycle-2.B.d: Likewise.
	* testsuite/ld-ctf/cycle-2.C.d: Likewise.
	* testsuite/ld-ctf/data-func-conflicted.d: Likewise.
	* testsuite/ld-ctf/diag-cttname-null.d: Likewise.
	* testsuite/ld-ctf/diag-cuname.d: Likewise.
	* testsuite/ld-ctf/diag-parlabel.d: Likewise.
	* testsuite/ld-ctf/diag-wrong-magic-number-mixed.d: Likewise.
	* testsuite/ld-ctf/function.d: Likewise.
	* testsuite/ld-ctf/slice.d: Likewise.
	* testsuite/ld-ctf/super-sub-cycles.d: Likewise.

libctf/ChangeLog
2021-01-05  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-dump.c (ctf_dump_format_type): Add 0x to hex type IDs.
	(ctf_dump_header): Add 0x to the hex magic number.
	(ctf_dump_str): Add 0x to the hex string offsets.
	(ctf_dump_membstate_t) <cdm_toplevel_indent>: New.
	(ctf_dump_type): Adjust.  Free it when we're done.
	(type_hex_digits): New.
	(ctf_dump_member): Align output depending on the width of the type
	ID being generated.  Use printf padding, not a loop, to generate
	indentation.
2021-01-05 14:53:39 +00:00
Alan Modra
b281a04ff0 ld sysroot-prefix test fails
* testsuite/ld-scripts/sysroot-prefix.exp: Exclude some targets.
2021-01-05 23:09:05 +10:30
Alan Modra
40b119304e Re: elf: Allow mixed ordered/unordered inputs for non-relocatable link
PR ld/26256
	* testsuite/ld-elf/pr26256-1b.d: xfail s12z.
	* testsuite/ld-scripts/crossref.exp (cross1): Don't xfail ia64.
2021-01-05 15:47:06 +10:30
H.J. Lu
cd6d537c48 elf: Allow mixed ordered/unordered inputs for non-relocatable link
For non-relocatable link with SHF_LINK_ORDER inputs, allow mixed indirect
and data inputs with ordered and unordered inputs:

1. Add pattern to bfd_section for the matching section name pattern in
linker script and update BFD_FAKE_SECTION.
2. Sort the consecutive bfd_indirect_link_order sections with the same
pattern to allow linker script to overdide input section order.
3. Place unordered sections before ordered sections.
4. Change the offsets of the indirect input sections only.

bfd/

	PR ld/26256
	* elflink.c (compare_link_order): Place unordered sections before
	ordered sections.
	(elf_fixup_link_order): Add a link info argument.  Allow mixed
	ordered and unordered input sections for non-relocatable link.
	Sort the consecutive bfd_indirect_link_order sections with the
	same pattern.  Change the offsets of the bfd_indirect_link_order
	sections only.
	(bfd_elf_final_link): Pass info to elf_fixup_link_order.
	* section.c (bfd_section): Add pattern.
	(BFD_FAKE_SECTION): Initialize pattern to NULL.
	* bfd-in2.h: Regenerated.

gas/

	PR ld/26256
	* config/obj-elf.c (obj_elf_change_section): Also filter out
	SHF_LINK_ORDER.

ld/

	PR ld/26256
	* ldlang.c (gc_section_callback): Set pattern.
	* testsuite/ld-elf/pr26256-1.s: New file.
	* testsuite/ld-elf/pr26256-1.t: Likewise.
	* testsuite/ld-elf/pr26256-1a.d: Likewise.
	* testsuite/ld-elf/pr26256-1b.d: Likewise.
	* testsuite/ld-elf/pr26256-2.s: Likewise.
	* testsuite/ld-elf/pr26256-2.t: Likewise.
	* testsuite/ld-elf/pr26256-2a.d: Likewise.
	* testsuite/ld-elf/pr26256-2b-alt.d: Likewise.
	* testsuite/ld-elf/pr26256-2b.d: Likewise.
	* testsuite/ld-elf/pr26256-3.s: Likewise.
	* testsuite/ld-elf/pr26256-3a.d: Likewise.
	* testsuite/ld-elf/pr26256-3a.t: Likewise.
	* testsuite/ld-elf/pr26256-3b.d: Likewise.
	* testsuite/ld-elf/pr26256-3b.t: Likewise.
2021-01-04 12:38:05 -08:00
Alan Modra
5b4293ba3c PR26822, How to prevent a STT_FILE with absolute path in the linked image
bfd/
	PR 26822
	* elflink.c (elf_link_input_bfd): Use the file base name in
	linker generated STT_FILE symbols.
ld/
	PR 26822
	* testsuite/ld-arm/non-contiguous-arm2.d: Adjust STT_FILE symbol match.
	* testsuite/ld-arm/non-contiguous-arm3.d: Likewise.
	* testsuite/ld-arm/non-contiguous-arm5.d: Likewise.
	* testsuite/ld-arm/non-contiguous-arm6.d: Likewise.
	* testsuite/ld-i386/tlsbin.rd: Likewise.
	* testsuite/ld-i386/tlsbin2.rd: Likewise.
	* testsuite/ld-i386/tlsbindesc.rd: Likewise.
	* testsuite/ld-i386/tlsdesc.rd: Likewise.
	* testsuite/ld-i386/tlsnopic.rd: Likewise.
	* testsuite/ld-i386/tlspic.rd: Likewise.
	* testsuite/ld-i386/tlspic2.rd: Likewise.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64.d: Likewise.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d: Likewise.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32.d: Likewise.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d: Likewise.
	* testsuite/ld-plugin/pr17973.d: 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-app-1.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/shlib-app-1rb.rd: Likewise.
	* testsuite/ld-tic6x/shlib-noindex.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1b.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1r.rd: Likewise.
	* testsuite/ld-tic6x/static-app-1rb.rd: Likewise.
	* testsuite/ld-x86-64/tlsbin.rd: Likewise.
	* testsuite/ld-x86-64/tlsbin2.rd: Likewise.
	* testsuite/ld-x86-64/tlsbindesc.rd: Likewise.
	* testsuite/ld-x86-64/tlsdesc.rd: Likewise.
	* testsuite/ld-x86-64/tlspic.rd: Likewise.
	* testsuite/ld-x86-64/tlspic2.rd: Likewise.
	* testsuite/ld-xtensa/tlsbin.rd: Likewise.
	* testsuite/ld-xtensa/tlspic.rd: Likewise.
2021-01-04 18:58:15 +10:30
Alan Modra
f9a6a8f09d PR27116, Spelling errors found by Debian style checker
PR 27116
bfd/
	* xcofflink.c: Correct spelling in comments.
binutils/
	* coffgrok.c (do_type): Correct spelling of auxiliary in errors.
	* doc/binutils.texi: Correct grammar.
	* readelf.c (process_version_sections): Correct spelling of auxiliary
	in warning.
	* testsuite/binutils-all/vax/objdump.exp: Comment grammar fix.
config/
	* override.m4: Correct comment grammar.
gas/
	* config/tc-i386.c: Correct comment spelling.
	* config/tc-riscv.c: Likewise.
	* config/tc-s390.c: Correct comment grammar.
	* doc/c-i386.texi: Correct spelling.
	* doc/c-s390.texi: Correct grammar.
gold/
	* tilegx.cc: Correct comment spelling.
gprof/
	* README: Correct grammar.
	* gprof.texi: Likewise.
include/
	* coff/internal.h: Correct comment spelling.
	* coff/sym.h: Likewise.
	* opcode/aarch64.h: Likewise.
ld/
	* configure.tgt: Correct comment grammar.
	* emultempl/m68hc1xelf.em: Likewise.
	* ld.texi: Correct grammar.
2021-01-01 14:36:35 +10:30
Alan Modra
250d07de5c Update year range in copyright notice of binutils files 2021-01-01 10:31:05 +10:30
Alan Modra
c2795844e6 ChangeLog rotation 2021-01-01 10:31:02 +10:30
Alan Modra
cab3f4da68 PR27128, nm -P portable output format regression
binutils/
	PR 27128
	* nm.c (print_symname): Append version string to symbol name
	before printing the lot under control of "form".  Append version
	to demangled names too.
ld/
	PR 27128
	* testsuite/ld-elf/pr27128.s: New file.
	* testsuite/ld-elf/pr27128.t: Likewise.
	* testsuite/ld-elf/pr27128a.d: Likewise.
	* testsuite/ld-elf/pr27128b.d: Likewise.
	* testsuite/ld-elf/pr27128c.d: Likewise.
	* testsuite/ld-elf/pr27128d.d: Likewise.
	* testsuite/ld-elf/pr27128e.d: Likewise.
2020-12-31 19:07:02 +10:30
Alan Modra
99d8bab0c1 SHF_GNU_RETAIN 7a and 7b tests
* testsuite/ld-elf/retain7a.d: Don't run on hppa-linux.
	* testsuite/ld-elf/retain7b.d: Correct name.  Don't run on tic6x.
	Allow OSABI FreeBSD.
2020-12-24 22:58:14 +10:30
Alan Modra
de34d42812 PR27100, final link failed: bad value
The failure on this PR is due to using the same bfd section for
multiple output sections.  Commit 21401fc7bf managed to create
duplicate linker script output section statements, but not the actual
bfd sections.

	PR 27100
	* ldlang.h (lang_output_section_statement_type): Add dup_output.
	* ldlang.c (lang_output_section_statement_lookup): Set dup_output.
	(init_os): Test dup_output rather than constraint.
	* testsuite/ld-scripts/pr27100.d,
	* testsuite/ld-scripts/pr27100.s,
	* testsuite/ld-scripts/pr27100.t: New test.
	* testsuite/ld-scripts/data.exp: Run it.  Don't exclude aout here.
	* testsuite/ld-scripts/data.d: Do so here instead.
	* testsuite/ld-scripts/fill.d: Likewise.
	* testsuite/ld-scripts/fill16.d: Likewise.
2020-12-24 22:58:03 +10:30
H.J. Lu
279d901e5a x86-64: Add Intel LAM property support
Add Intel Linear Address Masking (LAM) property support.  LAM modifies
the checking that is applied to 64-bit linear addresses, allowing
software to use of the untranslated address bits for metadata.

bfd/

	* elf-linker-x86.h (elf_x86_cet_report): Renamed to ...
	(elf_x86_prop_report): This.
	(elf_linker_x86_params): Add lam_u48, lam_u57, lam_u48_report
	and lam_u57_report.
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Support
	GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
	GNU_PROPERTY_X86_FEATURE_1_LAM_U57.
	(_bfd_x86_elf_link_fixup_gnu_properties): Keep LAM features only
	for 64-bit output.

binutils/

	* NEWS: Mention LAM_U48 and LAM_U57 support.
	* elfedit.c (elf_x86_feature): Support lam_u48 and lam_u57.
	(usage): Add lam_u48 and lam_u57.
	* readelf.c (decode_x86_feature_1): Support LAM_U48 and LAM_U57.
	* doc/binutils.texi: Update elfedit with lam_u48 and lam_u57
	support.
	* testsuite/binutils-all/x86-64/lam-u48.d: New file.
	* testsuite/binutils-all/x86-64/lam-u48.s: Likewise.
	* testsuite/binutils-all/x86-64/lam-u57.d: Likewise.
	* testsuite/binutils-all/x86-64/lam-u57.s: Likewise.

include/

	* elf/common.h (GNU_PROPERTY_X86_FEATURE_1_LAM_U48): New.
	(GNU_PROPERTY_X86_FEATURE_1_LAM_U57): Likewise.

ld/

	* NEWS: Mention LAM_U48 and LAM_U57 support.
	* ld.texi: Document LAM_U48 and LAM_U57 support.
	* emulparams/cet.sh: Updated.
	* emulparams/elf_x86_64.sh: Source x86-64-lam.sh.
	* emulparams/x86-64-lam.sh: New file.
	* testsuite/ld-x86-64/property-x86-lam-u48-1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48-5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u48.s: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-1a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-1b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-2.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-3a.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-3b.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-4.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57-5.d: Likewise.
	* testsuite/ld-x86-64/property-x86-lam-u57.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run LAM tests.
2020-12-23 13:00:55 -08:00
H.J. Lu
eba7b68cb0 ld: Build and install only unversioned libdep
Build only unversioned libdep and remove the installed libdep.la since
only a single libdep.so is needed.

	PR ld/27082
	* Makefile.am
	(libdep_la_LDFLAGS): Add -module -avoid-version.
	(libdep_la_LINK): New.
	(install-data-local): Depend on $(install-bfdpluginLTLIBRARIES)
	and remove libdep.la.
2020-12-18 04:30:59 -08:00
H.J. Lu
04f8967487 elf: Copy elf_gnu_osabi_retain only for relocatable link
Copy elf_gnu_osabi_retain from input only for relocatable link since
SHF_GNU_RETAIN has no impact on non-relocatable outputs.

bfd/

	PR ld/27091
	* elflink.c (elf_link_input_bfd): Copy elf_gnu_osabi_retain
	from input only for relocatable link.

ld/

	PR ld/27091
	* testsuite/ld-elf/retain7.s: New file.
	* testsuite/ld-elf/retain7a.d: Likewise.
	* testsuite/ld-elf/retain7b.d: Likewise.
2020-12-18 04:24:36 -08:00
H.J. Lu
bcac599f73 ld: Skip libdep plugin if not all plugin hooks are available
Skip plugin if not all required plugin hooks are available.

2020-12-16  Howard Chu <hyc@symas.com>
	    H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/27081
	* libdep_plugin.c (onload): Skip if not all required plugin hooks
	are available.
	* testsuite/config/default.exp (dep_plug_opt): New.
	* testsuite/ld-elf/elf.exp: Pass $dep_plug_opt to nm.
	* testsuite/ld-elf/pr26391.fd: New file.
2020-12-16 13:40:51 -08:00
Alan Modra
c410035d37 constify elfNN_bed
elfNN_bed was made writable as an expedient means of communicating
ld -z max-page-size and ld -z common-page-size values to BFD linker
code, and even for objcopy to communicate segment alignment between
copy_private_bfd_data, rewrite_elf_program_header and
assign_file_positions_for_load_sections.  Some time later elfNN_bed
elf_osabi was written by gas.  It turns out none of these
modifications to elfNN_bed was necessary, so make it const again.

include/
	* bfdlink.h (struct bfd_link_info): Add maxpagesize and
	commonpagesize.
bfd/
	* elfxx-target.h (elfNN_bed): Constify.
	* bfd.c (bfd_elf_set_pagesize): Delete.
	(bfd_emul_set_maxpagesize, bfd_emul_set_commonpagesize): Delete.
	* elf.c (get_program_header_size): Get commonpagesize from
	link info.
	(_bfd_elf_map_sections_to_segments): Get maxpagesize from link info.
	(assign_file_positions_for_load_sections): Likewise.
	(assign_file_positions_for_non_load_sections): Likewise.
	(rewrite_elf_program_header): Add maxpagesize param.  Set map_p_align.
	(copy_private_bfd_data): Don't call bfd_elf_set_maxpagesize.
	Instead pass maxpagesize to rewrite_elf_program_header.
	* elf32-nds32.c (relax_range_measurement): Add link_info param.
	Get maxpagesize from link_info.  Adjust caller.
	* bfd-in2.h: Regenerate.
gas/
	* config/obj-elf.c (obj_elf_section): Don't set elf_osabi here.
	(obj_elf_type): Likewise.
ld/
	* ld.h (ld_config_type): Delete maxpagesize and commonpagesize.
	* emultempl/elf.em: Use link_info rather than config
	for maxpagesize and commonpagesize.
	* emultempl/ppc32elf.em: Likewise.
	* ldexp.c (fold_binary, fold_name): Likewise.
	* ldemul.c (after_parse_default): Likewise.
	(set_output_arch_default): Don't call bfd_emul_set_maxpagesize
	or bfd_emul_set_commonpagesize.
2020-12-16 15:17:53 +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
Vivek Das Mohapatra
6a0a0dd0cc Handle -z unique/-z nounique in ld
Add (or suppress) a DT_GNU_FLAGS_1 dynamic section
with a bit flag value of DF_GNU_1_UNIQUE.

bfd/
	* elflink.c (bfd_elf_size_dynamic_sections): Call
	_bfd_elf_add_dynamic_entry to add a DT_GNU_FLAGS_1 section.
include/
	* bfdlink.h (struct bfd_link_info): New field gnu_flags_1.
ld/
	* emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
	Parse -z unique / -z nounique options.
2020-12-15 18:44:56 +10:30
Howard Chu
bf6d803782 Add a plugin for processing static library dependencies.
* libdep_plugin.c: New file: Processes archives that contain a
	special library dependencies element.
	* Makefile.am: Add build rules for libdep_plugin.
	* Makefile.in: Regenerate.
	* NEWS: Mention the new plugin.
	* ld.texi: Document the new plugin.
2020-12-14 14:26:11 +00:00
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
Alan Modra
6abe7848fa Solaris 11.4 ld build failure
/usr/include/sys/mman.h:81:0: note: this is the location of the previous definition
 #define SHARED  0x10

	PR 27064
	* deffilep.y (SHARED_K): Rename from SHARED.  Update uses.
2020-12-14 14:05:05 +10:30
Maciej W. Rozycki
0fcf331bb1 VAX/BFD: Do not warn about GOT addend mismatches if no GOT entry is made
Match the condition used in `elf_vax_instantiate_got_entries' for the
creation of GOT entries in the processing of R_VAX_GOT32 relocations in
`elf_vax_check_relocs', removing incorrect warnings about a GOT addend
mismatch like:

./ld-new: tmpdir/got-local-ref-off-r.o: warning: GOT addend of 1 to `bar_hidden' does not match previous GOT addend of 0
./ld-new: tmpdir/got-local-ref-off-r.o: warning: GOT addend of 2 to `bar_hidden' does not match previous GOT addend of 0

and corresponding failures with the test cases newly added here:

FAIL: GOT test (executable hidden reference with offset)
FAIL: GOT test (executable visible reference with offset)

for symbols that are considered local for reasons other than having been
forced local with a version script, which is usually the ELF visibility.
Correct code is produced regardless, but the warning breaks `-Werror'
compilation and may upset people regardless.

Interestingly this shows with executable links only, because in shared
library links code from `elf_link_add_object_symbols' triggers:

	    /* If the symbol already has a dynamic index, but
	       visibility says it should not be visible, turn it into
	       a local symbol.  */
	    switch (ELF_ST_VISIBILITY (h->other))
	      {
	      case STV_INTERNAL:
	      case STV_HIDDEN:
		(*bed->elf_backend_hide_symbol) (info, h, TRUE);
		dynsym = FALSE;
		break;
	      }

that sets `h->forced_local' like with a version script.

Add suitable test cases including disassembly to verify correct code has
been produced where no warnings have been issued, and that warnings do
get issued where necessary.  Do not verify (broken) code produced in the
latter case; we should probably make the warning an error, or preferably
actually start supporting GOT references with different addends as they
appear feasible with explicitly relocated GOT that we use.

	bfd/
	* elf32-vax.c (elf_vax_check_relocs) <R_VAX_GOT32>: Use
	SYMBOL_REFERENCES_LOCAL rather than `h->forced_local' to check
	whether the symbol referred is local or not.

	ld/
	* testsuite/ld-vax-elf/got-local-exe-off-hidden.dd: New test
	dump.
	* testsuite/ld-vax-elf/got-local-exe-off-visible.dd: New test
	dump.
	* testsuite/ld-vax-elf/got-local-lib-off-hidden.dd: New test
	dump.
	* testsuite/ld-vax-elf/got-local-lib-off-visible.ed: New test
	dump.
	* testsuite/ld-vax-elf/got-local-off-external.ed: New test dump.
	* testsuite/ld-vax-elf/got-local-exe-off.xd: New test dump.
	* testsuite/ld-vax-elf/got-local-lib-off.xd: New test dump.
	* testsuite/ld-vax-elf/got-local.ld: New test linker script.
	* testsuite/ld-vax-elf/got-local-aux-off.s: New test source.
	* testsuite/ld-vax-elf/got-local-def-off.s: New test source.
	* testsuite/ld-vax-elf/got-local-ref-off-external.s: New test
	source.
	* testsuite/ld-vax-elf/got-local-ref-off-hidden.s: New test
	source.
	* testsuite/ld-vax-elf/got-local-ref-off-visible.s: New test
	source.
	* testsuite/ld-vax-elf/vax-elf.exp: Run the new tests.
2020-12-05 11:18:14 +00:00
H.J. Lu
7e45e7a9ab x86-64: Convert load to mov only for GOTPCRELX relocations
Since converting load to mov needs to rewrite the REX byte and we don't
know if there is a REX byte with GOTPCREL relocation, do it only for
GOTPCRELX relocations.

bfd/

	PR ld/27016
	* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Convert load
	to mov only for GOTPCRELX relocations.

ld/

	PR ld/27016
	* testsuite/ld-x86-64/x86-64.exp: Run pr27016a and pr27016b.
	* testsuite/ld-x86-64/pr27016a.d: New file.
	* testsuite/ld-x86-64/pr27016a.s: Likewise.
	* testsuite/ld-x86-64/pr27016b.d: Likewise.
	* testsuite/ld-x86-64/pr27016b.s: Likewise.
2020-12-04 18:54:47 -08:00
Alan Modra
726d7d1ecf PR26978, Inconsistency for strong foo@v1 and weak foo@@v1
Prior to this patch
  ld -shared --version-script=pr26979.ver pr26978a.o pr26978b.o
results in
  ld: pr26978b.o: in function `foo_v1':
  (.text+0x0): multiple definition of `foo@v1'
  ld: pr26978b.o:(*IND*+0x0): multiple definition of `foo'
while
  ld -shared --version-script=pr26979.ver pr26978b.o pr26978a.o
results in no error, but some odd dynamic symbols.
  ... 0 NOTYPE  GLOBAL DEFAULT    7 foo@v1
  ... 0 NOTYPE  WEAK   DEFAULT    7 foo@@v1

When linking an undecorated reference to foo against such a shared
library, ld complains about multiple definitions of foo@v1 while gold
creates a dynamic reference to foo@v1.  That results in foo@v1 being
used at runtime.

While we could error in both cases, it is reasonable to say foo@v1 and
foo@@v1 are in fact the same symbol.  (Same name, same version.  The
only real difference is that foo@@v1 satisfies a reference to plain
foo, while foo@v1 does not.)  Just as merging a weak undecorated sym
with a strong sym results in the strong sym prevailing, so should the
strong foo@v1 prevail.  And since there is a definition that satisfies
plain foo, the foo@@v1 variety of dynamic symbol should be emitted at
the foo@v1 value.  That makes the testcase that currently links
continue to produce a shared library, and that shared library can now
be used by both ld and gold with the same runtime behaviour as when
using gold with the odd dynamic symbol library.

bfd/
	PR 26978
	* elflink.c (_bfd_elf_add_default_symbol): Handle the case where
	a new weak sym@@ver should be overridden by an existing sym@ver.
	(elf_link_add_object_symbols): Don't _bfd_elf_add_default_symbol
	for a new weak sym@ver when sym@@ver already exists.
	* linker.c (link_action): Choose MIND for previous indirect,
	current def, rather than MDEF.
	(_bfd_generic_link_add_one_symbol <MIND>): Handle redefinition of
	weak indirect symbol.
ld/
	* testsuite/ld-elf/pr26978a.d,
	* testsuite/ld-elf/pr26978a.s,
	* testsuite/ld-elf/pr26978b.d,
	* testsuite/ld-elf/pr26978b.s: New tests.
2020-12-04 11:06:52 +10:30
Andreas Krebbel
b10b530a45 IBM Z: Add support for HLASM extended mnemonics
Add extended mnemonics used in the HLASM assembler.  All of them are
just aliases for instructions we already support and help when
assembling code which was written for the HLASM assembler.

The HLASM mnemonics are documented here:
https://www.ibm.com/support/knowledgecenter/SSENW6_1.6.0/com.ibm.hlasm.v1r6.asm/asmr1023.pdf

See the 'Branching with extended mnemonic codes' chapter.

objdump will still print the existing mnemonics with the exception of
relative nop branches (i.e. conditional branches with an empty
condition code mask).  Now we have jnop and jgnop which will be used
by objdump when possible.

The same change have been applied to the LLVM assembler:
https://reviews.llvm.org/D92185

opcodes/

	* s390-opc.txt: Add extended mnemonics.

gas/

	* testsuite/gas/s390/esa-g5.s: Test new extended mnemonics.
	* testsuite/gas/s390/esa-g5.d: Likewise.
	* testsuite/gas/s390/esa-z900.s: Likewise.
	* testsuite/gas/s390/esa-z900.d: Likewise.
	* testsuite/gas/s390/zarch-z900.s: Likewise.
	* testsuite/gas/s390/zarch-z900.d: Likewise.

ld/

	* testsuite/ld-s390/tlsbin_64.dd: The newly added jgnop mnemonic
	replaces long relative branches with empty condition code mask.
2020-12-03 16:51:12 +01:00
Maciej W. Rozycki
9a5c1ed81d VAX/LD/testsuite: Wrap excessively long lines
A couple of lines in the vax-elf.exp test script exceed 80 characters;
wrap them.

	ld/
	* testsuite/ld-vax-elf/vax-elf.exp: Wrap excessively long lines
	throughout.
2020-12-03 13:27:45 +00:00
Hans-Peter Nilsson
5f410aa50c testsuite/ld-elf/pr26936.d: Pass -W.
Required for the expected "CU:" to be emitted for long
source-paths.  See binutils/dwarf.c:

 if (do_wide || strlen (directory) < 76)
   printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
 else
   printf ("%s:\n", file_table[0].name);
2020-12-02 21:53:42 +01:00
H.J. Lu
3ed3c10425 arc: Enable -Ttext-segment
Define TEXT_START_ADDR and SHLIB_TEXT_START_ADDR with SEGMENT_START to
enable -Ttext-segment.

	PR ld/26970
	* scripttempl/elfarc.sc (TEXT_START_ADDR): New.  Add SEGMENT_START.
	(SHLIB_TEXT_START_ADDR): Likewise.
2020-12-01 04:27:41 -08:00
Alan Modra
56af5a30b8 tic6x elf testsuite fix
* testsuite/ld-elf/elf.exp: Set ASFLAGS for tic6x.
	* testsuite/ld-elf/reloc-discard.d: Remove tic6x xfail.
2020-12-01 11:26:58 +10:30
Alan Modra
5160d0f323 PR26979, Visibility of undefined foo@v1 should constrain foo@@v1
Also, undefined foo should constrain the visibility of foo@@v1 just as
it does for a later plain foo definition.

bfd/
	PR 26979
	* elf-bfd.h (elf_backend_merge_symbol_attribute): Update prototype.
	* elf32-m68hc1x.h (elf32_m68hc11_merge_symbol_attribute): Likewise.
	* elfxx-mips.h (_bfd_mips_elf_merge_symbol_attribute): Likewise.
	* elfxx-x86.h (_bfd_x86_elf_merge_symbol_attribute): Likewise.
	* elf32-m68hc1x.c (elf32_m68hc11_merge_symbol_attribute): Replace
	isym parameter with st_other.  Adjust code.
	* elf64-alpha.c (elf64_alpha_merge_symbol_attribute): Likewise.
	* elf64-ppc.c (ppc64_elf_merge_symbol_attribute): Likewise.
	* elfnn-aarch64.c (elfNN_aarch64_merge_symbol_attribute): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_merge_symbol_attribute): Likewise.
	* elfxx-x86.c (_bfd_x86_elf_merge_symbol_attribute): Likewise.
	* elflink.c (elf_merge_st_other): Likewise.
	(_bfd_elf_merge_symbol, elf_link_add_object_symbols): Adjust to suit.
	(_bfd_elf_copy_link_hash_symbol_type): Likewise.
	(_bfd_elf_add_default_symbol): Merge st_other from undecorated
	symbol and @VER symbol to @@VER symbol.
ld/
	* testsuite/ld-elf/pr26979a.s,
	* testsuite/ld-elf/pr26979b.s,
	* testsuite/ld-elf/pr26979c.s,
	* testsuite/ld-elf/pr26979.ver,
	* testsuite/ld-elf/pr26979a.d,
	* testsuite/ld-elf/pr26979b.d: New tests.
2020-12-01 11:26:35 +10:30
H.J. Lu
15eb8c2d92 ld: Xfail PR ld/26936 test if not supported
Linkonce sections and comdat groups can be mixed only if comdat groups
have only a single member with matching symbol table entries.  Xfail
ld/26936 test:

1. If comdat groups always have more than one member.
2. If symbol table entries in linkonce and comdat group don't match.
3. If the assembly source file is renamed.

	PR ld/26936
	* testsuite/ld-elf/pr26936.d: Xfail targets which don't support
	mixing linkonce and comdat sections.
2020-11-30 05:21:51 -08:00
Alan Modra
8d748d1dc5 PR26907, segment contains empty SHT_NOBITS section
Section ordering is important for _bfd_elf_map_sections_to_segments
and assign_file_positions_for_load_sections, which are only prepared
to handle sections in increasing LMA order.  When zero size sections
are involved it is possible to have multiple sections at the same LMA.
In that case the zero size sections must sort before any non-zero size
sections regardless of their types.

bfd/
	PR 26907
	* elf.c (elf_sort_sections): Don't sort zero size !load sections
	after load sections.
ld/
	* testsuite/ld-elf/pr26907.ld,
	* testsuite/ld-elf/pr26907.s,
	* testsuite/ld-elf/pr26907.d: New test.
2020-11-28 18:31:32 +10:30
Jozef Lawrynowicz
2c6f3e56cb ELF: Support .noinit and .persistent sections
The ".persistent" section is for data that should be initialized during
load, but not during application reset.

The ".noinit" section is for data that should not be initialized during
load or application reset.

Targets utilizing the elf.sc linker script template can define
HAVE_{NOINIT,PERSISTENT}=yes to include the .noinit or .persistent
output sections in the generated linker script.

Targets with existing support for .noinit did not handle unique
.noinit.* and .gnu.linkonce.n.* sections the .noinit output section,
this patch also fixes that.

bfd/ChangeLog:

	* elf.c (special_sections_g): Add .gnu.linkonce.n and .gnu.linkonce.p.
	(special_sections_n): Add .noinit.
	(special_sections_p): Add .persistent.

binutils/ChangeLog:

	* testsuite/lib/binutils-common.exp (supports_noinit_section): New.
	(supports_persistent_section): New.

gas/ChangeLog:

	* testsuite/gas/elf/elf.exp: Run new tests.
	* testsuite/gas/elf/section25.d: New test.
	* testsuite/gas/elf/section25.s: New test.
	* testsuite/gas/elf/section26.d: New test.
	* testsuite/gas/elf/section26.s: New test.

ld/ChangeLog:

	* emulparams/armelf.sh (OTHER_SECTIONS): Remove .noinit section
	definition.
	Define HAVE_{NOINIT,PERSISTENT}=yes.
	* scripttempl/avr.sc (.noinit): Add .noinit.* and .gnu.linkonce.n.*
	input section wildcard patterns.
	* scripttempl/elf.sc: Define .noinit and .persistent sections when
	HAVE_NOINIT or HAVE_PERSISTENT are defined to "yes".
	* scripttempl/elf32msp430.sc (.noinit): Add .noinit.* and
	.gnu.linkonce.n.*. input section wildcard patterns.
	(.persistent): Add .persistent.* and
	.gnu.linkonce.p.*. input section wildcard patterns.
	* scripttempl/elfarcv2.sc (.noinit): Add .noinit.* and
	.gnu.linkonce.n.*. input section wildcard patterns.
	* scripttempl/pru.sc: Likewise.
	* testsuite/ld-elf/noinit-sections-1.d: New test.
	* testsuite/ld-elf/noinit-sections-2.d: New test.
	* testsuite/ld-elf/noinit-sections-2.l: New test.
	* testsuite/ld-elf/noinit-sections.s: New test.
	* testsuite/ld-elf/persistent-sections-1.d: New test.
	* testsuite/ld-elf/persistent-sections-2.d: New test.
	* testsuite/ld-elf/persistent-sections-2.l: New test.
	* testsuite/ld-elf/persistent-sections.s: New test.
2020-11-27 10:45:35 +00:00
Alan Modra
9ed0136bff PR26936 testsuite fixes
Many targets fail this test due to -z noseparate-code not being
supported, or _start not being the proper entry symbol, or "as -g"
something other than "generate debug".

	PR 26936
	* testsuite/ld-elf/pr26936.d: Pass --gen-debug to gas rather than -g.
	Only run when -shared -z options are supported.
	* testsuite/ld-elf/pr26936b.s: Define more entry symbols.
2020-11-26 18:40:10 +10:30
H.J. Lu
58349d00f4 elf: Get the real kept section
When mixing linkonce and comdat sections, we need to keep searching to
get the real kept section.

bfd/

	PR ld/26936
	* elflink.c (_bfd_elf_check_kept_section): Get the real kept
	section.

ld/

	PR ld/26936
	* testsuite/ld-elf/pr26936.d: New file.
	* testsuite/ld-elf/pr26936a.s: Likewise.
	* testsuite/ld-elf/pr26936b.s: Likewise.
	* testsuite/ld-elf/pr26936c.s: Likewise.
2020-11-25 16:14:29 -08:00
Alan Modra
21401fc7bf Duplicate output sections in scripts
Previously, ld merged duplicate output sections if such existed in
scripts, except for those with a constraint of SPECIAL.  This makes
scripts with duplicate output section statements create duplicate
output sections in the linker output file.

	* ldlang.c (lang_output_section_statement_lookup): Change "create"
	parameter to a tristate, if 2 then always create a new output
	section statement.  Update all callers, with
	lang_enter_output_section_statement using "2".
	(map_input_to_output_sections): Don't ignore SPECIAL constraint
	here.
	* ldlang.h (lang_output_section_statement_type): Update prototype.
	(lang_output_section_find): Update.
2020-11-25 19:13:51 +10:30
H.J. Lu
d0089f12f6 ld/x86-64: Add PR gold/26939 tests
GOTPCRELX relocations can be transformed only when addend == -4.  Add
tests for GOTPCRELX relocations with addend != -4.

	PR gold/26939
	* testsuite/ld-x86-64/pr26939-x32.d: New file.
	* testsuite/ld-x86-64/pr26939.d: Likewise.
	* testsuite/ld-x86-64/pr26939.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run PR gold/26939 tests.
2020-11-24 11:32:26 -08:00
H.J. Lu
cbf097d7b0 s390x: Set .got sh_entsize only if .got size > 0
bfd/

	PR ld/26918
	* elf64-s390.c (elf_s390_finish_dynamic_sections): Set .got
	sh_entsize only if .got size > 0.

ld:

	PR ld/26918
	* testsuite/ld-s390/pr26918-1.d: New file.
	* testsuite/ld-s390/pr26918-1.s: Likewise.
	* testsuite/ld-s390/s390.exp: Run all *.d tests.
2020-11-23 05:13:55 -08:00
Shahab Vahedi
e1b9725dfa ld: Make ARC's tls_ie-01 test more flexible
This is to address the regressions addressed by Nic [1].

The regular expression pattern for the tls_ie-01 test was
too strict and raising false alarms.  The new pattern only
looks for matches that should be there AND ignores the boiler
plates from the object dump.

[1] New failures for ARC targets in linker testsuite
https://sourceware.org/pipermail/binutils/2020-November/114177.html

ld/

	* testsuite/ld-arc/tls_ie-01.d: Use a more general pattern.
2020-11-23 12:25:44 +02:00
Nelson Chu
abd20cb637 RISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous.
I get the feedback recently that enable linker relaxations may fail to
build some program.  Consider the following case,

	.text
foo:
	addi	a0, a0, %pcrel_lo(.L2)
	call	foo
.L1:	auipc	a1, %pcrel_hi(data_g)
	addi	a1, a1, %pcrel_lo(.L1)
	lui	a2, %hi(data_g)
	addi	a2, a2, %lo(data_g)
	lui	a3, %tprel_hi(data_t)
	add	a3, a3, tp, %tprel_add(data_t)
	addi	a3, a3, %tprel_lo(data_t)
.L2:	auipc	a0, %pcrel_hi(data_g)

	.data
	.word 0x0
	.global data_g
data_g:	.word 0x1

	.section .tbss
data_t:	.word 0x0

The current ld reports `dangerous relocation error` when doing the
pcgp relaxation,
test.o: in function `foo':
(.text+0x0): dangerous relocation: %pcrel_lo missing matching %pcrel_hi

The .L2 auipc should not be removed since it is behind the corresponding
addi, so we record the information in the pcgp_relocs table to avoid
removing the auipc later.  But current ld still remove it since we do not
update the pcgp_relocs table while doing other relaxations.  I have two
solutions to fix the problem,

1. Update the pcgp_relocs table once we actually delete the code.
2. Add new relax pass to do the pcgp relaxations

At first I tried to do the first solution, and we need to update at
least three information - hi_sec_off of riscv_pcgp_lo_reloc, hi_sec_off
and hi_addr (symbol value) of riscv_pcgp_hi_reloc.  Update the hi_sec_off
is simple, but it is more complicate to update the symbol value, since we
almost have to do parts the same works of _bfd_riscv_relax_call again in
the riscv_relax_delete_bytes to get the correct symbol value.

Compared with the first solution, the second one is more intuitive and
simple.  We add a new relax pass to do the pcgp relaxations later, so
we will get all the information correctly in the _bfd_riscv_relax_call,
including the symbol value, without changing so much code.  I do not see
any penalty by adding a new relax pass for now, so it should be fine
to delay the pcgp relaxations.

Besides, I have pass all riscv-gnu-toolchain regressions for this patch.

	bfd/
	* elfnn-riscv.c (_bfd_riscv_relax_section):  Add a new relax pass
	to do the pcgp relaxation later, after the lui and call relaxations,
	but before the delete and alignment relaxations.

	ld/
	* emultempl/riscvelf.em (riscv_elf_before_allocation): Change
	link_info.relax_pass from 3 to 4.
	* testsuite/ld-riscv-elf/pcgp-relax.d: New testcase.
	* testsuite/ld-riscv-elf/pcgp-relax.s: Likewise.
	* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Updated.
2020-11-21 09:41:58 +08:00
Nick Alcock
0e28ade476 libctf, ld: properly deduplicate function types
Some type kinds in CTF (functions, arrays, pointers, slices, and
cvr-quals) are intrinsically nameless: the ctt_name field in the CTF
is always zero, and the libctf API provides no way to set a name.
But the compiler can and does sometimes set names for some of these
kinds: in particular, the name it sets on CTF_K_FUNCTION types is the
means it uses to force the name of the function into the string table
so that it can point at it from the function info section.

So null out the name at hashing time so that the deduplicator can
correctly detect that e.g. function types identical but for name should
be considered truly identical, since they will not have a name when the
deduplicator re-emits them into the output.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/data-func-conflicted.d: Shrink the expected
	size of the type section now that function types are being
	deduplicated properly.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-dedup.c (ctf_dedup_rhash_type): Null out the names of nameless
	type kinds, just in case the input has named them.
2020-11-20 13:34:10 +00:00
Nick Alcock
0ad70c536a ld, ctf: new and adjusted CTF tests due to func info / object data sections
The flags word is nonzero now (so all the tests have been adjusted to
not depend on its content): some of them have data objects and functions
in the data object and function info sections now, rather than in the
variable section or recorded nowhere.  There is a new test for
parent/child relationships and index section emission.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* testsuite/ld-ctf/array.d: Adjust for nonzero flags word and
	public symbols in the data section rather than variables: use
	sysv hash style to keep test results the same on non-GNU targets.
	* testsuite/ld-ctf/diag-cttname-null.d: Likewise.
	* testsuite/ld-ctf/diag-cuname.d: Likewise.
	* testsuite/ld-ctf/diag-parlabel.d: Likewise.
	* testsuite/ld-ctf/slice.d: Likewise.
	* testsuite/ld-ctf/function.d: Likewise, but in the function section.
	* testsuite/ld-ctf/conflicting-cycle-1.B-1.d:  Adjust for nonzero
	flags word.
	* testsuite/ld-ctf/conflicting-cycle-1.B-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-1.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.A-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.A-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-2.parent.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.C-1.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.C-2.d: Likewise.
	* testsuite/ld-ctf/conflicting-cycle-3.parent.d: Likewise.
	* testsuite/ld-ctf/cross-tu-noncyclic.d: Likewise.
	* testsuite/ld-ctf/cycle-1.d: Likewise.
	* testsuite/ld-ctf/cycle-2.A.d: Likewise.
	* testsuite/ld-ctf/cycle-2.B.d: Likewise.
	* testsuite/ld-ctf/cycle-2.C.d: Likewise.
	* testsuite/ld-ctf/diag-wrong-magic-number-mixed.d:  Likewise.
	* testsuite/ld-ctf/super-sub-cycles.d:  Likewise.
	* testsuite/ld-ctf/data-func-1.c: New test.
	* testsuite/ld-ctf/data-func-2.c: Likewise.
	* testsuite/ld-ctf/data-func-conflicted.d: Likewise.
2020-11-20 13:34:10 +00:00
Nick Alcock
3d16b64e28 bfd, include, ld, binutils, libctf: CTF should use the dynstr/sym
This is embarrassing.

The whole point of CTF is that it remains intact even after a binary is
stripped, providing a compact mapping from symbols to types for
everything in the externally-visible interface of an ELF object: it has
connections to the symbol table for that purpose, and to the string
table to avoid duplicating symbol names.  So it's a shame that the hooks
I implemented last year served to hook it up to the .symtab and .strtab,
which obviously disappear on strip, leaving any accompanying the CTF
dict containing references to strings (and, soon, symbols) which don't
exist any more because their containing strtab has been vaporized.  The
original Solaris design used .dynsym and .dynstr (well, actually,
.ldynsym, which has more symbols) which do not disappear. So should we.

Thankfully the work we did before serves as guide rails, and adjusting
things to use the .dynstr and .dynsym was fast and easy.  The only
annoyance is that the dynsym is assembled inside elflink.c in a fairly
piecemeal fashion, so that the easiest way to get the symbols out was to
hook in before every call to swap_symbol_out (we also leave in a hook in
front of symbol additions to the .symtab because it seems plausible that
we might want to hook them in future too: for now that hook is unused).
We adjust things so that rather than being offered a whole hash table of
symbols at once, libctf is now given symbols one at a time, with st_name
indexes already resolved and pointing at their final .dynstr offsets:
it's now up to libctf to resolve these to names as needed using the
strtab info we pass it separately.

Some bits might be contentious.  The ctf_new_dynstr callback takes an
elf_internal_sym, and this remains an elf_internal_sym right down
through the generic emulation layers into ldelfgen.  This is no worse
than the elf_sym_strtab we used to pass down, but in the future when we
gain non-ELF CTF symtab support we might want to lower the
elf_internal_sym to some other representation (perhaps a
ctf_link_symbol) in bfd or in ldlang_ctf_new_dynsym.  We rename the
'apply_strsym' hooks to 'acquire_strings' instead, becuse they no longer
have anything to do with symbols.

There are some API changes to pieces of API which are technically public
but actually totally unused by anything and/or unused by anything but ld
so they can change freely: the ctf_link_symbol gains new fields to allow
symbol names to be given as strtab offsets as well as strings, and a
symidx so that the symbol index can be passed in.  ctf_link_shuffle_syms
loses its callback parameter: the idea now is that linkers call the new
ctf_link_add_linker_symbol for every symbol in .dynsym, feed in all the
strtab entries with ctf_link_add_strtab, and then a call to
ctf_link_shuffle_syms will apply both and arrange to use them to reorder
the CTF symtab at CTF serialization time (which is coming in the next
commit).

Inside libctf we have a new preamble flag CTF_F_DYNSTR which is always
set in v3-format CTF dicts from this commit forwards: CTF dicts without
this flag are associated with .strtab like they used to be, so that old
dicts' external strings don't turn to garbage when loaded by new libctf.
Dicts with this flag are associated with .dynstr and .dynsym instead.
(The flag is not the next in sequence because this commit was written
quite late: the missing flags will be filled in by the next commit.)

Tests forthcoming in a later commit in this series.

bfd/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* elflink.c (elf_finalize_dynstr): Call examine_strtab after
	dynstr finalization.
	(elf_link_swap_symbols_out): Don't call it here.  Call
	ctf_new_symbol before swap_symbol_out.
	(elf_link_output_extsym): Call ctf_new_dynsym before
	swap_symbol_out.
	(bfd_elf_final_link): Likewise.
	* elf.c (swap_out_syms): Pass in bfd_link_info.  Call
	ctf_new_symbol before swap_symbol_out.
	(_bfd_elf_compute_section_file_positions): Adjust.

binutils/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* readelf.c (dump_section_as_ctf): Use .dynsym and .dynstr, not
	.symtab and .strtab.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* bfdlink.h (struct elf_sym_strtab): Replace with...
	(struct elf_internal_sym): ... this.
	(struct bfd_link_callbacks) <examine_strtab>: Take only a
	symstrtab argument.
	<ctf_new_symbol>: New.
	<ctf_new_dynsym>: Likewise.
	* ctf-api.h (struct ctf_link_sym) <st_symidx>: New.
	<st_nameidx>: Likewise.
	<st_nameidx_set>: Likewise.
	(ctf_link_iter_symbol_f): Removed.
	(ctf_link_shuffle_syms): Remove most parameters, just takes a
	ctf_dict_t now.
	(ctf_link_add_linker_symbol): New, split from
	ctf_link_shuffle_syms.
	* ctf.h (CTF_F_DYNSTR): New.
	(CTF_F_MAX): Adjust.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ldelfgen.c (struct ctf_strsym_iter_cb_arg): Rename to...
	(struct ctf_strtab_iter_cb_arg): ... this, changing fields:
	<syms>: Remove.
	<symcount>: Remove.
	<symstrtab>: Rename to...
	<strtab>: ... this.
	(ldelf_ctf_strtab_iter_cb): Adjust.
	(ldelf_ctf_symbols_iter_cb): Remove.
	(ldelf_new_dynsym_for_ctf): New, tell libctf about a single
	symbol.
	(ldelf_examine_strtab_for_ctf): Rename to...
	(ldelf_acquire_strings_for_ctf): ... this, only doing the strtab
	portion and not symbols.
	* ldelfgen.h: Adjust declarations accordingly.
	* ldemul.c (ldemul_examine_strtab_for_ctf): Rename to...
	(ldemul_acquire_strings_for_ctf): ... this.
	(ldemul_new_dynsym_for_ctf): New.
	* ldemul.h: Adjust declarations accordingly.
	* ldlang.c (ldlang_ctf_apply_strsym): Rename to...
	(ldlang_ctf_acquire_strings): ... this.
	(ldlang_ctf_new_dynsym): New.
	(lang_write_ctf): Call ldemul_new_dynsym_for_ctf with NULL to do
	the actual symbol shuffle.
	* ldlang.h (struct elf_strtab_hash): Adjust accordingly.
	* ldmain.c (bfd_link_callbacks): Wire up new/renamed callbacks.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-link.c (ctf_link_shuffle_syms): Adjust.
	(ctf_link_add_linker_symbol): New, unimplemented stub.
	* libctf.ver: Add it.
	* ctf-create.c (ctf_serialize): Set CTF_F_DYNSTR on newly-serialized
	dicts.
	* ctf-open-bfd.c (ctf_bfdopen_ctfsect): Check for the flag: open the
	symtab/strtab if not present, dynsym/dynstr otherwise.
	* ctf-archive.c (ctf_arc_bufpreamble): New, get the preamble from
	some arbitrary member of a CTF archive.
	* ctf-impl.h (ctf_arc_bufpreamble): Declare it.
2020-11-20 13:34:07 +00:00
Nick Alcock
139633c307 libctf, include, binutils, gdb, ld: rename ctf_file_t to ctf_dict_t
The naming of the ctf_file_t type in libctf is a historical curiosity.
Back in the Solaris days, CTF dictionaries were originally generated as
a separate file and then (sometimes) merged into objects: hence the
datatype was named ctf_file_t, and known as a "CTF file".  Nowadays, raw
CTF is essentially never written to a file on its own, and the datatype
changed name to a "CTF dictionary" years ago.  So the term "CTF file"
refers to something that is never a file!  This is at best confusing.

The type has also historically been known as a 'CTF container", which is
even more confusing now that we have CTF archives which are *also* a
sort of container (they contain CTF dictionaries), but which are never
referred to as containers in the source code.

So fix this by completing the renaming, renaming ctf_file_t to
ctf_dict_t throughout, and renaming those few functions that refer to
CTF files by name (keeping compatibility aliases) to refer to dicts
instead.  Old users who still refer to ctf_file_t will see (harmless)
pointer-compatibility warnings at compile time, but the ABI is unchanged
(since C doesn't mangle names, and ctf_file_t was always an opaque type)
and things will still compile fine as long as -Werror is not specified.
All references to CTF containers and CTF files in the source code are
fixed to refer to CTF dicts instead.

Further (smaller) renamings of annoyingly-named functions to come, as
part of the process of souping up queries across whole archives at once
(needed for the function info and data object sections).

binutils/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* objdump.c (dump_ctf_errs): Rename ctf_file_t to ctf_dict_t.
	(dump_ctf_archive_member): Likewise.
	(dump_ctf): Likewise. Use ctf_dict_close, not ctf_file_close.
	* readelf.c (dump_ctf_errs): Rename ctf_file_t to ctf_dict_t.
	(dump_ctf_archive_member): Likewise.
	(dump_section_as_ctf): Likewise.  Use ctf_dict_close, not
	ctf_file_close.

gdb/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctfread.c: Change uses of ctf_file_t to ctf_dict_t.
	(ctf_fp_info::~ctf_fp_info): Call ctf_dict_close, not ctf_file_close.

include/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-api.h (ctf_file_t): Rename to...
	(ctf_dict_t): ... this.  Keep ctf_file_t around for compatibility.
	(struct ctf_file): Likewise rename to...
	(struct ctf_dict): ... this.
	(ctf_file_close): Rename to...
	(ctf_dict_close): ... this, keeping compatibility function.
	(ctf_parent_file): Rename to...
	(ctf_parent_dict): ... this, keeping compatibility function.
	All callers adjusted.
	* ctf.h: Rename references to ctf_file_t to ctf_dict_t.
	(struct ctf_archive) <ctfa_nfiles>: Rename to...
	<ctfa_ndicts>: ... this.

ld/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ldlang.c (ctf_output): This is a ctf_dict_t now.
	(lang_ctf_errs_warnings): Rename ctf_file_t to ctf_dict_t.
	(ldlang_open_ctf): Adjust comment.
	(lang_merge_ctf): Use ctf_dict_close, not ctf_file_close.
	* ldelfgen.h (ldelf_examine_strtab_for_ctf): Rename ctf_file_t to
	ctf_dict_t.  Change opaque declaration accordingly.
	* ldelfgen.c (ldelf_examine_strtab_for_ctf): Adjust.
	* ldemul.h (examine_strtab_for_ctf): Likewise.
	(ldemul_examine_strtab_for_ctf): Likewise.
	* ldeuml.c (ldemul_examine_strtab_for_ctf): Likewise.

libctf/ChangeLog
2020-11-20  Nick Alcock  <nick.alcock@oracle.com>

	* ctf-impl.h: Rename ctf_file_t to ctf_dict_t: all declarations
	adjusted.
	(ctf_fileops): Rename to...
	(ctf_dictops): ... this.
	(ctf_dedup_t) <cd_id_to_file_t>: Rename to...
	<cd_id_to_dict_t>: ... this.
	(ctf_file_t): Fix outdated comment.
	<ctf_fileops>: Rename to...
	<ctf_dictops>: ... this.
	(struct ctf_archive_internal) <ctfi_file>: Rename to...
	<ctfi_dict>: ... this.
	* ctf-archive.c: Rename ctf_file_t to ctf_dict_t.
	Rename ctf_archive.ctfa_nfiles to ctfa_ndicts.
	Rename ctf_file_close to ctf_dict_close.  All users adjusted.
	* ctf-create.c: Likewise.  Refer to CTF dicts, not CTF containers.
	(ctf_bundle_t) <ctb_file>: Rename to...
	<ctb_dict): ... this.
	* ctf-decl.c: Rename ctf_file_t to ctf_dict_t.
	* ctf-dedup.c: Likewise.  Rename ctf_file_close to
	ctf_dict_close. Refer to CTF dicts, not CTF containers.
	* ctf-dump.c: Likewise.
	* ctf-error.c: Likewise.
	* ctf-hash.c: Likewise.
	* ctf-inlines.h: Likewise.
	* ctf-labels.c: Likewise.
	* ctf-link.c: Likewise.
	* ctf-lookup.c: Likewise.
	* ctf-open-bfd.c: Likewise.
	* ctf-string.c: Likewise.
	* ctf-subr.c: Likewise.
	* ctf-types.c: Likewise.
	* ctf-util.c: Likewise.
	* ctf-open.c: Likewise.
	(ctf_file_close): Rename to...
	(ctf_dict_close): ...this.
	(ctf_file_close): New trivial wrapper around ctf_dict_close, for
	compatibility.
	(ctf_parent_file): Rename to...
	(ctf_parent_dict): ... this.
	(ctf_parent_file): New trivial wrapper around ctf_parent_dict, for
	compatibility.
	* libctf.ver: Add ctf_dict_close and ctf_parent_dict.
2020-11-20 13:34:04 +00:00
Jozef Lawrynowicz
cc6fd584ed Fix SHF_GNU_RETAIN testsuite fallout
binutils/ChangeLog:

	* testsuite/binutils-all/readelf-maskos-1a.d: Fix test for unrecognized
	bit set in SHF_MASKOS range.
	* testsuite/binutils-all/readelf-maskos-1b.d: Likewise.
	* testsuite/binutils-all/readelf-maskos-unknown.s: New test.

ld/ChangeLog:

	* testsuite/ld-elf/retain3.s: Move symbolic reference into writeable
	.data section from read-only .text section.
	* testsuite/ld-elf/retain5.d: Don't pass --print-gc-sections for test
	that doesn't require it.
	* testsuite/ld-elf/retain6a.d: Adjust test.
	* testsuite/ld-elf/retain6main.s: Move symbolic reference into writeable
	.data section from read-only .text section.
2020-11-20 10:33:28 +00:00
Alan Modra
e4d9e5422f PowerPC paranioa testing of symbol merging involving comdat groups
Ensures we don't mistreat st_other localentry bits.

	* testsuite/ld-powerpc/group1.d,
	* testsuite/ld-powerpc/group1.s,
	* testsuite/ld-powerpc/group1.sym,
	* testsuite/ld-powerpc/group2.d,
	* testsuite/ld-powerpc/group2.s,
	* testsuite/ld-powerpc/group2.sym,
	* testsuite/ld-powerpc/group3.s,
	* testsuite/ld-powerpc/group3.sym: New test files.
	* testsuite/ld-powerpc/powerpc.exp: Run new tests.
2020-11-18 23:49:31 +10:30
Jozef Lawrynowicz
99fabbc973 Support SHF_GNU_RETAIN ELF section flag
The SHF_GNU_RETAIN section flag is an extension to the GNU ELF OSABI.
It is defined as follows:

=========================================================
Section Attribute Flags
+-------------------------------------+
| Name           | Value              |
+-------------------------------------+
| SHF_GNU_RETAIN | 0x200000 (1 << 21) |
+-------------------------------------+

SHF_GNU_RETAIN
  The link editor should not garbage collect the section.
=========================================================

The .section directive accepts the "R" flag, which indicates
SHF_GNU_RETAIN should be applied to the section.

There is not a direct mapping of SHF_GNU_RETAIN to the BFD
section flag SEC_KEEP. Keeping these flags distinct allows
SHF_GNU_RETAIN sections to be explicitly removed by placing them in
/DISCARD/.

bfd/ChangeLog:

	* elf-bfd.h (enum elf_gnu_osabi): Add elf_gnu_osabi_retain.
	(struct elf_obj_tdata): Increase has_gnu_osabi to 4 bits.
	* elf.c (_bfd_elf_make_section_from_shdr): Set elf_gnu_osabi_retain
	for SHF_GNU_RETAIN.
	(_bfd_elf_final_write_processing): Report if SHF_GNU_RETAIN is
	not supported by the OSABI.
	Adjust error messages.
	* elflink.c (elf_link_input_bfd): Copy enabled has_gnu_osabi bits from
	input BFD to output BFD.
	(bfd_elf_gc_sections): gc_mark the section if SHF_GNU_RETAIN is set.

binutils/ChangeLog:

	* NEWS: Announce SHF_GNU_RETAIN support.
	* readelf.c (get_elf_section_flags): Handle SHF_GNU_RETAIN.
	Recognize SHF_GNU_RETAIN and SHF_GNU_MBIND only for supported OSABIs.
	* testsuite/binutils-all/readelf.exp: Run new tests.
	Don't run run_dump_test when there isn't an assembler available.
	* testsuite/lib/binutils-common.exp (supports_gnu_osabi): Adjust
	comment.
	* testsuite/binutils-all/readelf-maskos-1a.d: New test.
	* testsuite/binutils-all/readelf-maskos-1b.d: New test.
	* testsuite/binutils-all/readelf-maskos.s: New test.
	* testsuite/binutils-all/retain1.s: New test.
	* testsuite/binutils-all/retain1a.d: New test.
	* testsuite/binutils-all/retain1b.d: New test.

gas/ChangeLog:

	* NEWS: Announce SHF_GNU_RETAIN support.
	* config/obj-elf.c (obj_elf_change_section): Merge SHF_GNU_RETAIN bit
	between section declarations.
	(obj_elf_parse_section_letters): Handle 'R' flag.
	Handle numeric flag values within the SHF_MASKOS range.
	(obj_elf_section): Validate SHF_GNU_RETAIN usage.
	* doc/as.texi: Document 'R' flag to .section directive.
	* testsuite/gas/elf/elf.exp: Run new tests.
	* testsuite/gas/elf/section10.d: Unset SHF_GNU_RETAIN bit.
	* testsuite/gas/elf/section10.s: Likewise.
	* testsuite/gas/elf/section22.d: New test.
	* testsuite/gas/elf/section22.s: New test.
	* testsuite/gas/elf/section23.s: New test.
	* testsuite/gas/elf/section23a.d: New test.
	* testsuite/gas/elf/section23b.d: New test.
	* testsuite/gas/elf/section23b.err: New test.
	* testsuite/gas/elf/section24.l: New test.
	* testsuite/gas/elf/section24.s: New test.
	* testsuite/gas/elf/section24a.d: New test.
	* testsuite/gas/elf/section24b.d: New test.

include/ChangeLog:

	* elf/common.h (SHF_GNU_RETAIN): Define.

ld/ChangeLog:

	* NEWS: Announce support for SHF_GNU_RETAIN.
	* ld.texi (garbage collection): Document SHF_GNU_RETAIN.
	(Output Section Discarding): Likewise.
	* testsuite/ld-elf/elf.exp: Run new tests.
	* testsuite/ld-elf/retain1.s: New test.
	* testsuite/ld-elf/retain1a.d: New test.
	* testsuite/ld-elf/retain1b.d: New test.
	* testsuite/ld-elf/retain2.d: New test.
	* testsuite/ld-elf/retain2.ld: New test.
	* testsuite/ld-elf/retain2.map: New test.
	* testsuite/ld-elf/retain3.d: New test.
	* testsuite/ld-elf/retain3.s: New test.
	* testsuite/ld-elf/retain4.d: New test.
	* testsuite/ld-elf/retain4.s: New test.
	* testsuite/ld-elf/retain5.d: New test.
	* testsuite/ld-elf/retain5.map: New test.
	* testsuite/ld-elf/retain5lib.s: New test.
	* testsuite/ld-elf/retain5main.s: New test.
	* testsuite/ld-elf/retain6a.d: New test.
	* testsuite/ld-elf/retain6b.d: New test.
	* testsuite/ld-elf/retain6lib.s: New test.
	* testsuite/ld-elf/retain6main.s: New test.
2020-11-18 11:51:13 +00:00