From patchwork Thu May 2 18:06:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carrot Wei X-Patchwork-Id: 241048 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 190772C00B1 for ; Fri, 3 May 2013 04:06:27 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=o4ilvs3DeIy7wgaudSahL4peC/knXEvyLszXCM+VvpobUu sF62ryPh8sG/B618j2uFXQYsqQI8XCIfORMVHQajNuxDFsK/QdEMperIIClHlePk pPAGAao/qUi5m9YnqYcKth95qdFnpOJ5qXeN9UAe2MBiB8Tk4GxB0H/whz86k= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=ss/vFdkUpB46ir8NfXbiQteCzOQ=; b=o8pPfIIsszDk4F6xXJ3d OboNa8n2G06OUU4ykmjBgU0F0MlzoXQRJ6fQR6JyR2Kcf5JxaSwxzlokxSPC1LRS 6re1B5GYSyQW5f55cnmpkHc0g6AQfkVS56MNYY392sRnKN48BpsOgNWcVQBO7ALK BL1UlEyLhV5TUKotBv83J7g= Received: (qmail 24603 invoked by alias); 2 May 2013 18:06:20 -0000 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 Received: (qmail 24592 invoked by uid 89); 2 May 2013 18:06:20 -0000 X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS, TW_TM autolearn=ham version=3.3.1 Received: from mail-qc0-f178.google.com (HELO mail-qc0-f178.google.com) (209.85.216.178) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 02 May 2013 18:06:03 +0000 Received: by mail-qc0-f178.google.com with SMTP id c1so364827qca.37 for ; Thu, 02 May 2013 11:06:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=K5ib0ZSBoANGoapu1ycoraql5MeuGJAcwtwrIHnxGSI=; b=MF3CGHmyo0wrzZQUcxo+t5jT/MR+qTOSBnHKxUZfxhMyBeuUW4DYKaVQh4H6Xq5VqS Q0110+OzSRnklR4pj0OGmN5tkimyC30U/qYQXf8uxTgPJyBSxuXjcA4+ySJOXI/QBeUU aiP1x2VvoXh3tKSyeUC+iRN5qK2wuVa2UdhUhtG4vUEx9AYA0QNaM0g+iDewPAknmj29 aXzPZ27eesK5jjiAMXgp0K182hwTrVA7zsFyxB8WHYhEl/vE3qbKX34lIsTTLVE9UjFh ph91H8JchgzhYFoy+mnhzJaMhZjhRLS8WmtK7psB1j37QzWirAF1W/NOwBoYZch19ik8 lCqg== MIME-Version: 1.0 X-Received: by 10.229.18.83 with SMTP id v19mr3076737qca.127.1367517961417; Thu, 02 May 2013 11:06:01 -0700 (PDT) Received: by 10.229.178.195 with HTTP; Thu, 2 May 2013 11:06:01 -0700 (PDT) Date: Thu, 2 May 2013 11:06:01 -0700 Message-ID: Subject: [google][4.7] Move the building of gcov constructor function after initialization of gcov_info_var From: Carrot Wei To: "gcc-patches@gcc.gnu.org" , David Li X-Gm-Message-State: ALoCoQktLu7a8hj8Ib6+Dh81G8/EvTzBSgelwKRQuhkfWDB3eSEwTfO73o+n4bDlsZL44UuRzUTN1teDp22W2HIOXvvvbxdbxKUFi0Xr45sRHxRRolWCXawJuz37LV2Yfl4/cttRtEzCok+JE/VJo4DxVbnJVkqCQbqfzVg5HpbeMmOJJtbXvvKs1le2b1gMDL6hMQ1vKrZL This patch fixes google bug 8397853 and targets google 4.7 branch. In LIPO mode, when coverage_obj_init is called, cgraph_state is CGRAPH_STATE_FINISHED. The variable gcov_info_var is created but not initialized. When cgraph_build_static_cdtor is called, the new function and variables are expanded immediately since cgraph_state is CGRAPH_STATE_FINISHED. It causes gcov_info_var into .bss section. But later in function coverage_obj_finish we initialize gcov_info_var with non zero contents, so it should not be put into .bss section. In FDO mode we don't have this problem because when coverage_obj_init is called, cgraph_state is CGRAPH_STATE_IPA_SSA. When cgraph_build_static_cdtor is called, the new function is not immediately expanded. The variable will have been properly initialized when it is expanded. It can be fixed by moving the construction of gcov constructor after initialization of gcov_info_var. Tested with following testing: x86-64 bootstrap. x86-64 regression test. power64 regression test on qemu. The only regression for power64 is FAIL: gcc.dg/torture/tls/tls-test.c -O2 -flto -fno-use-linker-plugin -flto-partition=none execution test It is a flaky test case in our testing environment since all other executions with different compiler options failed. All testing of tls-test.c pass native power64 testing. thanks Carrot 2013-05-02 Guozhi Wei * coverage.c (gcov_info_type): New global variable. (coverage_obj_init): Move the construction of gcov constructor to (build_init_ctor): here. (coverage_obj_finish): Call build_init_ctor after initialization of gcov_info_var. Index: coverage.c =================================================================== --- coverage.c (revision 198425) +++ coverage.c (working copy) @@ -123,6 +123,7 @@ /* Coverage info VAR_DECL and function info type nodes. */ static GTY(()) tree gcov_info_var; +static GTY(()) tree gcov_info_type; static GTY(()) tree gcov_fn_info_type; static GTY(()) tree gcov_fn_info_ptr_type; @@ -2478,14 +2479,12 @@ return build_constructor (info_type, v1); } -/* Create the gcov_info types and object. Generate the constructor - function to call __gcov_init. Does not generate the initializer +/* Create the gcov_info types and object. Does not generate the initializer for the object. Returns TRUE if coverage data is being emitted. */ static bool coverage_obj_init (void) { - tree gcov_info_type, ctor, stmt, init_fn; unsigned n_counters = 0; unsigned ix; struct coverage_data *fn; @@ -2531,24 +2530,6 @@ ASM_GENERATE_INTERNAL_LABEL (name_buf, "LPBX", 0); DECL_NAME (gcov_info_var) = get_identifier (name_buf); - /* Build a decl for __gcov_init. */ - init_fn = build_pointer_type (gcov_info_type); - init_fn = build_function_type_list (void_type_node, init_fn, NULL); - init_fn = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, - get_identifier ("__gcov_init"), init_fn); - TREE_PUBLIC (init_fn) = 1; - DECL_EXTERNAL (init_fn) = 1; - DECL_ASSEMBLER_NAME (init_fn); - - /* Generate a call to __gcov_init(&gcov_info). */ - ctor = NULL; - stmt = build_fold_addr_expr (gcov_info_var); - stmt = build_call_expr (init_fn, 1, stmt); - append_to_statement_list (stmt, &ctor); - - /* Generate a constructor to run it. */ - cgraph_build_static_cdtor ('I', ctor, DEFAULT_INIT_PRIORITY); - return true; } @@ -2570,6 +2551,32 @@ return ctor; } +/* Generate the constructor function to call __gcov_init. */ + +static void +build_init_ctor () +{ + tree ctor, stmt, init_fn; + + /* Build a decl for __gcov_init. */ + init_fn = build_pointer_type (gcov_info_type); + init_fn = build_function_type_list (void_type_node, init_fn, NULL); + init_fn = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, + get_identifier ("__gcov_init"), init_fn); + TREE_PUBLIC (init_fn) = 1; + DECL_EXTERNAL (init_fn) = 1; + DECL_ASSEMBLER_NAME (init_fn); + + /* Generate a call to __gcov_init(&gcov_info). */ + ctor = NULL; + stmt = build_fold_addr_expr (gcov_info_var); + stmt = build_call_expr (init_fn, 1, stmt); + append_to_statement_list (stmt, &ctor); + + /* Generate a constructor to run it. */ + cgraph_build_static_cdtor ('I', ctor, DEFAULT_INIT_PRIORITY); +} + /* Finalize the coverage data. Generates the array of pointers to function objects from CTOR. Generate the gcov_info initializer. */ @@ -2589,9 +2596,12 @@ DECL_NAME (fn_info_ary) = get_identifier (name_buf); DECL_INITIAL (fn_info_ary) = build_constructor (fn_info_ary_type, ctor); varpool_finalize_decl (fn_info_ary); - + DECL_INITIAL (gcov_info_var) = build_info (TREE_TYPE (gcov_info_var), fn_info_ary); + + build_init_ctor (); + varpool_finalize_decl (gcov_info_var); }