From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16730 invoked by alias); 13 Dec 2004 13:21:17 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 16657 invoked from network); 13 Dec 2004 13:21:08 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 13 Dec 2004 13:21:08 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id iBDDKwOM017470; Mon, 13 Dec 2004 08:21:03 -0500 Received: from localhost (mail@vpn50-59.rdu.redhat.com [172.16.50.59]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id iBDDKvr11871; Mon, 13 Dec 2004 08:20:57 -0500 Received: from rsandifo by localhost with local (Exim 3.35 #1) id 1Cdq8G-0006Fc-00; Mon, 13 Dec 2004 13:20:56 +0000 To: Ian Lance Taylor Cc: binutils@sourceware.org Subject: Re: Test for overflow in the R_MIPS_26 reloc References: <20041208202730.11374.qmail@gossamer.airs.com> From: Richard Sandiford Date: Mon, 13 Dec 2004 13:21:00 -0000 In-Reply-To: <20041208202730.11374.qmail@gossamer.airs.com> (Ian Lance Taylor's message of "8 Dec 2004 15:27:30 -0500") Message-ID: <87acsi72rr.fsf@redhat.com> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2004-12/txt/msg00150.txt.bz2 Ian Lance Taylor writes: > Index: elfxx-mips.c > =================================================================== > RCS file: /cvs/src/src/bfd/elfxx-mips.c,v > retrieving revision 1.113 > diff -p -u -r1.113 elfxx-mips.c > --- elfxx-mips.c 16 Nov 2004 09:54:10 -0000 1.113 > +++ elfxx-mips.c 8 Dec 2004 20:24:55 -0000 > @@ -3350,7 +3350,10 @@ mips_elf_calculate_relocation (bfd *abfd > if (local_p) > value = ((addend | ((p + 4) & 0xf0000000)) + symbol) >> 2; > else > - value = (_bfd_mips_elf_sign_extend (addend, 28) + symbol) >> 2; > + { > + value = (_bfd_mips_elf_sign_extend (addend, 28) + symbol) >> 2; > + overflowed_p = (value >> 26) != ((p + 4) >> 28); > + } > value &= howto->dst_mask; > break; On non-PIC targets, the overflow triggers for code like: void foo (void) { if (weak_symbol) weak_symbol (); } when weak_symbol is undefined and foo() is outside the low 256MB (in KSEG0, for example). This is causing lots of link failures in the mips64-elf gcc testsuite. Is the patch below OK? Tested against the gcc testsuite on mips64-elf. Also tested against the gas, ld & binutils testsuite on mips64-elf, mips-elf, mipsisa64el-elf and mips64-linux-gnu. Richard bfd/ * elfxx-mips.c (mips_elf_calculate_relocation): Don't report an overflow for calls to undefined weak symbols. ld/testsuite/ * ld-mips-elf/jal-overflow-2.[sd]: New test. * ld-mips-elf/mips-elf.exp: Run it. Index: bfd/elfxx-mips.c =================================================================== RCS file: /cvs/src/src/bfd/elfxx-mips.c,v retrieving revision 1.116 diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.116 elfxx-mips.c *** bfd/elfxx-mips.c 9 Dec 2004 07:12:28 -0000 1.116 --- bfd/elfxx-mips.c 13 Dec 2004 13:10:31 -0000 *************** mips_elf_calculate_relocation (bfd *abfd *** 3352,3358 **** else { value = (_bfd_mips_elf_sign_extend (addend, 28) + symbol) >> 2; ! overflowed_p = (value >> 26) != ((p + 4) >> 28); } value &= howto->dst_mask; break; --- 3352,3359 ---- else { value = (_bfd_mips_elf_sign_extend (addend, 28) + symbol) >> 2; ! if (h->root.root.type != bfd_link_hash_undefweak) ! overflowed_p = (value >> 26) != ((p + 4) >> 28); } value &= howto->dst_mask; break; Index: ld/testsuite/ld-mips-elf/mips-elf.exp =================================================================== RCS file: /cvs/src/src/ld/testsuite/ld-mips-elf/mips-elf.exp,v retrieving revision 1.22 diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.22 mips-elf.exp *** ld/testsuite/ld-mips-elf/mips-elf.exp 13 Dec 2004 13:09:55 -0000 1.22 --- ld/testsuite/ld-mips-elf/mips-elf.exp 13 Dec 2004 13:10:31 -0000 *************** if {$has_newabi && $linux_gnu} { *** 81,86 **** --- 81,87 ---- } run_dump_test "jaloverflow" + run_dump_test "jaloverflow-2" if {$has_newabi} { run_dump_test "jalbal" } diff -c /dev/null ld/testsuite/ld-mips-elf/jaloverflow-2.d *** /dev/null Fri Apr 23 00:21:55 2004 --- ld/testsuite/ld-mips-elf/jaloverflow-2.d Mon Dec 13 11:39:44 2004 *************** *** 0 **** --- 1,8 ---- + #name: JAL overflow 2 + #source: jaloverflow-2.s + #as: + #ld: -Ttext=0x10000000 -e start + #objdump: -dr + #... + 0*10000000: 0c000000.* + #pass diff -c /dev/null ld/testsuite/ld-mips-elf/jaloverflow-2.s *** /dev/null Fri Apr 23 00:21:55 2004 --- ld/testsuite/ld-mips-elf/jaloverflow-2.s Mon Dec 13 11:39:29 2004 *************** *** 0 **** --- 1,7 ---- + # jal relocs against undefined weak symbols should not be treated as + # overflowing + + .globl start + .weak foo + start: + jal foo