The problem was the ld expect libiberty/lrealpath() to always return a
path, but in some cases it returns a prefix. It seemed like too much of
an earthquake to propose a fix to lrealpath.
* ldmain.c (main): Remove directory separator, if any, from the
end of the canonicalized sysroot.
This patch adds --enable-separate-code to ld configure to turn on
-z separate-code by default and enables it by default for Linux/x86.
This avoids mixing code pages with data to improve cache performance
as well as security.
To reduce x86-64 executable and shared object sizes, the maximum page
size is reduced from 2MB to 4KB when -z separate-code is turned on by
default. Note: -z max-page-size= can be used to set the maximum page
size.
We compared SPEC CPU 2017 performance before and after this change on
Skylake server. There are no any significant performance changes.
Everything is mostly below +/-1%.
bfd/
* config.in: Regenerated.
* configure: Likewise.
* configure.ac: Add --enable-separate-code.
(DEFAULT_LD_Z_SEPARATE_CODE): New AC_DEFINE_UNQUOTED. Default
to 1 for Linux/x86 targets,
* elf64-x86-64.c (ELF_MAXPAGESIZE): Set to 0x1000 if
DEFAULT_LD_Z_SEPARATE_CODE is 1.
ld/
* NEWS: Mention --enable-separate-code.
* configure.ac: Add --enable-separate-code.
(DEFAULT_LD_Z_SEPARATE_CODE): New AC_DEFINE_UNQUOTED.
* configure.tgt: Default ac_default_ld_z_separate_code to 1 for
Linux/x86 targets.
* config.in: Regenerated.
* configure: Likewise.
* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Set
link_info.separate_code DEFAULT_LD_Z_SEPARATE_CODE.
Most of the emultempl/*.em error/warning messages do not currently
appear in ld.pot, and fixing that is not simply a matter of adding
missing files to POTFILES. The difficulty is the shell-script
quoting, for example aarch64elf.em:PARSE_AND_LIST_OPTIONS "Don'\''t".
I suppose you could avoid contractions like "don't" but I'm unsure as
to whether gettext could handle everything in the emulparams scripts.
The right thing to do is feed the generated C files to gettext, as
this patch does. The patch just copies what is already done in bfd/
for generated files.
* Makefile.am (EMULATION_FILES, POTFILES): Delete.
(SRC_POTFILES, BLD_POTFILES): Define.
(po/POTFILES.in): Delete rule.
(po/SRC-POTFILES.in, po/BLD-POTFILES.in): New rules.
* configure.ac: Add AC_CONFIG_COMMANDS to create po/Makefile.
* po/Make-in (DISTFILES): Remove POTFILES.in, add SRC-POTFILES.in
and BLD-POTFILES.in.
(POTFILES): Delete.
(SRC-POTFILES, BLD-POTFILES): Define place marker.
(ld.pot): Build from SRC-POTFILES plus BLD-POTFILES.
(distclean, maintainer-clean): Tidy up new files.
(POTFILES, POTFILES.in): Delete rules.
(SRC-POTFILES, BLD-POTFILES, SRC-POTFILES.in, BLD-POTFILES.in):
New rules.
(Makefile): Depend on SRC-POTFILES and BLD-POTFILES.
* po/SRC-POTFILES.in: Rename from po/POTFILES.in.
* po/BLD-POTFILES.in: New file.
* Makefile.in: Regenerate.
* configure: Regenerate.
More standarization of error/warning messages. The ARM backend has
some multi-line error messages, which don't fit particularly well with
the GNU coding standard insistence that error messages shouldn't be
capitalized or have a full-stop. I've replaced the line breaks with
semicolons.
So for instance the following
system/path/to/ld: myobject.o: invalid special symbol `foo'.
system/path/to/ld: It must be a global or weak function symbol.
becomes
system/path/to/ld: myobject.o: invalid special symbol `foo'; it must be a global or weak function symbol
bfd/
* elf32-arm.c, * elfnn-aarch64.c: Standardize error/warning messages.
ld/
* testsuite/ld-aarch64/reloc-overflow-bad.d,
* testsuite/ld-arm/attr-merge-9.out,
* testsuite/ld-arm/attr-merge-arch-2.d,
* testsuite/ld-arm/attr-merge-unknown-1.d,
* testsuite/ld-arm/attr-merge-unknown-2.d,
* testsuite/ld-arm/attr-merge-unknown-2r.d,
* testsuite/ld-arm/attr-merge-unknown-3.d,
* testsuite/ld-arm/cmse-implib-errors.out,
* testsuite/ld-arm/cmse-new-earlier-later-implib.out,
* testsuite/ld-arm/cmse-new-implib-no-output.out,
* testsuite/ld-arm/cmse-new-implib-not-sg-in-implib.out,
* testsuite/ld-arm/cmse-new-implib.out,
* testsuite/ld-arm/cmse-new-wrong-implib.out,
* testsuite/ld-arm/cmse-veneers-no-gnu_sgstubs.out,
* testsuite/ld-arm/cmse-veneers-wrong-entryfct.out,
* testsuite/ld-arm/group-relocs-alu-bad-2.d,
* testsuite/ld-arm/group-relocs-alu-bad.d,
* testsuite/ld-arm/group-relocs-ldc-bad-2.d,
* testsuite/ld-arm/group-relocs-ldc-bad.d,
* testsuite/ld-arm/group-relocs-ldr-bad-2.d,
* testsuite/ld-arm/group-relocs-ldr-bad.d,
* testsuite/ld-arm/group-relocs-ldrs-bad-2.d,
* testsuite/ld-arm/group-relocs-ldrs-bad.d,
* testsuite/ld-arm/stm32l4xx-cannot-fix-far-ldm.d: Update.
The GNU coding standard says error messages should be of the form
program:sourcefile:lineno: message
or
program: message
and
"The string message should not begin with a capital letter when it
follows a program name and/or file name, because that isn’t the
beginning of a sentence. (The sentence conceptually starts at the
beginning of the line.) Also, it should not end with a period."
This patch does that for ppc, and removes some British spelling.
I've also switched some error output from using the linker callback
einfo to _bfd_error_handler, due to improved compilation time
argument checking now done for the latter function.
bfd/
* elf32-ppc.c: Standardize error/warning messages. Use
_bfd_error_handler rather than einfo when einfo features not used.
* elf64-ppc.c: Likewise.
ld/
* testsuite/ld-powerpc/attr-gnu-12-21.d: Update.
* testsuite/ld-powerpc/attr-gnu-4-12.d: Update.
* testsuite/ld-powerpc/attr-gnu-4-13.d: Update.
* testsuite/ld-powerpc/attr-gnu-4-21.d: Update.
* testsuite/ld-powerpc/attr-gnu-4-23.d: Update.
* testsuite/ld-powerpc/attr-gnu-4-31.d: Update.
* testsuite/ld-powerpc/attr-gnu-4-32.d: Update.
* testsuite/ld-powerpc/attr-gnu-8-23.d: Update.
Use the SEC_FIXED_SIZE flag to actually fix the size of `.reginfo' and
`.MIPS.abiflags' sections in `_bfd_mips_elf_always_size_sections', as
originally intended, removing link failures such as:
ld: final link failed: Section has no contents
or:
ld: final link failed: Bad value
or:
ld: foo: .reginfo section size should be 24 bytes, actual size is 32
and assertion failures like:
ld: BFD (GNU Binutils) 2.30.51.20180131 assertion fail .../bfd/elfxx-mips.c:14322
in link scenarios involving a linker script that either creates an
output `.reginfo' or `.MIPS.abiflags' section from scratch or produces
either section from different sections. If such an output section's
size turns out to be incorrect according to the psABI, then the section
is either truncated or padded out to the correct size, as relevant.
This allows people to handle these sections in a link in an unusual way,
while still addressing the issue covered by commit 58807c48a5
("_bfd_mips_elf_final_link: Notify user about wrong .reginfo size").
The original arrangement, coming from an unindentified change made to
what was called `mips_elf_always_size_sections' back then, between
commit 02650bd0a9 ("This adds ABI flags to MIPS/ELF object files.")
and commit 252b5132c7 ("19990502 sourceware import"), also missing
from BFD ChangeLog files, assumed that the output section size is not
going to change after return from `bfd_elf_size_dynamic_sections', the
caller of that function, called in turn from `ldemul_before_allocation'
via `gld${EMULATION_NAME}_before_allocation' in ld/emultempl/elf32.em,
and ultimately from `lang_process'. This is because later on in
`lang_process' processing `lang_size_sections' is called , happily
recalculating the section size, and it has actually already been the
case at the time of commit 252b5132c7 ("19990502 sourceware import"),
so the assumption was clearly incorrect right from the beginning.
bfd/
* elfxx-mips.c (_bfd_mips_elf_always_size_sections): Set
SEC_FIXED_SIZE and SEC_HAS_CONTENTS flags for `.reginfo' and
`.MIPS.abiflags' sections.
(_bfd_mips_elf_final_link): Avoid reading beyond `.reginfo'
section's end.
ld/
* testsuite/ld-mips-elf/reginfo-0.d: New test.
* testsuite/ld-mips-elf/reginfo-0r.d: New test.
* testsuite/ld-mips-elf/reginfo-1.d: New test.
* testsuite/ld-mips-elf/reginfo-1r.d: New test.
* testsuite/ld-mips-elf/reginfo-2.d: New test.
* testsuite/ld-mips-elf/reginfo-2r.d: New test.
* testsuite/ld-mips-elf/mips-abiflags-0.d: New test.
* testsuite/ld-mips-elf/mips-abiflags-0r.d: New test.
* testsuite/ld-mips-elf/mips-abiflags-1.d: New test.
* testsuite/ld-mips-elf/mips-abiflags-1r.d: New test.
* testsuite/ld-mips-elf/mips-abiflags-2.d: New test.
* testsuite/ld-mips-elf/mips-abiflags-2r.d: New test.
* testsuite/ld-mips-elf/reginfo-0.ld: New test linker script.
* testsuite/ld-mips-elf/reginfo-1.ld: New test linker script.
* testsuite/ld-mips-elf/mips-abiflags-0.ld: New test linker
script.
* testsuite/ld-mips-elf/mips-abiflags-1.ld: New test linker
script.
* testsuite/ld-mips-elf/reginfo-1.s: New test source.
* testsuite/ld-mips-elf/reginfo-2.s: New test source.
* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
Define a SEC_FIXED_SIZE section flag for target backends to use for
output sections whose size has been fixed in the psABI. The size of
such sections will not be changed anyhow by the generic linker and it is
up to the target backend to get their size right.
bfd/
* section.c (SEC_FIXED_SIZE): New macro.
* bfd-in2.h: Regenerate.
ld/
* ldlang.c (insert_pad): Do not change output section's size if
SEC_FIXED_SIZE is set in the flags.
(size_input_section): Likewise.
(lang_size_sections_1): Likewise.
(lang_reset_memory_regions): Likewise.
ld-elf/ehdr_start fails with -z separate-code. Since there is no data
LOAD segment before code LOAD segment:
There are 2 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x200000 0x0000000000600000 0x0000000000600000 0x000010 0x000010 R E 0x200000
LOAD 0x400000 0x0000000000800000 0x0000000000800000 0x000008 0x000008 R 0x200000
Section to Segment mapping:
Segment Sections...
00 .text
01 .rodata
the program header isn't included in any LOAD segment. As the result,
reference to __ehdr_start is resolved to zero. Pass --build-id to ld
to add a data LOAD segment before code LOAD segment to put the program
header in the data LOAD segment.
PR ld/22845
* testsuite/ld-elf/ehdr_start.d: Pass --build-id to ld.
-z separate-code creates separate code LOAD segment, aligns it to the
maximum page size and places .plt section before .text section. But
ld-elf/eh4 passes -Ttext 0x400 to linker to place .text section at
address 0x400, which is impossible for linker to accomplish:
$ ld -shared -Ttext 0x400 -z separate-code -o x.so eh4.o
ld: section .eh_frame LMA [0000000000200000,000000000020006b] overlaps section .plt LMA [0000000000200000,000000000020001f]
Since ld-elf/eh4 also checks exact addresses, this patch passes
-z max-page-size=0x200000 -z noseparate-code to ld.
PR ld/22845
* ld-elf/eh4.d: Pass -z max-page-size=0x200000 -z noseparate-code
to ld.
"-z separate-code" generates different addresses. Update these tests
to accept any addresses.
* testsuite/ld-x86-64/bnd-ifunc-1.d: Updated.
* testsuite/ld-x86-64/ilp32-4.d: Likewise.
Add -z noseparate-code -z max-page-size=0x200000 since these tests
check for exact addresses and don't expect extra PT_LOAD segment. But
don't add them to nacl targets since they generate different addresses.
* testsuite/ld-x86-64/x86-64.exp: Add -z noseparate-code
-z max-page-size=0x200000, excluding NaCl target.
These tests fail due to one extra PT_LOAD segment with -z separate-code.
* testsuite/ld-elf/pr19162.d: Add -z noseparate-code.
* testsuite/ld-elf/textaddr1.d: Likewise.
* testsuite/ld-elf/textaddr2.d: Likewise.
* testsuite/ld-elf/textaddr4.d: Likewise.
* testsuite/ld-elf/textaddr6.d: Likewise.
bfd/
* elfnn-riscv.c (riscv_elf_relocate_section): Use bfd_reloc_dangerous
when pcrel_lo reloc has an addend. Use reloc_dangerous callback for
bfd_reloc_dangerous. Use einfo instead of warning callback for errors.
Add %X%P to error messages.
ld/
* testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run pcrel-lo-addend test.
* testsuite/ld-riscv-elf/pcrel-lo-addend.d: New.
* testsuite/ld-riscv-elf/pcrel-lo-addend.s: New.
Since PLT in PDE and PC-relative PLT in PIE can be used as function
address, there is no need for dynamic PC-relative relocation against
a dynamic function definition in PIE. Linker should resolve PC-relative
reference to its PLT address.
NB: i386 has non-PIC PLT and PIC PLT. Only non-PIC PLT in PDE can
be used as function address. PIC PLT in PIE can't be used as
function address.
bfd/
PR ld/22842
* elf32-i386.c (elf_i386_check_relocs): Pass FALSE for non
PC-relative PLT to NEED_DYNAMIC_RELOCATION_P.
* elf64-x86-64.c (elf_x86_64_check_relocs): Create PLT for
R_X86_64_PC32 reloc against dynamic function in data section.
Pass TRUE for PC-relative PLT to NEED_DYNAMIC_RELOCATION_P.
(elf_x86_64_relocate_section): Use PLT for R_X86_64_PC32 reloc
against dynamic function in data section.
* elfxx-x86.c (elf_x86_allocate_dynrelocs): Use PLT in PIE as
function address only if pcrel_plt is true.
(_bfd_x86_elf_link_hash_table_create): Set pcrel_plt.
* elfxx-x86.h (NEED_DYNAMIC_RELOCATION_P): Add PCREL_PLT for
PC-relative PLT. If PLT is PC-relative, don't generate dynamic
PC-relative relocation against a function definition in data
secton in PIE. Remove the obsolete comments.
(elf_x86_link_hash_table): Add pcrel_plt.
ld/
PR ld/22842
* testsuite/ld-i386/i386.exp: Run PR ld/22842 tests.
* testsuite/ld-x86-64/x86-64.exp: Likewise.
* testsuite/ld-i386/pr22842a.c: New file.
* testsuite/ld-i386/pr22842b.S: Likewise.
* testsuite/ld-x86-64/pr22842a.c: Likewise.
* testsuite/ld-x86-64/pr22842a.rd: Likewise.
* testsuite/ld-x86-64/pr22842b.S: Likewise.
* testsuite/ld-x86-64/pr22842b.rd: Likewise.
Complement commit d4e5e3c330 ("Use getopt instead of lex and yacc to
parse the command line.") and remove a stale `ldlex_command' prototype
for an inexistent function removed back in 1994.
ld/
* ldlex.h (ldlex_command): Remove prototype.
They should be pr22393-3a.so and pr22393-3a-now.so, not pr22393-2a.so
and pr22393-2a-now.so. Since ld-elf/shared.exp creates pr22393-2a.so
and pr22393-2a-now.so, we won't notice the problem if x86-64.exp runs
after ld-elf/shared.exp.
* testsuite/ld-x86-64/x86-64.exp: Replace pr22393-2a.so and
pr22393-2a-now.so with pr22393-3a.so and pr22393-3a-now.so.
Since there is no need to prepare for PLT branch on x86-64, generate
R_X86_64_PLT32, instead of R_X86_64_PC32, if possible, which can be
used as a marker for 32-bit PC-relative branches.
To compile Linux kernel, this patch:
From: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH] x86: Treat R_X86_64_PLT32 as R_X86_64_PC32
On i386, there are 2 types of PLTs, PIC and non-PIC. PIE and shared
objects must use PIC PLT. To use PIC PLT, you need to load
_GLOBAL_OFFSET_TABLE_ into EBX first. There is no need for that on
x86-64 since x86-64 uses PC-relative PLT.
On x86-64, for 32-bit PC-relative branches, we can generate PLT32
relocation, instead of PC32 relocation, which can also be used as
a marker for 32-bit PC-relative branches. Linker can always reduce
PLT32 relocation to PC32 if function is defined locally. Local
functions should use PC32 relocation. As far as Linux kernel is
concerned, R_X86_64_PLT32 can be treated the same as R_X86_64_PC32
since Linux kernel doesn't use PLT.
is needed. It is available on hjl/plt32/master branch at
https://github.com/hjl-tools/linux
bfd/
PR gas/22791
* elf64-x86-64.c (is_32bit_relative_branch): Removed.
(elf_x86_64_relocate_section): Check PIC relocations in PIE.
Remove is_32bit_relative_branch usage. Disallow PC32 reloc
against protected function in shared object.
gas/
PR gas/22791
* config/tc-i386.c (need_plt32_p): New function.
(output_jump): Generate BFD_RELOC_X86_64_PLT32 if possible.
(md_estimate_size_before_relax): Likewise.
* testsuite/gas/i386/reloc64.d: Updated.
* testsuite/gas/i386/x86-64-jump.d: Likewise.
* testsuite/gas/i386/x86-64-mpx-branch-1.d: Likewise.
* testsuite/gas/i386/x86-64-mpx-branch-2.d: Likewise.
* testsuite/gas/i386/x86-64-relax-2.d: Likewise.
* testsuite/gas/i386/x86-64-relax-3.d: Likewise.
* testsuite/gas/i386/ilp32/reloc64.d: Likewise.
* testsuite/gas/i386/ilp32/x86-64-branch.d: Likewise.
ld/
PR gas/22791
* testsuite/ld-x86-64/mpx1c.rd: Updated.
* testsuite/ld-x86-64/pr22791-1.err: New file.
* testsuite/ld-x86-64/pr22791-1a.c: Likewise.
* testsuite/ld-x86-64/pr22791-1b.s: Likewise.
* testsuite/ld-x86-64/pr22791-2.rd: Likewise.
* testsuite/ld-x86-64/pr22791-2a.s: Likewise.
* testsuite/ld-x86-64/pr22791-2b.c: Likewise.
* testsuite/ld-x86-64/pr22791-2c.s: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/22791 tests.
This fixes the case where all of a group is removed with ld -r, the
situation in the PR, and failures where part of a group is removed
that contain relocs.
bfd/
PR 22836
* elf.c (_bfd_elf_fixup_group_sections): Account for removed
relocation sections. If size reduces to just the flag word,
remove that too and mark with SEC_EXCLUDE.
* elflink.c (bfd_elf_final_link): Strip empty group sections.
binutils/
* testsuite/binutils-all/group-7.s,
* testsuite/binutils-all/group-7a.d,
* testsuite/binutils-all/group-7b.d,
* testsuite/binutils-all/group-7c.d: New tests.
* testsuite/binutils-all/objcopy.exp: Run them.
ld/
* testsuite/ld-elf/pr22836-2.d,
* testsuite/ld-elf/pr22836-2.s: New test.
lld lays out the relro segment differently to GNU ld, not bothering to
include the first few bytes of .got.plt and padding out to a page at
the end of the segment. This patch teaches binutils to recognize the
different (and somewhat inferior) layout as valid.
bfd/
PR 22829
* elf.c (assign_file_positions_for_non_load_sections): Rewrite
PT_GNU_RELRO setup.
ld/
* testsuite/ld-x86-64/pr14207.d: Adjust relro p_filesz.
This reverts most of commit 1be5d8d3bb.
Left in place are addition of --no-plt-align to some ppc32 ld tests
and the ld.texinfo --no-plt-thread-safe fix.
This is -fpie -pie generating dynamic relocations in the text section,
simply because no TLS transitions are applied in PIE mode. The meat
of the patch is to turn calls to bfd_link_pic (info) in TLS-related code
into !bfd_link_executable (info) and there are quite a lot of them...
bfd/
* elfxx-sparc.c (sparc_elf_tls_transition): Turn call to bfd_link_pic
into call to !bfd_link_executable and tidy up.
(_bfd_sparc_elf_check_relocs): Fix formatting and tidy up.
<R_SPARC_TLS_LE_HIX22>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_TLS_IE_HI22>: Likewise.
<GOT relocations>: Remove useless code, tidy and merge blocks.
<R_SPARC_TLS_GD_CALL>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_WPLT30>: Tidy up.
(_bfd_sparc_elf_gc_mark_hook): Turn call to bfd_link_pic into call
to !bfd_link_executable.
(allocate_dynrelocs): Likewise.
(_bfd_sparc_elf_relocate_section): Fix formatting and tidy up.
<R_SPARC_TLS_GD_HI22>: Merge into...
<R_SPARC_TLS_GD_LO10>: ...this. Adjust 4th argument in call to
sparc_elf_tls_transition and remove redundant code.
<R_SPARC_TLS_LDM_HI22>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_TLS_LDO_HIX22>: Likewise.
<R_SPARC_TLS_LE_HIX22>: Likewise. Tidy up.
<R_SPARC_TLS_LDM_CALL>: Likewise.
<R_SPARC_TLS_GD_CALL>: Likewise. Tidy up.
<R_SPARC_TLS_GD_ADD>: Likewise.
<R_SPARC_TLS_LDM_ADD>: Likewise.
<R_SPARC_TLS_LDO_ADD>: Likewise.
<R_SPARC_TLS_IE_LD>: Likewise.
ld/
* testsuite/ld-elf/tls.exp (AFLAGS_PIC): Define on SPARC.
(pr22263-1): Pass AFLAGS_PIC to the assembler.
* testsuite/ld-sparc/tlspie32.s: Add test for other 3 transitions.
* testsuite/ld-sparc/tlspie32.dd: Adjust to above.
* testsuite/ld-sparc/tlspie64.s: Add test for other 3 transitions.
* testsuite/ld-sparc/tlspie64.dd: Adjust to above.
The assumption that R_AARCH64_ABS16 and R_AARCH64_ABS32 relocation in LP64 abi
will be used to generate an address does not hold for absolute symbol.
In this case, it is a value fixed at static linking time.
The condition to check the relocations is relax to allow absolute symbol and
undefined symbol case.
bfd/
2018-02-05 Renlin Li <renlin.li@arm.com>
PR ld/22764
* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Relax the
R_AARCH64_ABS32 and R_AARCH64_ABS16 for absolute symbol. Apply the
check for writeable section as well.
ld/
2018-02-05 Renlin Li <renlin.li@arm.com>
PR ld/22764
* testsuite/ld-aarch64/emit-relocs-258.s: Define symbol as an address.
* testsuite/ld-aarch64/emit-relocs-259.s: Likewise.
* testsuite/ld-aarch64/aarch64-elf.exp: Run new test.
* testsuite/ld-aarch64/pr22764.s: New.
* testsuite/ld-aarch64/pr22764.d: New.
Since _GLOBAL_OFFSET_TABLE_ may be referenced implicitly on x86,
checking ref_regular_nonweak leaves the unused _GLOBAL_OFFSET_TABLE_
in output. This patch checks explicit GOT references instead.
ld-i386/discarded1.s and ld-x86-64/discarded1.s are updated to avoid
linker optimization which removes GOT references.
bfd/
PR ld/22782
* elf32-i386.c (elf_i386_check_relocs): Set got_referenced if
_GLOBAL_OFFSET_TABLE_ is referenced or GOT is needed to resolve
undefined weak symbol to 0.
* elf64-x86-64.c (elf_x86_64_check_relocs): Set got_referenced
if _GLOBAL_OFFSET_TABLE_ is referenced.
* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Check
got_referenced instead of ref_regular_nonweak. Remove the
unused _GLOBAL_OFFSET_TABLE_ from symbol table.
* elfxx-x86.h (elf_x86_link_hash_table): Add got_referenced.
ld/
PR ld/22782
* testsuite/ld-i386/discarded1.s: Replace mov with div.
* testsuite/ld-x86-64/discarded1.s: Likewise.
* testsuite/ld-i386/i386.exp: Run pr22782.
* testsuite/ld-i386/load1-nacl.d: Updated for removing
_GLOBAL_OFFSET_TABLE_ from output.
* testsuite/ld-i386/load1.d: Likewise.
* testsuite/ld-x86-64/load1a-nacl.d: Likewise.
* testsuite/ld-x86-64/load1a.d: Likewise.
* testsuite/ld-x86-64/load1b-nacl.d: Likewise.
* testsuite/ld-x86-64/load1b.d: Likewise.
* testsuite/ld-i386/pr22782.d: New file.
* testsuite/ld-i386/pr22782.s: Likewise.
* testsuite/ld-x86-64/pr22782.s: Likewise.
* testsuite/ld-x86-64/pr22782a.d: Likewise.
* testsuite/ld-x86-64/pr22782b.d: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run pr22782a and pr22782b.
PR 22762
* scripttempl/pe.sc: Remove PROVIDE()s from __CTOR_LIST__ and
__DTOR_LIST__ symbols. Add a comment explaining why this is
necessary.
* scripttemp/pep.sc: Likewise.
* ld.texinfo (PROVIDE): Add a note about the effect of common
symbols.
Add $AFLAGS_PIC flags for PIC assembly to a number of tests missing them
and remove `tic6x-*-*' XFAIL annotations from them, previously added to
paper over:
.../ld-new: warning: generating a shared library containing non-PID code
error messages produced due to `-mpic -mpid=near' GAS options having not
been used. Such errors now do not happen anymore, removing:
XFAIL: Build shared library for pr14170
XFAIL: PR ld/21703 shared
XFAIL: Build shared library for broken linker script test
XFAIL: Build pr17068.so
XFAIL: -Bsymbolic-functions
XFAIL: Build pr20995.so
XFAIL: Build pr22374 shared library
with `tic6x-elf' and `tic6x-uclinux' targets. These tests now pass all
except for:
FAIL: PR ld/21703 shared
which is now due to a different reason, as follows:
extra regexps in .../ld/testsuite/ld-elf/pr21703-shared.sd starting with "^Symbol table '\.dynsym' contains [0-9]+ entries:$"
EOF from dump.out
FAIL: PR ld/21703 shared
The addition of $AFLAGS_PIC requires the affected test cases to use the
`list' command rather than `{}' characters to create a list, to avoid
the quoting property `{}' also have in TCL. Consequently the change is
slightly more extensive than it could otherwise be.
ld/
* testsuite/ld-elf/shared.exp: Add $AFLAGS_PIC throughout to PIC
assembly builds where missing and remove `tic6x-*-*' XFAIL
markings accordingly.
bfdI would like to fix instances of the following warning, when building
with clang with no special CFLAGS other than -g3 -O0.
/home/emaisin/src/binutils-gdb/bfd/elflink.c:5425:45: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
return (struct elf_link_hash_entry *) 0 - 1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
Replacing those with "(struct elf_link_hash_entry *) -1" gets rid of the
warning. I wanted to check that it didn't change the resulting code, so
I tried to build this:
$ cat test.c
int *before()
{
return (int *) 0 - 1;
}
int *after()
{
return (int *) - 1;
}
$ gcc -c test.c -g
$ objdump -d test.o
test.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <before>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 c7 c0 fc ff ff ff mov $0xfffffffffffffffc,%rax
b: 5d pop %rbp
c: c3 retq
000000000000000d <after>:
d: 55 push %rbp
e: 48 89 e5 mov %rsp,%rbp
11: 48 c7 c0 ff ff ff ff mov $0xffffffffffffffff,%rax
18: 5d pop %rbp
19: c3 retq
This shows that the previous code doesn't actually return -1 as the
function documentation says, but the new one does, so it's kind of a
bugfix.
bfd * elf64-ppc.c (ppc64_elf_archive_symbol_lookup): Avoid pointer
arithmetic on NULL pointer.
* elflink.c (_bfd_elf_archive_symbol_lookup,
elf_link_add_archive_symbols): Likewise.
ld * ldexp.c (fold_name, exp_fold_tree_1): Avoid pointer arithmetic
on NULL pointer.