From patchwork Fri Jun 1 20:27:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teresa Johnson X-Patchwork-Id: 162365 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id A4155B6FD3 for ; Sat, 2 Jun 2012 06:28:08 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1339187289; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:To:Subject:Message-Id:Date: From:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=0teF6Ps 4VkknbXk9uJHngckZa7o=; b=uAAI08BwKnYL2IbdyrS7bpfQvXZM7EpL01k3T1B 3cSyamicMEA2WtpX8KO/6iTwyVrQdGTq3/lcaY+RQ6Ib+lRoUorZ4QMnwmTSIEXn X4lzJ06blLAIO+DxxAL0N1kDTzDpDHGxJLLLbqZHqNYoO2Ta1znAIdkiFxK9UKVw f5UM= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:Received:Received:To:Subject:Message-Id:Date:From:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=tZYQHMXGTlqQNzzkgS2upo0J89A1D9sqXCuaKZXWUkYHX3dOzzuWL9Aft7viQo yNcok7bQkUAg4/TFJ0BkB1RqhODi9LcWM+zh34ewen8NoEq/CtbaFp4aRP3dafw0 I9jhCrDdN2ec7gvN7ZpqAPgMH7KF/y0KeVdU7kCUYlss8=; Received: (qmail 5912 invoked by alias); 1 Jun 2012 20:28:04 -0000 Received: (qmail 5902 invoked by uid 22791); 1 Jun 2012 20:28:02 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-bk0-f73.google.com (HELO mail-bk0-f73.google.com) (209.85.214.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jun 2012 20:27:48 +0000 Received: by bkcjc3 with SMTP id jc3so146916bkc.2 for ; Fri, 01 Jun 2012 13:27:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=to:subject:message-id:date:from:x-gm-message-state; bh=WkCamZrsw1Da4I6SCnOENfZj//C6fTc/ZpGRq4976dQ=; b=OJDgVf+AHRwFCO12iCa+3IdkPLBHoByzG6bTYTaVT4pZTP/RJm4Cr1s0bh6DnfMDLx CSXP2I4aL0vkcxYJT9wh0BxyvqU2xr3VjIa5f/nz/N3PUXyh3Qwk9ggjaL4xx28tJ+34 v7xQ1BagU4PwI7YaItHklT62wgBvdUIHTvBtbbnek+a68kbQ6HSjgo9KJ2rFTFIjVAPW 1cOcno8CmhQQl80aIllb1GuFBA5w45IxXAkilysg46Zi9hYZi1jIxIgDZST7q+p5zXgR nh1lIEyhmfscZfsv4CJQZzTQ+IP8l4vMJWKQUkhOoYaQh7fTsa/yO9+HPQhIkhVu9dLn qEhw== Received: by 10.14.28.197 with SMTP id g45mr1514025eea.9.1338582467523; Fri, 01 Jun 2012 13:27:47 -0700 (PDT) Received: by 10.14.28.197 with SMTP id g45mr1514019eea.9.1338582467422; Fri, 01 Jun 2012 13:27:47 -0700 (PDT) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id u54si2924503eeb.2.2012.06.01.13.27.47 (version=TLSv1/SSLv3 cipher=AES128-SHA); Fri, 01 Jun 2012 13:27:47 -0700 (PDT) Received: from tjsboxrox.mtv.corp.google.com (tjsboxrox.mtv.corp.google.com [172.18.110.68]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id 3AD5D20004E; Fri, 1 Jun 2012 13:27:47 -0700 (PDT) Received: by tjsboxrox.mtv.corp.google.com (Postfix, from userid 147431) id 7822061578; Fri, 1 Jun 2012 13:27:46 -0700 (PDT) To: reply@codereview.appspotmail.com,gcc-patches@gcc.gnu.org Subject: [google] libgcov workaround for weak reference issue (issue6276043) Message-Id: <20120601202746.7822061578@tjsboxrox.mtv.corp.google.com> Date: Fri, 1 Jun 2012 13:27:46 -0700 (PDT) From: tejohnson@google.com (Teresa Johnson) X-Gm-Message-State: ALoCoQnIV4IIxXYlsay0sqLXHLYFozqvkRu+X0M5wSpYATx6Uxw3PzhrrrFYWKqMiYakl/yIKVftgtjHP4zW+7JyqMsQzwzi8Q1bIVleCbxzcj9suCwmp2I7CGCdbbraLuPqYcsAuk+aYPP/UbZRA04jy5Y/7XBBiQ== X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch works around a subtlety in the way weak references to symbols defined in archives are handled by the linker. This is an issue because google binaries are using weak references to detect whether the libgcov.a version contains the new __gcov_reset and __gcov_dump interfaces. Since they are defined in their own object file within the archive, and no strong references are made to any other symbols within the same object file, the linker does not resolve the weak references. The workaround is to add dummy strong references to the new routines from the main object file (defined under L_gcov) that will always be referenced during -fprofile-generate builds. Bootstrapped and tested on x86_64-unknown-linux-gnu. Ok for google branches? Thanks, Teresa 2012-06-01 Teresa Johnson * libgcov.c: Add references to gcov_reset and gcov_dump from L_gcov section. --- This patch is available for review at http://codereview.appspot.com/6276043 Index: libgcov.c =================================================================== --- libgcov.c (revision 188119) +++ libgcov.c (working copy) @@ -119,6 +119,21 @@ extern int gcov_dump_complete ATTRIBUTE_HIDDEN; #ifdef L_gcov #include "gcov-io.c" +/* Create a strong reference to these symbols so that they are + unconditionally pulled into the instrumented binary, even when + the only reference is a weak reference. This is necessary because + we are using weak references to handle older compilers that + pre-date these new functions. A subtlety of the linker is that + it will only resolve weak references defined within archive libraries + when there is a string reference to something else defined within + the same object file. Since these two functions are defined within + their own object files (using L_gcov_reset and L_gcov_dump), they + would not get resolved. Since there are symbols within the main L_gcov + section that are strongly referenced during -fprofile-generate builds, + these symbols will always need to be resolved. */ +void (*unused1)() = &__gcov_reset; +void (*unused2)() = &__gcov_dump; + /* Utility function for outputing errors. */ static int gcov_error (const char *fmt, ...)