From patchwork Thu Nov 21 06:09:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Strager Neds X-Patchwork-Id: 1198665 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514271-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jH3XGZG3"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="scJbcVO1"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47JTgL1FzBz9sPL for ; Thu, 21 Nov 2019 17:10:05 +1100 (AEDT) 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:from:date:message-id:subject:to:content-type; q= dns; s=default; b=Qos4E+KvMzKJTCdVMEKo0dVdPBApiF/JpDVH0ZJDOgNvEi POS65RM4FZBjlvwrhuB/k0qfS3iBEqxcnp0iempUJOpErA44TPNKMIbabwFH66Ry o+846d9txJMPPzuR1dq0q44zU3/673xqd7IwiDyuLdikXX398aTEqc5cEe8B0= 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:from:date:message-id:subject:to:content-type; s= default; bh=niH1M5yMwYc+kRCG1me334AgW+s=; b=jH3XGZG3yXdaH/vQR1Il 7SfJr8ZD8WZtXCxGH/8xqftkUwclKXFO0TuqnlTniNEKYt7J1awpqtH7QuX9N6T+ rhu7Smt1VN3jBa8c27j2kHsFTD/XejGt1EzN56Cpa40M8EUiSsxkv7e5VwXJsrTH JBxnMD2x0nSfPM+p5oENgQo= Received: (qmail 59455 invoked by alias); 21 Nov 2019 06:09:58 -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 59443 invoked by uid 89); 21 Nov 2019 06:09:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=uncovered, ucw X-HELO: mail-io1-f66.google.com Received: from mail-io1-f66.google.com (HELO mail-io1-f66.google.com) (209.85.166.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Nov 2019 06:09:56 +0000 Received: by mail-io1-f66.google.com with SMTP id r144so2041537iod.8 for ; Wed, 20 Nov 2019 22:09:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=SduygxDVP4DonuQjonZziJIu1kBhm8LpboMHd0WUr04=; b=scJbcVO1s9H4fn5tzlmqkI7gKOGWnATBUG0WcQoFIiS2ueuLHWRuQsn0baERH8EkZM kJH3NQ1JEOGUTa5szQMMhtXi0frzfl+rJ385hDUaZjxGyShlhk8Zxww8Dtx2JXue9/GY 0rc4ZkIkQl4qiJuEpTBcPaBEN/IMTHWQCRWWDZfXUQ7ZEbeJNP1RwtDjkp8w1fSsj2JW kwkpBIxcsRHEs0h8IK32Q7/VEDfMfCnfFoIAP702r37wTsTjYY5vAAiGh0u70thMVYnD Kv2s1TyktRAsCCcOZNg3phA4SyNucpGoxSnBE64Wi66x8gfOhzYgT2KpUDcD0Coc/7VJ t3hA== MIME-Version: 1.0 From: Strager Neds Date: Wed, 20 Nov 2019 22:09:43 -0800 Message-ID: Subject: [PATCH] Fix attribute((section)) with -flto To: gcc-patches@gcc.gnu.org When building an executable with LTO, GCC effectively ignores __attribute__((section)) on C++ inline member functions. Moving such functions into the .text section seems to be intentional, but I think ignoring the section attribute is unintentional: https://gcc.gnu.org/ml/gcc-patches/2010-07/msg00580.html > From: Jan Hubicka > > The patch uncovered two latent problems. [...] Also I think we > should clear NAMED_SECTION for comdats to conserve size. This is the > cgraph_make_decl_local change. Stop resetting the section of localized comdat symbols. This fixes __attribute__((section)) with -flto. Testing: Bootstrap on x86_64-linux-gnu with --disable-multilib --enable-checking=release --enable-languages=c,c++. Observe no change in test results (aside from the added tests). 2019-11-12 Matthew Glazar * gcc/ipa-visibility.c (localize_node): Never set section_name to NULL. --- gcc/ipa-visibility.c | 4 --- .../ext/section-class-inline-function-lto.C | 17 +++++++++++ .../ext/section-class-inline-function.C | 25 ++++++++++++++++ gcc/testsuite/lib/scanasm.exp | 30 ++++++++++++++++++- 4 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/section-class-inline-function-lto.C create mode 100644 gcc/testsuite/g++.dg/ext/section-class-inline-function.C # Check that symbols are emitted in the desired section. # # Symbols and sections are interpreted as regexp patterns. @@ -724,11 +747,16 @@ proc dg-function-on-line { args } { proc scan-lto-assembler { args } { set testcase [testname-for-summary] + set output_file [lto_assembly_output_file $testcase] + dg-scan "scan-lto-assembler" 1 $testcase $output_file $args +} + +proc lto_assembly_output_file { testcase } { # The name might include a list of options; extract the file name. set filename [lindex $testcase 0] set output_file "[file rootname [file tail $filename]].exe.ltrans0.s" verbose "output_file: $output_file" - dg-scan "scan-lto-assembler" 1 $testcase $output_file $args + return $output_file } # Read assembly file FILENAME and store a mapping from function names diff --git gcc/ipa-visibility.c gcc/ipa-visibility.c index f470465f935..cf4c9101a2a 100644 --- gcc/ipa-visibility.c +++ gcc/ipa-visibility.c @@ -571,8 +571,6 @@ localize_node (bool whole_program, symtab_node *node) next != node; next = next->same_comdat_group) { next->set_comdat_group (NULL); - if (!next->alias) - next->set_section (NULL); if (!next->transparent_alias) next->make_decl_local (); next->unique_name @@ -595,8 +593,6 @@ localize_node (bool whole_program, symtab_node *node) if (TREE_PUBLIC (node->decl)) node->set_comdat_group (NULL); - if (DECL_COMDAT (node->decl) && !node->alias) - node->set_section (NULL); if (!node->transparent_alias) { node->resolution = LDPR_PREVAILING_DEF_IRONLY; diff --git gcc/testsuite/g++.dg/ext/section-class-inline-function-lto.C gcc/testsuite/g++.dg/ext/section-class-inline-function-lto.C new file mode 100644 index 00000000000..4567d03a512 --- /dev/null +++ gcc/testsuite/g++.dg/ext/section-class-inline-function-lto.C @@ -0,0 +1,17 @@ +// attribute((section)) should affect inline member functions even with -flto. + +// { dg-do link } +// { dg-require-effective-target lto } +// { dg-require-named-sections "" } +// { dg-options "-flto --save-temps" } + +// { dg-final { scan-lto-assembler-symbol-section {callee} {^(\.testsection|__TEXT,__testsection)$} } } +#include "section-class-inline-function.C" + +// { dg-final { cleanup-saved-temps } } + +int +main() +{ + return f(); +} diff --git gcc/testsuite/g++.dg/ext/section-class-inline-function.C gcc/testsuite/g++.dg/ext/section-class-inline-function.C new file mode 100644 index 00000000000..01a12d02aff --- /dev/null +++ gcc/testsuite/g++.dg/ext/section-class-inline-function.C @@ -0,0 +1,25 @@ +// attribute((section)) should affect inline member functions. + +// { dg-do compile } +// { dg-require-named-sections "" } + +#if defined(__APPLE__) +#define TESTSECTION "__TEXT,__testsection" +#else +#define TESTSECTION ".testsection" +#endif + +// { dg-final { scan-assembler-symbol-section {callee} {^(\.testsection|__TEXT,__testsection)$} } } +struct s { + __attribute__((section(TESTSECTION))) + int callee() + { + return 0; + } +}; + +int +f() +{ + return s().callee(); +} diff --git gcc/testsuite/lib/scanasm.exp gcc/testsuite/lib/scanasm.exp index e9ebf52d77e..2eeb5b1e1fb 100644 --- gcc/testsuite/lib/scanasm.exp +++ gcc/testsuite/lib/scanasm.exp @@ -183,6 +183,29 @@ proc scan-assembler-symbol-section { args } { $expected_section_pattern } +# Check that symbols are emitted in the desired section. +# Like scan-assembler-symbol-section, but using the assembly output generated by +# the compiler with '-flto --save-temps'. +# +# Example: +# +# // All numbered functions (func1, func2, etc.) must be in the .text section or +# // in a .text sub-section (like .text._func1). +# { dg-final { scan-lto-assembler-symbol-section {^_func[1-5]$} {^\.text($|\.)} } } + +proc scan-lto-assembler-symbol-section { args } { + set testcase [testname-for-summary] + set output_file [lto_assembly_output_file $testcase] + set symbol_pattern [lindex $args 0] + set expected_section_pattern [lindex $args 1] + dg-scan-symbol-section \ + "scan-lto-assembler-symbol-section" \ + $testcase \ + $output_file \ + $symbol_pattern \ + $expected_section_pattern +} +