mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-02-11 13:02:10 +08:00
We recently fixed a bug in libgcc (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115360) where a symbol was missing a %function .type decoration. This meant the linker would silently pick the wrong type of 'farcall stub', involving Arm-mode instructions on Thumb-only CPUs. This patch emits an error instead, and warns in some other cases, to encourage users to add the missing '.type foo,%function' directive. In practice: in arm_type_of_stub() we no longer try to infer which stub to use if the destination is of unknown type and the CPU is Thumb-only; so we won't lie to elf32_arm_size_stubs() which does not check branch_type. If branch_type is ST_BRANCH_TO_ARM but the CPU is Thumb-only, we now convert it to ST_BRANCH_TO_THUMB only if the destination is of absolute type. This is to support the case where the destination of the branch is defined by the linker script (see thumb-b-lks-sym.s and thumb-bl-lks-sym.s testcases for instance). The motivating case is covered by the new farcall-missing-type testcase, where we now emit an error message. We do not emit an error when branch_type is ST_BRANCH_UNKNOWN and the CPU supports Arm-mode: a lot of legacy code (e.g. newlib's crt0.S) lacks the corresponding '.type foo, %function' directives and even a (too verbose) warning could be perceived as a nuisance. Existing testcases where such a warning would trigger: arm-static-app.s (app_func, app_func2) arm-rel32.s (foo) arm-app.s (app_func) rel32-reject.s () main) fix-arm1176.s (func_to_branch_to) but this list is not exhaustive. For the sake of clarity, the patch replaces occurrences of sym.st_target_internal = 0; with sym.st_target_internal = ST_BRANCH_TO_ARM; enum arm_st_branch_type is defined in include/elf/arm.h, and relies on ST_BRANCH_TO_ARM==0, as sym.st_target_internal is also initialized to 0 in other target-independent parts of BFD code. (For instance, swapping the ST_BRANCH_TO_ARM and ST_BRANCH_TO_THUMB entries in the enum definition leads to 'interesting' results...) Regarding the testsuite: * new expected warning for thumb-b-lks-sym and thumb-bl-lks-sym * new testcase farcall-missing-type to check the new error case * attr-merge-arch-2b.s, branch-futures (and bfs-1.s) updated to avoid a diagnostic Tested on arm-eabi and arm-pe with no regression. |
||
---|---|---|
.. | ||
emulparams | ||
emultempl | ||
po | ||
scripttempl | ||
testsuite | ||
.gitignore | ||
aclocal.m4 | ||
ChangeLog | ||
ChangeLog-0001 | ||
ChangeLog-0203 | ||
ChangeLog-2004 | ||
ChangeLog-2005 | ||
ChangeLog-2006 | ||
ChangeLog-2007 | ||
ChangeLog-2008 | ||
ChangeLog-2009 | ||
ChangeLog-2010 | ||
ChangeLog-2011 | ||
ChangeLog-2012 | ||
ChangeLog-2013 | ||
ChangeLog-2014 | ||
ChangeLog-2015 | ||
ChangeLog-2016 | ||
ChangeLog-2017 | ||
ChangeLog-2018 | ||
ChangeLog-2019 | ||
ChangeLog-2020 | ||
ChangeLog-9197 | ||
ChangeLog-9899 | ||
config.in | ||
configure | ||
configure.ac | ||
configure.host | ||
configure.tgt | ||
deffile.h | ||
deffilep.y | ||
dep-in.sed | ||
elf-hints-local.h | ||
fdl.texi | ||
gen-doc.texi | ||
genscrba.sh | ||
genscripts.sh | ||
h8-doc.texi | ||
ld.h | ||
ld.texi | ||
ldbuildid.c | ||
ldbuildid.h | ||
ldcref.c | ||
ldctor.c | ||
ldctor.h | ||
ldelf.c | ||
ldelf.h | ||
ldelfgen.c | ||
ldelfgen.h | ||
ldemul.c | ||
ldemul.h | ||
ldexp.c | ||
ldexp.h | ||
ldfile.c | ||
ldfile.h | ||
ldgram.y | ||
ldint.texi | ||
ldlang.c | ||
ldlang.h | ||
ldlex-wrapper.c | ||
ldlex.h | ||
ldlex.l | ||
ldmain.c | ||
ldmain.h | ||
ldmisc.c | ||
ldmisc.h | ||
ldver.c | ||
ldver.h | ||
ldwrite.c | ||
ldwrite.h | ||
lexsup.c | ||
libdep_plugin.c | ||
MAINTAINERS | ||
Makefile.am | ||
Makefile.in | ||
mri.c | ||
mri.h | ||
NEWS | ||
pdb.c | ||
pdb.h | ||
pe-dll.c | ||
pe-dll.h | ||
pep-dll-aarch64.c | ||
pep-dll-x86_64.c | ||
pep-dll.c | ||
pep-dll.h | ||
plugin.c | ||
plugin.h | ||
README | ||
sysdep.h | ||
testplug2.c | ||
testplug3.c | ||
testplug4.c | ||
testplug.c | ||
TODO |
README for LD
This is the GNU linker. It is distributed with other "binary
utilities" which should be in ../binutils. See ../binutils/README for
more general notes, including where to send bug reports.
There are many features of the linker:
* The linker uses a Binary File Descriptor library (../bfd)
that it uses to read and write object files. This helps
insulate the linker itself from the format of object files.
* The linker supports a number of different object file
formats. It can even handle multiple formats at once:
Read two input formats and write a third.
* The linker can be configured for cross-linking.
* The linker supports a control language.
* There is a user manual (ld.texi), as well as the
beginnings of an internals manual (ldint.texi).
Installation
============
See ../binutils/README.
If you want to make a cross-linker, you may want to specify
a different search path of -lfoo libraries than the default.
You can do this by setting the LIB_PATH variable in ./Makefile
or using the --with-lib-path configure switch.
To build just the linker, make the target all-ld from the top level
directory (one directory above this one).
Porting to a new target
=======================
See the ldint.texi manual.
Reporting bugs etc
===========================
See ../binutils/README.
Known problems
==============
The Solaris linker normally exports all dynamic symbols from an
executable. The GNU linker does not do this by default. This is
because the GNU linker tries to present the same interface for all
similar targets (in this case, all native ELF targets). This does not
matter for normal programs, but it can make a difference for programs
which try to dlopen an executable, such as PERL or Tcl. You can make
the GNU linker export all dynamic symbols with the -E or
--export-dynamic command line option.
HP/UX 9.01 has a shell bug that causes the linker scripts to be
generated incorrectly. The symptom of this appears to be "fatal error
- scanner input buffer overflow" error messages. There are various
workarounds to this:
* Build and install bash, and build with "make SHELL=bash".
* Update to a version of HP/UX with a working shell (e.g., 9.05).
* Replace "(. ${srcdir}/scripttempl/${SCRIPT_NAME}.sc)" in
genscripts.sh with "sh ${srcdir}..." (no parens) and make sure the
emulparams script used exports any shell variables it sets.
Copyright (C) 2012-2024 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.