From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id C78A8385800A for ; Tue, 8 Dec 2020 12:51:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C78A8385800A Received: by mail-pf1-x431.google.com with SMTP id f9so13226024pfc.11 for ; Tue, 08 Dec 2020 04:51:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=XTxbh0MT3sqsxGUTrg9Bn+DRfdvglAILOJ85PRL/PVY=; b=QCdKEFirHVLREfFER/lVVRXCrPBqZM17iO/wLGPq/jFcOXiSkJDxrffJPisEK4bEXI oFWYOfaz5x7qnHPs/vQ0vk5XkqczjGRSp7LuaPq6xOedxaaeNmJ+/Qvcd2AisJameOWj qJMTNeNh7AKVUOZALjEW8ViF4i5PT+AL5oKLNauJNMUmc9K7rRJa9DXkRKSncfGVYfgA Ls7vj8EDx5kRSLZHsad4z6+RbtX8L8AbwAhKOxZ9VX9yHhrMe38j1COGKSFR5P9mTzOe GDcep/Sx9N15qWO2Eudwa2GLDzMLKDqI7D01j6pW6xuV/3wMcBsjYIRmUsvdLnEw/ax9 oVAw== X-Gm-Message-State: AOAM5337SWnwcsbhIALVl8eIi4YwfnIGrVKxaFPW5f4U5AQtOPgZvTVx k14snzfYiECwZkC1wEd6HSXAZ+8t9o4= X-Google-Smtp-Source: ABdhPJy7nesB/SX9tZyx6iKDUmpOIKnExPD4OU9SnZ1920avWrKIAF1LKk4bNoVAfhXI+/nv7t4UBQ== X-Received: by 2002:aa7:860b:0:b029:19e:2827:93b7 with SMTP id p11-20020aa7860b0000b029019e282793b7mr6987256pfn.22.1607431892350; Tue, 08 Dec 2020 04:51:32 -0800 (PST) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id l17sm3082258pjy.29.2020.12.08.04.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 04:51:31 -0800 (PST) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 937CD1A0177; Tue, 8 Dec 2020 04:51:30 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Subject: V3 [PATCH 0/2] Switch to a new section if the SECTION_RETAIN bit doesn't match Date: Tue, 8 Dec 2020 04:51:26 -0800 Message-Id: <20201208125128.775313-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3034.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Dec 2020 12:51:35 -0000 When SECTION_RETAIN is used, definitions marked with used attribute and unmarked definitions are placed in a section with the same name. Instead of issue an error: [hjl@gnu-cfl-2 gcc]$ /usr/gcc-11.0.0-x32/bin/gcc -S c.c -fdiagnostics-plain-output c.c:2:49: error: ‘foo1’ causes a section type conflict with ‘foo2’ c.c:1:54: note: ‘foo2’ was declared here [hjl@gnu-cfl-2 gcc]$ the first patch switches to a new section if the SECTION_RETAIN bit doesn't match. The second optional patch issues a warning: [hjl@gnu-cfl-2 gcc]$ ./xgcc -B./ -S c.c c.c:2:49: warning: ‘foo1’ without ‘used’ attribute and ‘foo2’ with ‘used’ attribute are placed in a section with the same name [-Wattributes] 2 | const int __attribute__((section(".data.foo"))) foo1 = 1; | ^~~~ c.c:1:54: note: ‘foo2’ was declared here 1 | const int __attribute__((used,section(".data.foo"))) foo2 = 2; | [hjl@gnu-cfl-2 gcc]$ Changes from V2: 1. Add (new_section->common.flags & SECTION_NAMED) check since SHF_GNU_RETAIN section must be named. 2. Move c-c++-common/attr-used-9.c to the fist patch since there are no new warnings. 3. Check new warnings only for R_flag_in_section target. H.J. Lu (2): Switch to a new section if the SECTION_RETAIN bit doesn't match Warn used and not used symbols in section with the same name gcc/output.h | 2 +- gcc/testsuite/c-c++-common/attr-used-5.c | 27 ++++++++++++++ gcc/testsuite/c-c++-common/attr-used-6.c | 27 ++++++++++++++ gcc/testsuite/c-c++-common/attr-used-7.c | 9 +++++ gcc/testsuite/c-c++-common/attr-used-8.c | 9 +++++ gcc/testsuite/c-c++-common/attr-used-9.c | 28 +++++++++++++++ gcc/varasm.c | 46 +++++++++++++++++++++--- 7 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/attr-used-5.c create mode 100644 gcc/testsuite/c-c++-common/attr-used-6.c create mode 100644 gcc/testsuite/c-c++-common/attr-used-7.c create mode 100644 gcc/testsuite/c-c++-common/attr-used-8.c create mode 100644 gcc/testsuite/c-c++-common/attr-used-9.c -- 2.28.0