From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 381 invoked by alias); 8 Aug 2012 22:47:24 -0000 Received: (qmail 372 invoked by uid 22791); 8 Aug 2012 22:47:23 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,TW_FX X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 08 Aug 2012 22:47:08 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1SzF1w-0001q4-4v from Maciej_Rozycki@mentor.com ; Wed, 08 Aug 2012 15:47:08 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Wed, 8 Aug 2012 15:47:07 -0700 Received: from [172.30.3.42] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Wed, 8 Aug 2012 23:47:05 +0100 Date: Wed, 08 Aug 2012 22:49:00 -0000 From: "Maciej W. Rozycki" To: CC: Richard Sandiford Subject: [PATCH 1/3] MIPS/BFD: Correct protected symbol relocation processing Message-ID: User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" 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 X-SW-Source: 2012-08/txt/msg00165.txt.bz2 Hello, The change below fixes a problem where an R_MIPS_CALL16 relocation against a protected symbol makes BFD treat the symbol as a global (preemptible) one. This cannot succeed as protected symbols are local (non-preemptible) and therefore assigned to the local part of the GOT (as long as they are not referred to for a purpose other than making a call; strictly speaking this is a divergence from how export classess have been originally specified[1] for the MIPS target by SGI). Such relocations are produced by GCC when compiling to PIC code where calls are made to functions that have not been declared with the "protected" visibility attribute (of course handcoded assembly code may have them as well). The problem triggers when the references (relocations) are satisfied with a symbol whose export class (visibility) has been set to "protected", but not either of "hidden" or "internal". An assertion has been placed in code to ensure that references to global symbols end up in the global part of the GOT and as a result of the mistreatment described the assertion fails: mips-linux-gnu-ld: BFD (...) 2.23.51.20120807 assertion fail .../bfd/elfxx-mips.c:3321 -- that's: BFD_ASSERT (got_index < htab->sgot->size); in mips_elf_global_got_index. The change adjusts the treatment of protected symbols in relocation processing to match code that assigns them to the local part of the GOT. The difference between SYMBOL_REFERENCES_LOCAL and SYMBOL_CALLS_LOCAL is the former treats protected symbols as global and the latter treats them as local. The got_only_for_calls condition has been set to treat protected symbols as global or local as appropriate (depending on whether they are only used for making a call or not; as noted above). The change causes no regressions in binutils testsuites on the 23 MIPS targets I've been using for testing recently. There have been no regressions in the glibc test suite on Linux targets either (o32 and n64 tested). OK to apply? I have prepared specific test cases to cover this problem and will be sending them separately. Additionally the test cases triggered a segmentation fault in LD with the mips-sgi-irix6 target that I have fixed with the second patch of this series. 2012-08-08 Maciej W. Rozycki bfd/ * elfxx-mips.c (mips_elf_calculate_relocation): Fix the handling of protected symbols. Maciej [1] "64-bit ELF Object File Specification Draft Version 2.5", SGI doc #007-4658-001 binutils-bfd-mips-protected-call16.diff Index: binutils-fsf-trunk-quilt/bfd/elfxx-mips.c =================================================================== --- binutils-fsf-trunk-quilt.orig/bfd/elfxx-mips.c 2012-08-08 02:12:20.120577868 +0100 +++ binutils-fsf-trunk-quilt/bfd/elfxx-mips.c 2012-08-08 14:03:37.480542340 +0100 @@ -5343,7 +5343,10 @@ mips_elf_calculate_relocation (bfd *abfd && (target_is_16_bit_code_p || target_is_micromips_code_p)))); - local_p = h == NULL || SYMBOL_REFERENCES_LOCAL (info, &h->root); + local_p = (h == NULL + || (h->got_only_for_calls + ? SYMBOL_CALLS_LOCAL (info, &h->root) + : SYMBOL_REFERENCES_LOCAL (info, &h->root))); gp0 = _bfd_get_gp_value (input_bfd); gp = _bfd_get_gp_value (abfd);