aboutsummaryrefslogtreecommitdiff
path: root/ld
AgeCommit message (Collapse)AuthorFilesLines
2021-01-06ld rgn-at10 and rgn-at11 testAlan Modra3-3/+7
These fail on v850 due to that target using different .tbss section flags. * testsuite/ld-scripts/rgn-at10.d: xfail v850. * testsuite/ld-scripts/rgn-at11.d: Likewise.
2021-01-06RISC-V: Fix riscv gas/ld testsuites failures for big endian.Marcus Comstedt14-23/+59
Add riscv_choose_[ilp32|lp64]_emul, and use them to choose the correct linker script rather than set elf[32|64]lriscv directly. gas/ * testsuite/gas/riscv/li32.d: Accept bigriscv in addition to littleriscv. * testsuite/gas/riscv/li64.d: Likewise. * testsuite/gas/riscv/lla32.d: Likewise. * testsuite/gas/riscv/lla64.d: Likewise. * testsuite/gas/riscv/march-ok-g2.d: Likewise. * testsuite/gas/riscv/march-ok-g2_p1.d: Likewise. * testsuite/gas/riscv/march-ok-g2p0.d: Likewise. * testsuite/gas/riscv/march-ok-i2p0.d: Likewise. * testsuite/gas/riscv/march-ok-i2p0m2_a2f2.d: Likewise. * testsuite/gas/riscv/march-ok-nse-with-version.d: Likewise. * testsuite/gas/riscv/march-ok-two-nse.d: Likewise. ld/ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Added riscv_choose_[ilp32|lp64]_emul to choose the correct linker script. * testsuite/ld-riscv-elf/attr-merge-arch-01.d: Call riscv_choose_[ilp32|lp64]_emul instead of hardcoding elf[32|64]lriscv. * testsuite/ld-riscv-elf/attr-merge-arch-02.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-03.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-failed-01.d: Likewise. * testsuite/ld-riscv-elf/attr-merge-arch-failed-02.d: Likewise. * testsuite/ld-riscv-elf/c-lui-2.d: Likewise. * testsuite/ld-riscv-elf/c-lui.d: Likewise. * testsuite/ld-riscv-elf/call-relax.d: Likewise. * testsuite/ld-riscv-elf/pcrel-lo-addend-2.d: Likewise. * testsuite/ld-riscv-elf/pcrel-lo-addend.d: Likewise. * testsuite/ld-riscv-elf/weakref32.d: Accept bigriscv in addition to littleriscv. * testsuite/ld-riscv-elf/weakref64.d: Likewise.
2021-01-06RISC-V: Implement support for big endian targets.Marcus Comstedt10-4/+78
RISC-V instruction/code is always little endian, but data might be big-endian. Therefore, we can not use the original bfd_get/bfd_put to get/put the code for big endian targets. Add new riscv_get_insn and riscv_put_insn to always get/put code as little endian can resolve the problem. Just remember to update them once we have supported the 48-bit/128-bit instructions in the future patches. bfd/ * config.bfd: Added targets riscv64be*-*-*, riscv32be*-*-* and riscvbe*-*-*. Also added riscv_elf[32|64]_be_vec. * configure.ac: Handle riscv_elf[32|64]_be_vec. * configure: Regenerate. * elfnn-riscv.c: Include <limits.h> and define CHAR_BIT for riscv_is_insn_reloc. (riscv_get_insn): RISC-V instructions are always little endian, but bfd_get may be used for big-endian, so add new riscv_get_insn to handle the insturctions. (riscv_put_insn): Likewsie. (riscv_is_insn_reloc): Check if we are relocaing an instruction. (perform_relocation): Call riscv_is_insn_reloc to decide if we should use riscv_[get|put]_insn or bfd_[get|put]. (riscv_zero_pcrel_hi_reloc): Use riscv_[get|put]_insn, bfd_[get|put]l32 or bfd_[get|put]l16 for code. (riscv_elf_relocate_section): Likewise. (riscv_elf_finish_dynamic_symbol): Likewise. (riscv_elf_finish_dynamic_sections): Likewise. (_bfd_riscv_relax_call): Likewise. (_bfd_riscv_relax_lui): Likewise. (_bfd_riscv_relax_align): Likewise. (_bfd_riscv_relax_pc): Likewise. (riscv_elf_object_p): Handled for big endian. (TARGET_BIG_SYM, TARGET_BIG_NAME): Defined. * targets.c: Add riscv_elf[32|64]_be_vec. (_bfd_target_vector): Likewise. gas/ * config/tc-riscv.c (riscv_target_format): Add elf64-bigriscv and elf32-bigriscv. (install_insn): Always write instructions as little endian. (riscv_make_nops): Likewise. (md_convert_frag_branch): Likewise. (md_number_to_chars): Write data in target endianness. (options, md_longopts): Add -mbig-endian and -mlittle-endian options. (md_parse_option): Handle the endian options. * config/tc-riscv.h: Only define TARGET_BYTES_BIG_ENDIAN if not already defined. * configure.tgt: Added riscv64be*, riscv32be*, riscvbe*. ld/ * configure.tgt: Added riscvbe-*-*, riscv32be*-*-*, riscv64be*-*-*, riscv32be*-*-linux*, and riscv64be*-*-linux*. * Makefile.am: Added eelf32briscv.c, eelf32briscv_ilp32f.c and eelf32briscv_ilp32.c. * Makefile.in: Regenerate. * emulparams/elf32briscv.sh: Added. * emulparams/elf32briscv_ilp32.sh: Likewise. * emulparams/elf32briscv_ilp32f.sh: Likewise. * emulparams/elf64briscv.sh: Likewise. * emulparams/elf64briscv_lp64.sh: Likewise. * emulparams/elf64briscv_lp64f.sh: Likewise.
2021-01-05libctf, ld: fix formatting of forwards to unions and enumsNick Alcock3-0/+27
The type printer was unconditionally printing these as if they were forwards to structs, even if they were forwards to unions or enums. ld/ChangeLog 2021-01-05 Nick Alcock <nick.alcock@oracle.com> * testsuite/ld-ctf/enum-forward.c: New test. * testsuite/ld-ctf/enum-forward.c: New results. libctf/ChangeLog 2021-01-05 Nick Alcock <nick.alcock@oracle.com> * ctf-types.c (ctf_type_aname): Print forwards to unions and enums properly.
2021-01-05libctf, ld: dump enums: generally improve dump formattingNick Alcock32-185/+244
This commit adds dumping of enumerands in this general form: 0x3: (kind 8) enum eleven_els (size 0x4) (aligned at 0x4) ELEVEN_ONE: 10 ELEVEN_TWO: 11 ELEVEN_THREE: -256 ELEVEN_FOUR: -255 ELEVEN_FIVE: -254 ... ELEVEN_SEVEN: -252 ELEVEN_EIGHT: -251 ELEVEN_NINE: -250 ELEVEN_TEN: -249 ELEVEN_ELEVEN: -248 The first and last enumerands in the enumerated type are printed so that you can tell if they've been cut off at one end or the other. (For now, there is no way to control how many enumerands are printed.) The dump output in general is improved, from this sort of thing a few days ago: 4c: char [0x0:0x8] (size 0x1) [0x0] (ID 0x4c) (kind 1) char:8 (aligned at 0x1, format 0x3, offset:bits 0x0:0x8) 4d: char * (size 0x8) -> 4c: char [0x0:0x8] (size 0x1) [0x0] (ID 0x4d) (kind 3) char * (aligned at 0x8) [...] 5a: struct _IO_FILE (size 0xd8) [0x0] (ID 0x5a) (kind 6) struct _IO_FILE (aligned at 0x4) [0x0] (ID 0x3) (kind 1) int _flags:32 (aligned at 0x4, format 0x1, offset:bits 0x0:0x20) [0x40] (ID 0x4d) (kind 3) char * _IO_read_ptr (aligned at 0x8) [0x80] (ID 0x4d) (kind 3) char * _IO_read_end (aligned at 0x8) [0xc0] (ID 0x4d) (kind 3) char * _IO_read_base (aligned at 0x8) 5b: __FILE (size 0xd8) -> 5a: struct _IO_FILE (size 0xd8) [0x0] (ID 0x5b) (kind 10) __FILE (aligned at 0x4) [0x0] (ID 0x3) (kind 1) int _flags:32 (aligned at 0x4, format 0x1, offset:bits 0x0:0x20) [0x40] (ID 0x4d) (kind 3) char * _IO_read_ptr (aligned at 0x8) [0x80] (ID 0x4d) (kind 3) char * _IO_read_end (aligned at 0x8) [0xc0] (ID 0x4d) (kind 3) char * _IO_read_base (aligned at 0x8) [...] 406: struct coff_link_hash_entry (size 0x60) [0x0] (ID 0x406) (kind 6) struct coff_link_hash_entry (aligned at 0x8) [0x0] (ID 0x2b3) (kind 6) struct bfd_link_hash_entry root (aligned at 0x8) [0x0] (ID 0x1d6) (kind 6) struct bfd_hash_entry root (aligned at 0x8) [0x0] (ID 0x1d7) (kind 3) struct bfd_hash_entry * next (aligned at 0x8) [0x40] (ID 0x61) (kind 3) const char * string (aligned at 0x8) [0x80] (ID 0x1) (kind 1) long unsigned int hash:64 (aligned at 0x8, format 0x0, offset:bits 0x0:0x40) [0xc0] (ID 0x397) (kind 8) enum bfd_link_hash_type type:8 (aligned at 0x1, format 0x0, offset:bits 0x0:0x8) [0xc8] (ID 0x1c7) (kind 1) unsigned int non_ir_ref_regular:1 (aligned at 0x1, format 0x0, offset:bits 0x8:0x1) [0xc9] (ID 0x1c8) (kind 1) unsigned int non_ir_ref_dynamic:1 (aligned at 0x1, format 0x0, offset:bits 0x9:0x1) [0xca] (ID 0x1c9) (kind 1) unsigned int linker_def:1 (aligned at 0x1, format 0x0, offset:bits 0xa:0x1) [0xcb] (ID 0x1ca) (kind 1) unsigned int ldscript_def:1 (aligned at 0x1, format 0x0, offset:bits 0xb:0x1) [0xcc] (ID 0x1cb) (kind 1) unsigned int rel_from_abs:1 (aligned at 0x1, format 0x0, offset:bits 0xc:0x1) ... to this: 0x4c: (kind 1) char (format 0x3) (size 0x1) (aligned at 0x1) 0x4d: (kind 3) char * (size 0x8) (aligned at 0x8) -> 0x4c: (kind 1) char (format 0x3) (size 0x1) (aligned at 0x1) 0x5a: (kind 6) struct _IO_FILE (size 0xd8) (aligned at 0x4) [0x0] _flags: ID 0x3: (kind 1) int (format 0x1) (size 0x4) (aligned at 0x4) [0x40] _IO_read_ptr: ID 0x4d: (kind 3) char * (size 0x8) (aligned at 0x8) [0x80] _IO_read_end: ID 0x4d: (kind 3) char * (size 0x8) (aligned at 0x8) [0xc0] _IO_read_base: ID 0x4d: (kind 3) char * (size 0x8) (aligned at 0x8) [0x100] _IO_write_base: ID 0x4d: (kind 3) char * (size 0x8) (aligned at 0x8) 0x5b: (kind 10) __FILE (size 0xd8) (aligned at 0x4) -> 0x5a: (kind 6) struct _IO_FILE (size 0xd8) (aligned at 0x4) [...] 0x406: (kind 6) struct coff_link_hash_entry (size 0x60) (aligned at 0x8) [0x0] root: ID 0x2b3: (kind 6) struct bfd_link_hash_entry (size 0x38) (aligned at 0x8) [0x0] root: ID 0x1d6: (kind 6) struct bfd_hash_entry (size 0x18) (aligned at 0x8) [0x0] next: ID 0x1d7: (kind 3) struct bfd_hash_entry * (size 0x8) (aligned at 0x8) [0x40] string: ID 0x61: (kind 3) const char * (size 0x8) (aligned at 0x8) [0x80] hash: ID 0x1: (kind 1) long unsigned int (format 0x0) (size 0x8) (aligned at 0x8) [0xc0] type: ID 0x397: (kind 8) enum bfd_link_hash_type (format 0x7f2e) (size 0x1) (aligned at 0x1) [0xc8] non_ir_ref_regular: ID 0x1c7: (kind 1) unsigned int:1 [slice 0x8:0x1] (format 0x0) (size 0x1) (aligned at 0x1) [0xc9] non_ir_ref_dynamic: ID 0x1c8: (kind 1) unsigned int:1 [slice 0x9:0x1] (format 0x0) (size 0x1) (aligned at 0x1) [0xca] linker_def: ID 0x1c9: (kind 1) unsigned int:1 [slice 0xa:0x1] (format 0x0) (size 0x1) (aligned at 0x1) [0xcb] ldscript_def: ID 0x1ca: (kind 1) unsigned int:1 [slice 0xb:0x1] (format 0x0) (size 0x1) (aligned at 0x1) [0xcc] rel_from_abs: ID 0x1cb: (kind 1) unsigned int:1 [slice 0xc:0x1] (format 0x0) (size 0x1) (aligned at 0x1) [...] In particular, indented subsections are only present for actual structs and unions, not forwards to them, and the structure itself doesn't add a spurious level of indentation; structure field names are easier to spot (at the cost of not making them look so much like C field declarations any more, but they weren't always shown in valid decl syntax even before this change) the size, type kind, and alignment are shown for all types for which they are meaningful; bitfield info is only shown for actual bitfields within structures and not ordinary integral fields; and type IDs are never omitted. Type printing is in general much more consistent and there is much less duplicated code in the type dumper. There is one user-visible effect outside the dumper: ctf_type_(a)name was erroneously emitting a trailing space on the name of slice types, even though a slice of an int and an int with the corresponding encoding represent the same type and should have the same print form. This trailing space is now gone. 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/forward.d: Likewise. * testsuite/ld-ctf/function.d: Likewise. * testsuite/ld-ctf/slice.d: Likewise. * testsuite/ld-ctf/super-sub-cycles.d: Likewise. * testsuite/ld-ctf/enums.c: New test. * testsuite/ld-ctf/enums.d: New test. libctf/ChangeLog 2021-01-05 Nick Alcock <nick.alcock@oracle.com> * ctf-decl.c (ctf_decl_push): Exclude slices from the decl stack. * ctf-types.c (ctf_type_aname): No longer deal with slices here. * ctf-dump.c (ctf_dump_membstate_t) <cdm_toplevel_indent>: Constify. (CTF_FT_REFS): New. (CTF_FT_BITFIELD): Likewise. (CTF_FT_ID): Likewise. (ctf_dump_member): Do not do indentation here. Migrate the type-printing parts of this into... (ctf_dump_format_type): ... here, to be shared by all type printers. Get the errno value for non-representable types right. Do not print bitfield info for non-bitfields. Improve the format and indentation of other type output. Shuffle spacing around to make all indentation either 'width of column' or 4 chars. (ctf_dump_label): Pass CTF_FT_REFS to ctf_dump_format_type. (ctf_dump_objts): Likewise. Spacing shuffle. (ctf_dump_var): Likewise. (type_hex_digits): Migrate down in the file, to above its new user. (ctf_dump_type): Indent here instead. Pass CTF_FT_REFS to ctf_dump_format_type. Don't trim off excess linefeeds now we no longer generate them. Dump enumerated types.
2021-01-05libctf, ld: prohibit getting the size or alignment of forwardsNick Alcock5-4/+37
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-05libctf, ld: more dumper improvementsNick Alcock8-19/+29
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-05libctf, ld: CTF dumper changes for consistencyNick Alcock29-205/+236
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-05ld sysroot-prefix test failsAlan Modra2-0/+13
* testsuite/ld-scripts/sysroot-prefix.exp: Exclude some targets.
2021-01-05Re: elf: Allow mixed ordered/unordered inputs for non-relocatable linkAlan Modra3-3/+8
PR ld/26256 * testsuite/ld-elf/pr26256-1b.d: xfail s12z. * testsuite/ld-scripts/crossref.exp (cross1): Don't xfail ia64.
2021-01-04elf: Allow mixed ordered/unordered inputs for non-relocatable linkH.J. Lu16-1/+256
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-04PR26822, How to prevent a STT_FILE with absolute path in the linked imageAlan Modra38-73/+114
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-01PR27116, Spelling errors found by Debian style checkerAlan Modra5-4/+10
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-01Update year range in copyright notice of binutils filesAlan Modra342-401/+405
2021-01-01ChangeLog rotationAlan Modra2-4544/+4558
2020-12-31PR27128, nm -P portable output format regressionAlan Modra8-0/+111
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-24SHF_GNU_RETAIN 7a and 7b testsAlan Modra3-4/+11
* 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-24PR27100, final link failed: bad valueAlan Modra10-9/+38
The failure on this PR is due to using the same bfd section for multiple output sections. Commit 21401fc7bf67 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-23x86-64: Add Intel LAM property supportH.J. Lu23-7/+385
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-18ld: Build and install only unversioned libdepH.J. Lu3-11/+28
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-18elf: Copy elf_gnu_osabi_retain only for relocatable linkH.J. Lu4-0/+33
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-16ld: Skip libdep plugin if not all plugin hooks are availableH.J. Lu5-20/+32
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-16constify elfNN_bedAlan Modra6-23/+26
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-15Document -z unique/-z nounique in the ld man page and help outputVivek Das Mohapatra3-0/+16
* ld.texi (Options): Document -z unique and -z nounique. * lexsup.c (elf_shlib_list_options): Likewise.
2020-12-15Handle -z unique/-z nounique in ldVivek Das Mohapatra2-0/+9
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-14Add a plugin for processing static library dependencies.Howard Chu7-1524/+2180
* 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-14PR26836, memory leak in parse_argsAlan Modra2-0/+10
PR 26836 * lexsup.c (parse_args): Free really_longopts, longopts and shortopts.
2020-12-14Fix a use of an uninitialised variable in the bfd linker.Nick Clifton2-1/+7
PR 27050 * lexsup.c (parse_args): Ensure that the longind local variable is set.
2020-12-14Solaris 11.4 ld build failureAlan Modra2-4/+9
/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-05VAX/BFD: Do not warn about GOT addend mismatches if no GOT entry is madeMaciej W. Rozycki15-2/+238
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-04x86-64: Convert load to mov only for GOTPCRELX relocationsH.J. Lu6-0/+84
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-04PR26978, Inconsistency for strong foo@v1 and weak foo@@v1Alan Modra5-0/+37
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-03IBM Z: Add support for HLASM extended mnemonicsAndreas Krebbel2-5/+10
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-03VAX/LD/testsuite: Wrap excessively long linesMaciej W. Rozycki2-3/+11
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-02testsuite/ld-elf/pr26936.d: Pass -W.Hans-Peter Nilsson2-1/+5
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-01arc: Enable -Ttext-segmentH.J. Lu2-0/+9
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-01tic6x elf testsuite fixAlan Modra3-3/+9
* testsuite/ld-elf/elf.exp: Set ASFLAGS for tic6x. * testsuite/ld-elf/reloc-discard.d: Remove tic6x xfail.
2020-12-01PR26979, Visibility of undefined foo@v1 should constrain foo@@v1Alan Modra7-0/+44
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-11-30ld: Xfail PR ld/26936 test if not supportedH.J. Lu2-0/+13
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-28PR26907, segment contains empty SHT_NOBITS sectionAlan Modra4-0/+31
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-27ELF: Support .noinit and .persistent sectionsJozef Lawrynowicz15-18/+145
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-26PR26936 testsuite fixesAlan Modra3-3/+23
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-25elf: Get the real kept sectionH.J. Lu5-0/+43
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-25Duplicate output sections in scriptsAlan Modra3-42/+45
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-24ld/x86-64: Add PR gold/26939 testsH.J. Lu5-0/+40
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-23s390x: Set .got sh_entsize only if .got size > 0H.J. Lu4-0/+38
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-23ld: Make ARC's tls_ie-01 test more flexibleShahab Vahedi2-7/+60
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-21RISC-V: Relax PCREL to GPREL while doing other relaxations is dangerous.Nelson Chu5-1/+55
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-20libctf, ld: properly deduplicate function typesNick Alcock2-1/+7
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-20ld, ctf: new and adjusted CTF tests due to func info / object data sectionsNick Alcock26-45/+1191
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.