From patchwork Tue Apr 12 09:47:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yanchao X-Patchwork-Id: 52809 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6767B3857364 for ; Tue, 12 Apr 2022 09:48:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6767B3857364 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1649756890; bh=sDH/umILPGQEATgvbo7EVmL8dYqcyjmlnYyFBpAfDCQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=u1ayxV8HAPA4WyYkgvasXbkR60jT4kc/kK7B7NQQy5BIbkDPWo2tdmh2tmQkwOJS2 TM566idQCyj8OXlG0SscT6sTkkaFvawV9c6Nt+C2Hi7FaBBKT4EAm9ZXY4w/KBcD5R zjsXuckytIoGKQFqrNpvCXBx81SvGKSG9FxLS2Rg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by sourceware.org (Postfix) with ESMTPS id 24B523857405 for ; Tue, 12 Apr 2022 09:47:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 24B523857405 Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Kd18r1N3fzdZqp; Tue, 12 Apr 2022 17:47:08 +0800 (CST) Received: from dggpeml100016.china.huawei.com (7.185.36.216) by dggpeml500025.china.huawei.com (7.185.36.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 12 Apr 2022 17:47:42 +0800 Received: from huawei.com (10.174.179.133) by dggpeml100016.china.huawei.com (7.185.36.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 12 Apr 2022 17:47:42 +0800 To: Subject: [PATCH v4] elf: fixes compile error when both enable -Werror and -DNDEBUG Date: Tue, 12 Apr 2022 17:47:41 +0800 Message-ID: <20220412094741.1902-1-yangyanchao6@huawei.com> X-Mailer: git-send-email 2.31.1.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.174.179.133] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml100016.china.huawei.com (7.185.36.216) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yang Yanchao via Libc-alpha From: Yang Yanchao Reply-To: Yang Yanchao Cc: linfeilong@huawei.com, schwab@linux-m68k.org, fweimer@redhat.com Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Use -Werror and -DNDEBUG at the same time will causes the following compilation errors: cache.c: In function 'save_cache': cache.c:758:15: error: unused variable 'old_offset' [-Werror=unused-variable] 758 | off64_t old_offset = lseek64 (fd, extension_offset, SEEK_SET); | ^~~~~~~~~~ -DNDEBUG will disables the assertion. Therefore, only the variables used by assertions do not take effect. use DIAG_IGNORE_NEEDS_COMMENT to disable this warning. --- elf/cache.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/elf/cache.c b/elf/cache.c index dbf4c83a7a..1e5427555b 100644 --- a/elf/cache.c +++ b/elf/cache.c @@ -36,6 +36,7 @@ #include #include #include +#include /* Used to store library names, paths, and other strings. */ static struct stringtable strings; @@ -751,6 +752,10 @@ save_cache (const char *cache_name) != (ssize_t) strings_finalized.size) error (EXIT_FAILURE, errno, _("Writing of cache data failed")); + /* Building with -DNDEBUG, assert will be ignored, + so that old_offset is not used */ + DIAG_PUSH_NEEDS_COMMENT + DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wunused-variable"); if (opt_format != opt_format_old) { /* Align file position to 4. */ @@ -758,6 +763,7 @@ save_cache (const char *cache_name) assert ((unsigned long long int) (extension_offset - old_offset) < 4); write_extensions (fd, str_offset, extension_offset); } + DIAG_POP_NEEDS_COMMENT /* Make sure user can always read cache file */ if (chmod (temp_name, S_IROTH|S_IRGRP|S_IRUSR|S_IWUSR))