This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [Xtensa] change relaxation of calls to weak symbols
- From: Bob Wilson <bwilson at tensilica dot com>
- To: binutils at sources dot redhat dot com
- Date: Thu, 13 Dec 2007 11:09:49 -0800
- Subject: Re: [Xtensa] change relaxation of calls to weak symbols
- References: <476051E2.1090209@tensilica.com>
Bob Wilson wrote:
I noticed yesterday that the Xtensa port of GAS has been relaxing all
calls to weak symbols, even when the --longcalls option is disabled.
This seems wrong to me. The assembler doesn't know the final address of
a weak symbol, but that is no different than a call to a different
section. This patch changes GAS to handle both of those cases (weak
symbol and different section) in the same way. Tested with an
xtensa-elf build and committed.
The GAS testsuite for Xtensa is not worth much.... This change broke GCC's
g++.dg/warn/weak1.C test. It seems like the best solution is to distinguish
weak references (which may resolve to zero) from weak definitions. Fixed with
the following patch, which I have committed. In an effort to improve the
testsuite, I also added a test for this.
2007-12-13 Bob Wilson <bob.wilson@acm.org>
gas/
* config/tc-xtensa.c (xg_symbolic_immeds_fit): Relax for weak
references but not weak definitions.
gas/testsuite/
* gas/xtensa/all.exp: Run new weak-call test.
* gas/xtensa/weak-call.d: New.
* gas/xtensa/weak-call.s: New.
Index: config/tc-xtensa.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-xtensa.c,v
retrieving revision 1.94
diff -u -p -r1.94 tc-xtensa.c
--- config/tc-xtensa.c 12 Dec 2007 21:16:47 -0000 1.94
+++ config/tc-xtensa.c 13 Dec 2007 18:59:43 -0000
@@ -3241,9 +3241,15 @@ xg_symbolic_immeds_fit (const TInsn *ins
|| S_GET_SEGMENT (expr->X_add_symbol) != pc_seg)
{
/* For a direct call with --no-longcalls, be optimistic and
- assume it will be in range. */
+ assume it will be in range. If the symbol is weak and
+ undefined, it may remain undefined at link-time, in which
+ case it will have a zero value and almost certainly be out
+ of range for a direct call; thus, relax for undefined weak
+ symbols even if longcalls is not enabled. */
if (is_direct_call_opcode (insn->opcode)
- && ! pc_frag->tc_frag_data.use_longcalls)
+ && ! pc_frag->tc_frag_data.use_longcalls
+ && (! S_IS_WEAK (expr->X_add_symbol)
+ || S_IS_DEFINED (expr->X_add_symbol)))
return TRUE;
return FALSE;
Index: testsuite/gas/xtensa/all.exp
===================================================================
RCS file: /cvs/src/src/gas/testsuite/gas/xtensa/all.exp,v
retrieving revision 1.4
diff -u -p -r1.4 all.exp
--- testsuite/gas/xtensa/all.exp 7 Dec 2007 22:52:10 -0000 1.4
+++ testsuite/gas/xtensa/all.exp 13 Dec 2007 18:59:47 -0000
@@ -80,6 +80,7 @@ if [istarget xtensa*-*-*] then {
run_dump_test "short_branch_offset"
run_dump_test "pcrel"
+ run_dump_test "weak-call"
}
if [info exists errorInfo] then {
Index: testsuite/gas/xtensa/weak-call.d
===================================================================
RCS file: testsuite/gas/xtensa/weak-call.d
diff -N testsuite/gas/xtensa/weak-call.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gas/xtensa/weak-call.d 13 Dec 2007 18:59:47 -0000
@@ -0,0 +1,11 @@
+#as:
+#objdump: -r -j .text
+#name: relaxing calls to weak symbols
+
+.*: +file format .*xtensa.*
+
+RELOCATION RECORDS FOR \[\.text\]:
+OFFSET TYPE VALUE
+00000000 R_XTENSA_SLOT0_OP weakdef
+00000003 R_XTENSA_SLOT0_OP \.literal
+00000003 R_XTENSA_ASM_EXPAND weakref
Index: testsuite/gas/xtensa/weak-call.s
===================================================================
RCS file: testsuite/gas/xtensa/weak-call.s
diff -N testsuite/gas/xtensa/weak-call.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/gas/xtensa/weak-call.s 13 Dec 2007 18:59:47 -0000
@@ -0,0 +1,8 @@
+ .text
+ .begin no-longcalls
+ .weak weakdef
+ call8 weakdef
+weakdef:
+ .weak weakref
+ call8 weakref
+ .end no-longcalls