From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6064 invoked by alias); 25 Apr 2017 09:53:38 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 6038 invoked by uid 89); 25 Apr 2017 09:53:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 spammy= X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Apr 2017 09:53:36 +0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v3P9ratu014858 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 25 Apr 2017 09:53:36 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v3P9rZsU023191 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 25 Apr 2017 09:53:36 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v3P9rZKX014201 for ; Tue, 25 Apr 2017 09:53:35 GMT Received: from termi.oracle.com (/10.175.194.132) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 25 Apr 2017 02:53:35 -0700 From: jose.marchesi@oracle.com (Jose E. Marchesi) To: binutils@sourceware.org Subject: [PATCH][COMMITTED] gas: sparc: fix relaxation of CALL instruction into branches in a.out targets Date: Tue, 25 Apr 2017 09:53:00 -0000 Message-ID: <871ssgvmn8.fsf@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2017-04/txt/msg00217.txt.bz2 I just applied the patch below in order to fix PR gas/21407. --- gas: sparc: fix relaxation of CALL instruction into branches in a.out targets This patch avoids CALL instructions to be optimized into branches if the symbols referred to in the CALL instruction are not fully resolved at the time the assembler writes its output. Tested in sparc64-linux-gnu and sparc-sun-sunos4.1.3 targets. No regressions. gas/ChangeLog: 2017-04-25 Jose E. Marchesi PR gas/21407 * config/tc-sparc.c (md_apply_fix): Do not transform `call' instructions into branch instructions in fixups generating additional relocations. * testsuite/gas/sparc/call-relax.s: New file. * testsuite/gas/sparc/call-relax.d: Likewise. * testsuite/gas/sparc/call-relax-aout.d: Likewise. * testsuite/gas/sparc/sparc.exp: Test call-relax and call-relax-aout. diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c index 030e10d..4c930b5 100644 --- a/gas/config/tc-sparc.c +++ b/gas/config/tc-sparc.c @@ -3584,8 +3584,13 @@ md_apply_fix (fixS *fixP, valueT *valP, segT segment ATTRIBUTE_UNUSED) insn |= val & 0x3fffffff; - /* See if we have a delay slot. */ - if (sparc_relax && fixP->fx_where + 8 <= fixP->fx_frag->fr_fix) + /* See if we have a delay slot. In that case we attempt to + optimize several cases transforming CALL instructions + into branches. But we can only do that if the relocation + can be completely resolved here, i.e. if no undefined + symbol is associated with it. */ + if (sparc_relax && fixP->fx_addsy == NULL + && fixP->fx_where + 8 <= fixP->fx_frag->fr_fix) { #define G0 0 #define O7 15 diff --git a/gas/testsuite/gas/sparc/call-relax-aout.d b/gas/testsuite/gas/sparc/call-relax-aout.d new file mode 100644 index 0000000..8afcf5e --- /dev/null +++ b/gas/testsuite/gas/sparc/call-relax-aout.d @@ -0,0 +1,19 @@ +#as: -Av9 -relax +#source: call-relax.s +#objdump: -dr +#name: sparc relax CALL (a.out) + +.*: +file format .*a\.out.* + +Disassembly of section .text: + +0+ : + 0: 31 00 00 00 sethi %hi\(0\), %i0 + 4: 10 80 00 02 b c + 8: 91 ee 20 00 restore %i0, 0, %o0 + +0+c : + c: 31 00 00 00 sethi %hi\(0\), %i0 + 10: 40 00 00 00 call 10 + 10: WDISP30 _undefined-0x10 + 14: 91 ee 20 00 restore %i0, 0, %o0 diff --git a/gas/testsuite/gas/sparc/call-relax.d b/gas/testsuite/gas/sparc/call-relax.d new file mode 100644 index 0000000..de52274 --- /dev/null +++ b/gas/testsuite/gas/sparc/call-relax.d @@ -0,0 +1,18 @@ +#as: -Av9 -relax +#objdump: -dr +#name: sparc relax CALL + +.*: +file format .*sparc.* + +Disassembly of section .text: + +0+ : + 0: 31 00 00 00 sethi %hi\(0\), %i0 + 4: 10 68 00 02 b %xcc, c + 8: 91 ee 20 00 restore %i0, 0, %o0 + +0+c : + c: 31 00 00 00 sethi %hi\(0\), %i0 + 10: 40 00 00 00 call 10 + 10: R_SPARC_WDISP30 _undefined + 14: 91 ee 20 00 restore %i0, 0, %o0 diff --git a/gas/testsuite/gas/sparc/call-relax.s b/gas/testsuite/gas/sparc/call-relax.s new file mode 100644 index 0000000..f5ebbb6 --- /dev/null +++ b/gas/testsuite/gas/sparc/call-relax.s @@ -0,0 +1,10 @@ +# Test relaxation of CALL instructions into branches. + .text +foo: + sethi %hi(0), %i0 + call bar, 0 + restore %i0, %lo(0), %o0 +bar: + sethi %hi(0), %i0 + call _undefined, 0 + restore %i0, %lo(0), %o0 diff --git a/gas/testsuite/gas/sparc/sparc.exp b/gas/testsuite/gas/sparc/sparc.exp index eb69e50..1e9cc2c 100644 --- a/gas/testsuite/gas/sparc/sparc.exp +++ b/gas/testsuite/gas/sparc/sparc.exp @@ -72,6 +72,10 @@ if [istarget sparc*-*-*] { run_dump_test "v9branch1" run_dump_test "imm-plus-rreg" run_dump_test "dcti-couples-v9" + run_dump_test "call-relax" + } else { + # The next tests are a.out only. + run_dump_test "call-relax-aout" } if [gas_64_check] {