ELF size_dynamic_sections is called by the ELF backend linker after all
the linker input files have been seen but before the section sizes have
been set. After the sections sizes have been set, target-specific,
global optimizations may make some dynamic sections zero-sized if they
are no longer needed.
Add ELF strip_zero_sized_dynamic_sections so that ELF backend linker can
strip zero-sized dynamic sections after the sections sizes have been set.
bfd/
PR ld/25849
* elf-bfd.h (elf_backend_data): Add
elf_backend_strip_zero_sized_dynamic_sections.
(_bfd_elf_strip_zero_sized_dynamic_sections): New prototype.
* elf64-alpha.c (elf_backend_strip_zero_sized_dynamic_sections):
New macro.
* elflink.c (_bfd_elf_strip_zero_sized_dynamic_sections): New
function.
* elfxx-target.h (elf_backend_strip_zero_sized_dynamic_sections):
New macro.
(elfNN_bed): Add elf_backend_strip_zero_sized_dynamic_sections.
ld/
PR ld/25849
* ldelfgen.c (ldelf_map_segments): Call
elf_backend_strip_zero_sized_dynamic_sections.
* testsuite/ld-alpha/tlsbinr.rd: Updated.
Stripping .rela.branch_lt is easy enough but messes with the
testsuite due to stub symbols (that use section id) changing. Tests
that run on more than one target variant can be tricky to fix, this
renaming happened to work.
bfd/
* elf64-ppc.c (ppc64_elf_size_stubs): Strip relbrlt too.
ld/
* testsuite/ld-powerpc/tlsopt5.s: Rename foo to aaaaa.
* testsuite/ld-powerpc/tlsopt5.d: Adjust to suit.
* testsuite/ld-powerpc/tlsopt6.d: Likewise.
Two ld tests currently XPASS on 64-bit Solaris/SPARC:
XPASS: ld-elf/warn1
XPASS: ld-elf/warn2
They were xfail'ed on Solaris/SPARCv9 back in 2005
https://sourceware.org/pipermail/binutils/2005-February/039268.html
but obviously this no longer appplies.
Fixed by removing the xfail's.
Tested on sparcv9-sun-solaris2.11 and sparc-sun-solaris2.11.
* testsuite/ld-elf/warn1.d: Don't xfail on 64-bit Solaris/SPARC.
* testsuite/ld-elf/warn2.d: Likewise.
Since the .set directive of ELF/alpha target is different, define NO_SET
to 1 to use "=" for ELF/alpha target.
* testsuite/ld-elf/elf.exp (ASFLAGS): Add "--defsym NO_SET=1" for
alpha target.
* testsuite/ld-elf/pr19789.s: Use "=" if NO_SET is defined.
* testsuite/config/default.exp: If not already set then create the
CCC_OVERRIDE_OPTIONS environment variable to help when running the
testsuite with clang.
* testsuite/ld-elf/pr22269-1.c: Add a missing return statement.
* testsuite/ld-elfvers/vers.exp: Add checks to detect if files
were built before attempting to copy them.
PR ld/18963
* testsuite/ld-scripts/pr18963.s: New, replaces empty data.s to
allocate space in text, data, bss here rather than pr18963.t.
* testsuite/ld-scripts/pr18963.t: Remove assignments to dot.
* testsuite/ld-scripts/pr18963.d: Change addresses to fit 16 bits.
When reconstructing dynamic symbol table from the PT_DYNAMIC segment,
compute dynamic symbol table size from hash table. For DT_HASH, the
number of dynamic symbol table entries equals the number of chains.
For DT_GNU_HASH/DT_MIPS_XHASH, only defined symbols with non-STB_LOCAL
indings are in hash table. Since DT_GNU_HASH/DT_MIPS_XHASH place all
symbols with STB_LOCAL binding before symbols with other bindings and
all undefined symbols defined ones in dynamic symbol table, the highest
symbol index in DT_GNU_HASH/DT_MIPS_XHASH is the highest dynamic symbol
table index.
Rewrite print_dynamic_symbol to dump dynamic symbol table for --dyn-syms
and --syms --use-dynamic.
binutils/
PR binutils/25707
* readelf.c (nbuckets): New.
(nchains): Likewise.
(buckets): Likewise.
(chains): Likewise.
(ngnubuckets): Likewise.
(gnubuckets): Likewise.
(gnuchains): Likewise.
(mipsxlat): Likewise.
(ngnuchains): Likewise.
(gnusymidx): Likewise.
(VALID_SYMBOL_NAME): Likewise.
(VALID_DYNAMIC_NAME): Use it.
(get_dynamic_data): Moved before process_dynamic_section.
(get_num_dynamic_syms): New function.
(process_dynamic_section): Use DT_SYMTAB, DT_SYMENT, DT_HASH,
DT_GNU_HASH and DT_MIPS_XHASH to reconstruct dynamic symbol
table. Use DT_STRTAB and DT_STRSZ to reconstruct dynamic string
table.
(get_symbol_index_type): Don't print "bad section index" when
there is no section header.
(print_dynamic_symbol): Rewrite.
(process_symbol_table): Call print_dynamic_symbol to dump dynamic
symbol table.
ld/
PR binutils/25707
* testsuite/ld-arm/armthumb-lib.sym: Updated.
* testsuite/ld-arm/farcall-mixed-app.sym: Likewise.
* testsuite/ld-arm/farcall-mixed-app2.sym: Likewise.
* testsuite/ld-arm/fdpic-main-m.sym: Likewise.
* testsuite/ld-arm/fdpic-main.sym: Likewise.
* testsuite/ld-arm/fdpic-shared-m.sym: Likewise.
* testsuite/ld-arm/fdpic-shared.sym: Likewise.
* testsuite/ld-arm/mixed-app.sym: Likewise.
* testsuite/ld-arm/mixed-lib.sym: Likewise.
* testsuite/ld-arm/preempt-app.sym: Likewise.
* testsuite/ld-elf/hash.d: Likewise.
* testsuite/ld-elf/pr13195.d: Likewise.
* testsuite/ld-elfvsb/hidden2.d: Likewise.
* testsuite/ld-mips-elf/hash2.d: Likewise.
Three ld tests currently FAIL on Solaris/SPARC:
FAIL: shared (non PIC)
FAIL: shared (non PIC, load offset)
FAIL: shared (PIC main, non PIC so)
all of them in the same way:
/var/gcc/binutils/sparcv7/obj/binutils/ld/tmpdir/ld/collect-ld: read-only
segment has dynamic relocations
Given that Solaris defaults to -z text, this is to be expected, thus
this patch xfail's them.
Tested on sparc-sun-solaris2.11 and sparcv9-sun-solaris2.11.
* testsuite/ld-shared/shared.exp: Remove dangling comments.
xfail shared non PIC tests on Solaris.
pr22269-1.s currently FAILs to assemble on 32-bit Solaris/SPARC:
ERROR: -K PIC tmpdir/pr22269-1.s: assembly failed
UNRESOLVED: pr22269-1 (static pie undefined weak)
tmpdir/pr22269-1.s: Assembler messages:
tmpdir/pr22269-1.s:27: Error: Architecture mismatch on "be,pn %icc,.LL4 ,pn %icc,.LL4".
tmpdir/pr22269-1.s:27: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
tmpdir/pr22269-1.s:32: Error: Architecture mismatch on "return %i7+8".
tmpdir/pr22269-1.s:32: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
tmpdir/pr22269-1.s:36: Error: Architecture mismatch on "return %i7+8".
tmpdir/pr22269-1.s:36: (Requires v9|v9a|v9b|v9c|v9d|v9e|v9v|v9m|m8; requested architecture is sparclite.)
I could trace this to the fact that gcc on sparc-sun-solaris2.* defaults
to --with-cpu=v9. So the gcc -S step of compiling the testcase is run
with -mcpu=v9, while the manual invocation of as-new lacks the
corresponding -Av9, creating a mismatch.
Solaris seems to be the only affected target, otherwise only
64-bit-default configurations default to --with-cpu=v9 or
--with-cpu=ultrasparc: sparcv9-*-*, sparc64-*-*,
sparc64-*-freebsd*, ultrasparc-*-freebsd*, and sparc64-*-openbsd*.
This patch just adds -Av9 to AFLAGS_PIC in ld-elf/shared.exp. It has a
precedent in ld-elfvers/vers.exp where -Av9a is added to as_options on
sparc-*-*. It lets the test pass and causes no other changes in
sparc-sun-solaris2.11 test results.
* testsuite/ld-elf/shared.exp: Add -Av9 to AFLAGS_PIC on sparc*-*-*.
GCC in Ubuntu 20.04 enables -fcf-protection by default, which leads to
FAIL: S-records
FAIL: S-records with constructors
FAIL: Build plt-main with -z bndplt
FAIL: Build plt-main with PIE and -z bndplt
FAIL: Build plt-main with -z bndplt -z now
FAIL: Build plt-main with PIE and -z bndplt -z now
on x86-64. Add NOCF_PROTECTION_CFLAGS to pass -fcf-protection=none on
these tests.
* testsuite/config/default.exp (NOCF_PROTECTION_CFLAGS): New.
Set to "-fcf-protection=none" if target compiler supports it.
* testsuite/ld-srec/srec.exp: Add $NOCF_PROTECTION_CFLAGS to
CC and CXX.
* testsuite/ld-x86-64/x86-64.exp: Add $NOCF_PROTECTION_CFLAGS
to PLT BND tests.
Compile with -I../bfd to include <bfd_stdint.h> in PR ld/25749 tests.
* testsuite/ld-elf/linux-x86.exp (check_pr25749a): Compile with
-I../bfd.
(check_pr25749b): Likewise.
A couple of ld ifunc tests currently FAIL on 64-bit Solaris/x86:
FAIL: ld-ifunc/ifunc-10-x86-64
FAIL: ld-ifunc/ifunc-11-x86-64
FAIL: ld-ifunc/ifunc-12-x86-64
FAIL: ld-ifunc/ifunc-13-x86-64
FAIL: ld-ifunc/ifunc-14a-x86-64
FAIL: ld-ifunc/ifunc-14b-x86-64
FAIL: ld-ifunc/ifunc-14c-x86-64
FAIL: ld-ifunc/ifunc-14d-x86-64
FAIL: ld-ifunc/ifunc-14e-x86-64
FAIL: ld-ifunc/ifunc-14f-x86-64
FAIL: ld-ifunc/ifunc-15-x86-64
FAIL: ld-ifunc/ifunc-17a-x86-64
FAIL: ld-ifunc/ifunc-17b-x86-64
FAIL: ld-ifunc/ifunc-2-local-x86-64-now
FAIL: ld-ifunc/ifunc-2-local-x86-64
FAIL: ld-ifunc/ifunc-2-x86-64-now
FAIL: ld-ifunc/ifunc-2-x86-64
FAIL: ld-ifunc/ifunc-20-x86-64
FAIL: ld-ifunc/pr17154-x86-64-now
FAIL: ld-ifunc/pr17154-x86-64
For one, the actual error is weird:
./ld-new: target elf64-x86-64 not found
failed with: <./ld-new: target elf64-x86-64 not found>, no expected output
FAIL: ld-ifunc/ifunc-10-x86-64
although ld -V does report the elf_x86_64 emulation as supported:
$ ./ld/ld-new -V
GNU ld (GNU Binutils) 2.34.50.20200328
Supported emulations:
elf_x86_64_sol2
elf_x86_64
[...]
When using ld -m elf_x86_64_sol2 instead, one of the testcases links
successfully.
However, there's no point in pursuing this: Solaris does not support
ifunc, as can be seen in <sys/elf.h>:
/*
* GNU/Linux specific symbol type not used by Solaris
*/
#define STT_GNU_IFUNC 10
and never will, given that it has symbol capabilities as solution to
effectively the same problem:
http://www.linker-aliens.org/blogs/rie/entry/symbol_capabilitie/
Therefore this patch disables ifunc testing on Solaris completely by
removing Solaris from binutils/testsuite/lib/binutils-common.exp
(supports_gnu_osabi). The ifunc part is justified above. SHF_GNU_MBIND is
in the OS-specific range and conflicts with
#define SHF_SUNW_REALLOC 0x01000000 /* internal: krtld realloc */
While the comment suggests this might be relocatable without too much
problems, the description of mbind (no formal spec AFAICS, just the
comment in the binutils patch submission) strongly suggests that this
isn't relevant to Solaris at all.
Indirectly, clearing supports_gnu_osabi on Solaris disables
supports_gnu_unique. Again, Solaris <sys/elf.h> has
/*
* GNU/Linux specific binding not used by Solaris
*/
#define STB_GNU_UNIQUE 10
so this seems the right thing to do.
Afterwards, one can remove the explicit mentions of *-*-solaris2* in
quite a number of (but not all) the ld-ifunc dump file notarget lists.
There's one fallout, though: two gas tests now XPASS because they are
xfail'ed for !supports_gnu_osabi:
XPASS: mbind sections 12
XPASS: mbind section contents 16
XPASS: mbind sections 16
XPASS: mbind section contents 16
To fix that, I've changed
#xfail: ![supports_gnu_osabi]
to notarget.
Tested on x86_64-pc-solaris2.11, i386-pc-solaris2.11,
x86_64-pc-linux-gnu, and i686-pc-linux-gnu.
ld:
* testsuite/ld-ifunc/ifunc-10-i386.d: Remove *-*-solaris2* from
notarget.
* ifunc-11-i386.d: Likewise.
* ifunc-12-i386.d: Likewise.
* ifunc-13-i386.d: Likewise.
* ifunc-14a-i386.d: Likewise.
* ifunc-14b-i386.d: Likewise.
* ifunc-14c-i386.d: Likewise.
* ifunc-14d-i386.d: Likewise.
* ifunc-14e-i386.d: Likewise.
* ifunc-14f-i386.d: Likewise.
* ifunc-15-i386.d: Likewise.
* ifunc-16-i386-now.d: Likewise.
* ifunc-16-i386.d: Likewise.
* ifunc-17a-i386.d: Likewise.
* ifunc-17b-i386.d: Likewise.
* ifunc-18a-i386.d: Likewise.
* ifunc-18b-i386.d: Likewise.
* ifunc-19a-i386.d: Likewise.
* ifunc-19b-i386.d: Likewise.
* ifunc-2-i386-now.d: Likewise.
* ifunc-2-i386.d: Likewise.
* ifunc-2-local-i386-now.d: Likewise.
* ifunc-2-local-i386.d: Likewise.
* ifunc-20-i386.d: Likewise.
* ifunc-21-i386.d: Likewise.
* ifunc-22-i386.d: Likewise.
* ifunc-5a-i386.d: Likewise.
* ifunc-5a-local-i386.d: Likewise.
* ifunc-5b-i386.d: Likewise.
* ifunc-5b-local-i386.d: Likewise.
* ifunc-5r-local-i386.d: Likewise.
* ifunc-6a-i386.d: Likewise.
* ifunc-6b-i386.d: Likewise.
* ifunc-7a-i386.d: Likewise.
* ifunc-7b-i386.d: Likewise.
* ifunc-8-i386.d: Likewise.
* ifunc-9-i386.d: Likewise.
* pr17154-i386-now.d: Likewise.
* pr17154-i386.d: Likewise.
* ifunc-23a-x86.d: Remove notarget.
* ifunc-24a-x86.d: Likewise.
* ifunc-25a-x86.d: Likewise.
gas:
* testsuite/gas/elf/section12a.d: Use notarget instead of xfail.
* testsuite/gas/elf/section12b.d: Likewise.
* testsuite/gas/elf/section16a.d: Likewise.
* testsuite/gas/elf/section16b.d: Likewise.
binutils:
* testsuite/lib/binutils-common.exp (supports_gnu_osabi): Don't
enable on *-*-solaris*.
Since value of non-preemptible absolute symbol (SHN_ABS) won't change,
only relocations, which can be resolved as absolute value + addend, and
GOTPCREL relocations, where absolute value + addend is stored in the GOT
slot, against non-preemptible absolute symbol are allowed in PIE and
shared library.
Also convert load relocation to R_386_32, R_X86_64_32S or R_X86_64_32 for
relocation against non-preemptible absolute symbol. Don't convert to
R_X86_64_32S nor R_X86_64_32 for non-preemptible absolute symbol if they
overflow.
bfd/
PR ld/25749
PR ld/25754
* elf32-i386.c (elf_i386_convert_load_reloc): Convert load
relocation to R_386_32 for relocation against non-preemptible
absolute symbol.
(elf_i386_check_relocs): Call _bfd_elf_x86_valid_reloc_p. Don't
allocate dynamic relocation for non-preemptible absolute symbol.
(elf_i386_relocate_section): Pass sec to
GENERATE_DYNAMIC_RELOCATION_P.
* elf64-x86-64.c (R_X86_64_converted_reloc_bit): Moved.
(elf_x86_64_convert_load_reloc): Covert load relocation to
R_X86_64_32S or R_X86_64_32 for relocation against non-preemptible
absolute symbol. Don't convert to R_X86_64_32S nor R_X86_64_32
for non-preemptible absolute symbol if they overflow.
(elf_x86_64_check_relocs): Call _bfd_elf_x86_valid_reloc_p. Set
tls_type for GOT slot to GOT_ABS for non-preemptible absolute
symbol. Don't allocate dynamic relocation for non-preemptible
absolute symbol.
(elf_x86_64_relocate_section): Don't generate relative relocation
for GOTPCREL relocations aganst local absolute symbol. Pass sec
to GENERATE_DYNAMIC_RELOCATION_P.
* elfxx-x86.c (elf_x86_allocate_dynrelocs): No dynamic relocation
against non-preemptible absolute symbol.
(_bfd_elf_x86_valid_reloc_p): New function.
(_bfd_x86_elf_size_dynamic_sections): No dynamic relocation for
GOT_ABS GOT slot.
* elfxx-x86.h (GENERATE_DYNAMIC_RELOCATION_P): Add an SEC
argument. Don't generate dynamic relocation against
non-preemptible absolute symbol.
(ABS_SYMBOL_P): New.
(GENERATE_RELATIVE_RELOC_P): Don't generate relative relocation
against non-preemptible absolute symbol.
(GOT_ABS): New.
(R_X86_64_converted_reloc_bit): New. Moved from elf64-x86-64.c.
(_bfd_elf_x86_valid_reloc_p): New.
ld/
PR ld/25749
PR ld/25754
* testsuite/ld-elf/linux-x86.exp: Run ld/25749 tests.
* testsuite/ld-elf/pr25749-1.c: New file.
* testsuite/ld-elf/pr25749-1a.c: Likewise.
* testsuite/ld-elf/pr25749-1b.c: Likewise.
* testsuite/ld-elf/pr25749-1b.err: Likewise.
* testsuite/ld-elf/pr25749-1c.c: Likewise.
* testsuite/ld-elf/pr25749-1d.c: Likewise.
* testsuite/ld-elf/pr25749-2.c: Likewise.
* testsuite/ld-elf/pr25749-2a.s: Likewise.
* testsuite/ld-elf/pr25749-2b.s: Likewise.
* testsuite/ld-elf/pr25749.rd: Likewise.
* testsuite/ld-elf/pr25754-1a.c: Likewise.
* testsuite/ld-elf/pr25754-1b.s: Likewise.
* testsuite/ld-elf/pr25754-2a.c: Likewise.
* testsuite/ld-elf/pr25754-2b.err: Likewise.
* testsuite/ld-elf/pr25754-2b.s: Likewise.
* testsuite/ld-elf/pr25754-3a.c: Likewise.
* testsuite/ld-elf/pr25754-3b.s: Likewise.
* testsuite/ld-elf/pr25754-4a.c: Likewise.
* testsuite/ld-elf/pr25754-4b.s: Likewise.
* testsuite/ld-elf/pr25754-4c.s: Likewise.
* testsuite/ld-elf/pr25754-5a.c: Likewise.
* testsuite/ld-elf/pr25754-5b.s: Likewise.
* testsuite/ld-elf/pr25754-5c.s: Likewise.
* testsuite/ld-elf/pr25754-6a.c: Likewise.
* testsuite/ld-elf/pr25754-6b.s: Likewise.
* testsuite/ld-x86-64/pr19609-6a.d: Don't expect linker error.
NaCL does not support dynamic linking and so these tests should be
skipped under it.
ld/ChangeLog:
PR ld/16017
* testsuite/ld-arm/arm-elf.exp (thumb-plt, thumb-plt-got): Skip for NaCL.
PR ld/25747
* ldfile.c (ldfile_open_file): If a search for a library fails,
but there is a file that would match if it had a "lib" prefix to
its name, then tell the user.
When you have a Thumb only PLT then the address in the GOT for PLT0 needs to
have the Thumb bit set since the instruction used in PLTn to get there is
`ldr.w pc` which is an inter-working instruction:
the PLT sequence in question is
00000120 <foo@plt>:
120: f240 0c98 movw ip, #152 ; 0x98
124: f2c0 0c01 movt ip, #1
128: 44fc add ip, pc
12a: f8dc f000 ldr.w pc, [ip]
12e: e7fc b.n 12a <foo@plt+0xa>
Disassembly of section .text:
00000130 <bar>:
130: b580 push {r7, lr}
132: af00 add r7, sp, #0
134: f7ff fff4 bl 120 <foo@plt>
and previously the linker would generate
Hex dump of section '.got':
...
0x000101b8 40010100 00000000 00000000 10010000 @...............
Which would make it jump and transition out of thumb mode and crash since you
only have thumb mode on such cores.
Now it correctly generates
Hex dump of section '.got':
...
0x000101b8 40010100 00000000 00000000 11010000 @...............
Thanks to Amol for testing patch and to rgujju for reporting it.
bfd/ChangeLog:
PR ld/16017
* elf32-arm.c (elf32_arm_populate_plt_entry): Set LSB of the PLT0
address in the GOT if in thumb only mode.
ld/ChangeLog:
PR ld/16017
* testsuite/ld-arm/arm-elf.exp (thumb-plt-got): New.
* testsuite/ld-arm/thumb-plt-got.d: New test.
When I previously changed these offsets I had incorrectly used an offset of -2
for this Thumb2 PLT. Unfortunately because we had no tests for this PLT I had
missed that the result was incorrect.
This patch fixes the offset to PC .-4 so that it correctly addresses the
previous instruction and adds a test for this PLT stub.
bfd/ChangeLog:
* elf32-arm.c (elf32_thumb2_plt_entry): Fix PC-rel offset.
ld/ChangeLog:
* testsuite/ld-arm/arm-elf.exp (thumb-plt): New.
* testsuite/ld-arm/thumb-plt.d: New test.
* testsuite/ld-arm/thumb-plt.s: New test.
A recent fix for the mmo input reader caused symbol-to-type mapping
(which is heuristic for the mmo format) to change (as in "corrected"),
and this test-case now passes.
Before that change, the comment was actually wrong: the symbol type
was mistakenly set to as B for uninitialized data, not T for text
section.
PR binutils/pr25662
bfd * libcoff-in.h (struct pe_tdata): Rename the insert_timestamp
field to timestamp and make it an integer.
* libcoff.h: Regenerate.
* peXXigen.c (_bfd_XXi_only_swap_filehdr_out): Test the timestamp
field in the pe_data structure rather than the insert_timestamp
field.
binutils* objcopy.c (copy_object): When copying PE format files set the
timestamp field in the pe_data structure if the preserve_dates
flag is set.
* testsuite/binutils-all/objcopy.exp (objcopy_test) Use
--preserve-dates in place of the -p option, in order to make its
effect more obvious.
ld * emultempl/pe.em (after_open): Replace initialisation of the
insert_timestamp field in the pe_data structure with an
initialisation of the timestamp field.
* emultemp/pep.em: Likewise.
* pe-dll.c (fill_edata): Use the timestamp field in the pe_data
structure instead of the insert_timestamp field.
Since COMMONPAGESIZE is set for other Solaris targets, including x86-64
Solaris, also set COMMONPAGESIZE for i386 Solaris to fix
FAIL: Build pr20995-2.so
FAIL: pr20995-2
PR 25732
* emulparams/elf_i386_ldso.sh (COMMONPAGESIZE): New.
* testsuite/ld-elf/shared.exp:Don't xfail pr20995-2 tests for
Solaris.
Since Solaris ld.so.1 doesn't support ifunc and never will, skip some
x86 IFUNC tests for Solaris.
PR 25732
* testsuite/ld-ifunc/ifunc-23a-x86.d: Add notarget for Solaris.
* testsuite/ld-ifunc/ifunc-24a-x86.d: Likewise.
* testsuite/ld-ifunc/ifunc-25a-x86.d: Likewise.
Extend _bfd_elf_get_symbol_version_string for nm -D to display symbol
version. _bfd_elf_get_symbol_version_name is added to avoid updating
all XXX_get_symbol_version_string functions.
bfd/
PR binutils/25708
* elf-bfd.h (_bfd_elf_get_symbol_version_name): New.
* elf.c (_bfd_elf_get_symbol_version_name): New function. Based
on the previous _bfd_elf_get_symbol_version_string.
(_bfd_elf_get_symbol_version_string): Use it.
binutils/
PR binutils/25708
* nm.c (SYM_NAME): Removed.
(print_symname): Add a pointer to struct extended_symbol_info
argument. Call _bfd_elf_get_symbol_version_name to get symbol
version.
(print_symdef_entry): Pass NULL to print_symname.
(print_symbol_info_bsd): Update call to print_symname.
(print_symbol_info_sysv): Likewise.
(print_symbol_info_posix): Likewise.
ld/
PR binutils/25708
* testsuite/ld-elf/pr25708.d: New file.
Also reinstate ld i386aout for i386-msdos target, which doesn't build
otherwise.
bfd/
* i386msdos.c (msdos_object_p): Don't access e_lfanew when that
field hasn't been read. Remove unnecessary casts.
ld/
* Makefile.am (ALL_EMULATION_SOURCES): Reinstate ei386aout.c.
Include ei386aout dep file.
* Makefile.in: Regenerate.
* po/BLD-POTFILES.in: Regenerate.
This test XPASSes on the generic ELF targets, so adjusting. I also
made xtensa an xfail instead of a skip, since skip is hiding some
nastiness.
* testsuite/ld-elf/non-contiguous.d: Don't xfail generic ELF
targets. Don't skip xtensa, xfail instead.
On Linux/x86, when -static is passed to gcc, gcc passes it to linker
before all input files suitable for creating static executable. X86
linker will report error for dynamic input objects if -static is passed
at command-line before all input files without --dynamic-linker unless
--no-dynamic-linker is used.
bfd/
PR ld/24920
* elf-linker-x86.h (elf_linker_x86_params): Add
static_before_all_inputs and has_dynamic_linker.
* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): Report
dynamic input objects if -static is passed at command-line
before all input files without --dynamic-linker unless
--no-dynamic-linker is used.
ld/
PR ld/24920
* emulparams/elf32_x86_64.sh: Use static.sh.
* emulparams/elf_i386.sh: Likewise.
* emulparams/elf_x86_64.sh: Likewise.
* emulparams/static.sh: New file.
* emultempl/elf-x86.em: Include "ldlex.h".
* testsuite/ld-elf/pr24920.err: New file.
* testsuite/ld-elf/linux-x86.exp: Run ld/24920 tests.
When converting between addresses in ELF headers [octets] and bfd
LMA/VMA [bytes], the number of octets per byte needs to be
incorporated.
In ld, the SIZEOF_HEADERS linker script statement must be resolved to
bytes instead of octets.
include/
* elf/internal.h (struct elf_internal_phdr): Add unit (octets)
to several member field comments.
(Elf_Internal_Shdr): likewise.
bfd/
* elf.c (_bfd_elf_make_section_from_shdr): Introduce new temp
opb. Divide Elf_Internal_Shdr::sh_addr by opb when setting
section LMA/VMA.
(_bfd_elf_make_section_from_phdr): Similarly.
(elf_fake_sections): Fix calculation of
Elf_Internal_shdr::sh_addr from section VMA.
(_bfd_elf_map_sections_to_segments): Fix mixup between octets
and bytes.
(assign_file_positions_for_load_sections): Fix calculations of
Elf_Internal_shdr::p_vaddr and p_paddr from section LMA/VMA. Fix
comparison between program header address and section LMA.
(assign_file_positions_for_non_load_sections): Likewise.
(rewrite_elf_program_header): Likewise. Introduce new temp opb.
(IS_CONTAINED_BY_VMA): Add parameter opb.
(IS_CONTAINED_BY_LMA,IS_SECTION_IN_INPUT_SEGMENT,
INCLUDE_SECTION_IN_SEGMENT): Likewise.
(copy_elf_program_header): Update call to ELF_SECTION_IN_SEGMENT.
Fix calculations of p_addr_valid and p_vaddr_offset.
* elflink.c (elf_link_add_object_symbols): Multiply section VMA
with octets per byte when comparing against p_vaddr.
ld/
* ldexp.c (fold_name): Return SIZEOF_HEADERS in bytes.
Not just SHF_EXCLUDE but any of these flags ought to prevent merging
of sections for ld -r.
* ldelf.c (elf_orphan_compatible): Return false when two sections
have differing SHF_MASKPROC or SHF_MASKOS flags.
PR 25570
* ldlang.c (lang_size_sections_1): Don't report changes on
second and subsequent iterations that make no change in
alignment from that already reported.
Note that because we should report a signed delta from the previous
VMA it isn't possible to use ngettext. ngettext only supports
unsigned long values. So byte/bytes goes from the message.
PR 25570
* ldlang.c (lang_sizing_iteration): New static var.
(lang_size_sections_1): Warn about no memory region only on first
iteration. Warn about changing start address on first iteration
then any delta from that on subsequent iterations. Report a signed
delta.
(one_lang_size_sections_pass): Increment lang_sizing_iteration.
The object_p (and archive_p, core_file_p) functions are not supposed
to have any target specific malloc'd memory attached to the bfd on
their return. This should be obvious on a failure return, but it's
also true for a successful return. The reason is that even though the
object_p recognises the file, that particular target may not be used
and thus the bfd won't be closed calling close_and_cleanup for the
target that allocated the memory.
It turns out that the object_p bfd_target* return value isn't needed.
In all cases except ld/plugin.c the target is abfd->xvec and with
ld/plugin.c the target isn't used. So this patch returns a cleanup
function from object_p instead, called in bfd_check_format_matches to
tidy the bfd before trying a different target match. The only cleanup
that does anything at this stage is the alpha-vms one.
bfd/
* targets.c (bfd_cleanup): New typedef.
(struct bfd <_bfd_check_format>): Return a bfd_cleanup.
* libbfd-in.h (_bfd_no_cleanup): Define.
* format.c (bfd_reinit): Add cleanup parameter, call it.
(bfd_check_format_matches): Set cleanup from _bfd_check_format
call and pass to bfd_reinit. Delete temp, use abfd->xvec instead.
* aout-target.h (callback, object_p): Return bfd_cleanup.
* aout-tic30.c (tic30_aout_callback, tic30_aout_object_p): Likewise.
* archive.c (bfd_generic_archive_p): Likewise.
* binary.c (binary_object_p): Likewise.
* coff-alpha.c (alpha_ecoff_object_p): Likewise.
* coff-ia64.c (ia64coff_object_p): Likewise.
* coff-rs6000.c (_bfd_xcoff_archive_p, rs6000coff_core_p): Likewise.
* coff-sh.c (coff_small_object_p): Likewise.
* coff-stgo32.c (go32_check_format): Likewise.
* coff64-rs6000.c (xcoff64_archive_p, rs6000coff_core_p),
(xcoff64_core_p): Likewise.
* coffgen.c (coff_real_object_p, coff_object_p): Likewise.
* elf-bfd.h (bfd_elf32_object_p, bfd_elf32_core_file_p),
(bfd_elf64_object_p, bfd_elf64_core_file_p): Likewise.
* elfcode.h (elf_object_p): Likewise.
* elfcore.h (elf_core_file_p): Likewise.
* i386msdos.c (msdos_object_p): Likewise.
* ihex.c (ihex_object_p): Likewise.
* libaout.h (some_aout_object_p): Likewise.
* libbfd-in.h (bfd_generic_archive_p, _bfd_dummy_target),
(_bfd_vms_lib_alpha_archive_p, _bfd_vms_lib_ia64_archive_p): Likewise.
* libbfd.c (_bfd_dummy_target): Likewise.
* libcoff-in.h (coff_object_p): Likewise.
* mach-o-aarch64.c (bfd_mach_o_arm64_object_p),
(bfd_mach_o_arm64_core_p): Likewise.
* mach-o-arm.c (bfd_mach_o_arm_object_p),
(bfd_mach_o_arm_core_p): Likewise.
* mach-o-i386.c (bfd_mach_o_i386_object_p),
(bfd_mach_o_i386_core_p): Likewise.
* mach-o-x86-64.c (bfd_mach_o_x86_64_object_p),
(bfd_mach_o_x86_64_core_p): Likewise.
* mach-o.c (bfd_mach_o_header_p, bfd_mach_o_gen_object_p),
(bfd_mach_o_gen_core_p, bfd_mach_o_fat_archive_p): Likewise.
* mach-o.h (bfd_mach_o_object_p, bfd_mach_o_core_p),
(bfd_mach_o_fat_archive_p, bfd_mach_o_header_p): Likewise.
* mmo.c (mmo_object_p): Likewise.
* pef.c (bfd_pef_object_p, bfd_pef_xlib_object_p): Likewise.
* peicode.h (coff_real_object_p, pe_ILF_object_p),
(pe_bfd_object_p): Likewise.
* plugin.c (ld_plugin_object_p, bfd_plugin_object_p): Likewise.
* ppcboot.c (ppcboot_object_p): Likewise.
* rs6000-core.c (rs6000coff_core_p): Likewise.
* som.c (som_object_setup, som_object_p): Likewise.
* srec.c (srec_object_p, symbolsrec_object_p): Likewise.
* tekhex.c (tekhex_object_p): Likewise.
* vms-alpha.c (alpha_vms_object_p): Likewise.
* vms-lib.c (_bfd_vms_lib_archive_p, _bfd_vms_lib_alpha_archive_p),
(_bfd_vms_lib_ia64_archive_p, _bfd_vms_lib_txt_archive_p): Likewise.
* wasm-module.c (wasm_object_p): Likewise.
* xsym.c (bfd_sym_object_p): Likewise.
* xsym.h (bfd_sym_object_p): Likewise.
* aoutx.h (some_aout_object_p): Likewise, and callback parameter
return type.
* pdp11.c (some_aout_object_p): Likewise.
* plugin.c (register_ld_plugin_object_p): Update object_p
parameter type.
* plugin.h (register_ld_plugin_object_p): Likewise.
* bfd-in2.h: Regenerate.
* libbfd.h: Regenerate.
* libcoff.h: Regenerate.
ld/
* plugin.c (plugin_object_p): Return a bfd_cleanup.
(plugin_cleanup): New function.
Copy the no_export field to the IR dummy object when claiming an IR
object.
PR ld/25618
* plugin.c (plugin_object_p): Copy the no_export field to the IR
dummy object.
* testsuite/ld-plugin/lto.exp (lto_link_elf_tests): Add
PR ld/25618 tests.
* testsuite/ld-plugin/pr25618.d: New file.
* testsuite/ld-plugin/pr25618a.cc: Likewise.
* testsuite/ld-plugin/pr25618a.h: Likewise.
* testsuite/ld-plugin/pr25618b.cc: Likewise.
* testsuite/ld-plugin/pr25618b.h: Likewise.