From patchwork Mon Jan 8 20:21:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 760791 Delivered-To: patch@linaro.org Received: by 2002:a5d:6e02:0:b0:337:62d3:c6d5 with SMTP id h2csp1062840wrz; Mon, 8 Jan 2024 12:25:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IF65yMXPwwa+YFi9o9dDSEwQgS8JPAKQN5FfdOwUbGd0NdQINjOf6ElBAldYubASiPzyiMU X-Received: by 2002:a05:6870:ab8b:b0:205:cb69:ecce with SMTP id gs11-20020a056870ab8b00b00205cb69eccemr3490221oab.52.1704745504537; Mon, 08 Jan 2024 12:25:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704745504; cv=pass; d=google.com; s=arc-20160816; b=rO5WkCFNNMe4CXXJ+37loHQrRJn43yQedPqN4vQKyVrwD8681Knw2eXG8ivq6lmOvO vu87Sn+KNs8Gqvf3kjrLBEtdtENGy8LeSaW7mk24c5efmLRbHiTjeaZGBd9qOXad13QN THzBxu318xoRVhlWYAAS5abXee8XHHIVh6vhE3GUVFwER8EOZJDbi5co51rHfm9/HT7y Z1OXg0BWeHhDeK0dZKndIy1ogtUMBrjc0HhDh/KgLYhzjK1WwIso54ef3tGm4QxF2Klh 8gTQfKSfb3OosobNOGH7Md0qWSewRC6p7+Kx3iE6ZsSB8in9XvaDwIKFPCtl/GC1PS8f 5suw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=+lXNyVmzS19qsCwprnU9lhxbiK68WYoELWDA1qhWWV0=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=OgxPCYTtDpJVEIWQUgtXypscGJg04rdEORfvSMHf+WK5yVHk89shOaPsAGRVtE6Kg7 hIPV5f7aX+GwwcCPifqK1ulssdg2n65eyv5rDYCuXUZGPnQBjM88rBzhzq9RCBVBOLy0 lXeFWzl2IPoiPk1bJ2LtMMALqzTsMYUHkh0RsZvHKHVyGor9/sHbdjHUrpZDmVMfihHN N1Izl4K+6yJrtlQojfbntVz+VYXaC0E4DI6SgpFh2N98hdEulmkqbsdVVtsSm6F33ScZ prpB4fveGQhBy7GSpixNIRLe38oa8bLsHtwniUKjkgxhRIY//gwllqgEMX2QI0J3CilU sCtA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yo++BxOF; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k8-20020a05620a414800b007831cab89e7si550308qko.170.2024.01.08.12.25.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 12:25:04 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yo++BxOF; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E6783385803D for ; Mon, 8 Jan 2024 20:25:03 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 9A86F3858415 for ; Mon, 8 Jan 2024 20:22:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A86F3858415 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9A86F3858415 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704745336; cv=none; b=jD4Qwe31upU8QOBSykVaG8aI+NLLr58P0EWPL8z3WVj3C1a7poNEvLqRsfrpDW6BJIlzDmIPWhLAWCVndIiA/D+1xtY3splvYNsHDrjgi472zTHJCbe4sZgEDczmQhwVRO9J/KwJo0GEFWyZo5XZgoRgJ0QklJ6RKj2maXB4dpI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704745336; c=relaxed/simple; bh=wNEfDapJnYnujUhCBMBO9HlIe30rH4wQGFMbqQzqlEE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=jNH+IlpjJaEIYZ+JqkMr5Y009LuBI8qrV1Nzpp5qFVVYWXD9YEaAzkqnkUPeoOLdN4tzw4PzDyTbbL2Olz1oEMFMlLaOzX3KFzai36PIZv7ncCs3rdQhM0T+gNAlmqTdpn3se+G1YQ4UKSzli2AdVWxH5GjfWYA7jLr27tHqSew= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6d99980b2e0so1945063b3a.2 for ; Mon, 08 Jan 2024 12:22:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704745331; x=1705350131; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+lXNyVmzS19qsCwprnU9lhxbiK68WYoELWDA1qhWWV0=; b=yo++BxOFnj21H1ysTdl097l3QAwAYwp/7HFRTRRSgVsAdLR63M7dkLGQbdZzWLOQZF ErEqwFxq0+226lim03JdudDrtX1UrywHk085pHavse+ro4FjXFtgSi8yDlAkXjm3joqy NaYURNXvmr1rPp8uJjR0peVl8lbAwvyQTsNujzmgsmcSxPWuFt4Exkv2cSSm4MDvDgmD ZUPShyKjU+QFrM/JgR0evngimgz8Dfs832idGGGUQl9lL2PuodyAY6rnCaQUQdiLCxNT 8UYpHmpAnZMv5rWdeSNCnX/Ii2PeDW/Taykd5JxNlTJV9CBp34H6tUcYjGvpNg0shHNr dwmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704745331; x=1705350131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+lXNyVmzS19qsCwprnU9lhxbiK68WYoELWDA1qhWWV0=; b=eF0x8QkCdhHLtpRS8ShI6IRA6jisqv/teYgZbZICvalB1rWUy0MGS3Tsd5Z6g2S9J5 EOf+lZQscjQkIES+lvkNL0v/8+bziBoToK4UDo+JaLtI88qdAW2YE43MSBOeJ0ShpTRY O9iBTz9kfN1H+3D3A7o5EQaiRURUSeDvUQZAqZe8KePGWxlih4O9mdZv57+6AJyUvgCM SjYH6dHB8a0TzCWYjDfFJLowXCTFqsTuMtU/aGmLw3a0gyCvUEweLGTMVAExhP4Ln0/0 +5p7AmXrsUUDAUcUwLxR6cyDbn6JOFq/wsSJbYwgZ/kIHG2w57rFmYFJ0KPzXjYtayKt C4og== X-Gm-Message-State: AOJu0YyFg7uEgnx3rTVWSiEynuRTRxcLZhp1N01/ggSNnOI/NktZffLQ aQDoA90EkcRPFwJBlDG5I1Hm8J9XvJ9hLKDZac5QNpA4/V4= X-Received: by 2002:aa7:9205:0:b0:6da:23d7:3786 with SMTP id 5-20020aa79205000000b006da23d73786mr3783344pfo.21.1704745331056; Mon, 08 Jan 2024 12:22:11 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:9dd2:7f25:c108:2fff:5f8e]) by smtp.gmail.com with ESMTPSA id z13-20020a62d10d000000b006d9bdc0f765sm287936pfg.53.2024.01.08.12.22.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 12:22:10 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 10/10] debug: Improve mqueue.h fortify warnings with clang Date: Mon, 8 Jan 2024 17:21:49 -0300 Message-Id: <20240108202149.335305-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240108202149.335305-1-adhemerval.zanella@linaro.org> References: <20240108202149.335305-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org It improve mq_open. The compile and runtime checks have similar coverage as with GCC. Checked on aarch64, armhf, x86_64, and i686. --- rt/bits/mqueue2.h | 29 +++++++++++++++++++++++++++++ rt/mqueue.h | 3 +-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/rt/bits/mqueue2.h b/rt/bits/mqueue2.h index 0f9d67966f..d6d2d9012d 100644 --- a/rt/bits/mqueue2.h +++ b/rt/bits/mqueue2.h @@ -29,6 +29,8 @@ extern mqd_t __mq_open_2 (const char *__name, int __oflag) extern mqd_t __REDIRECT_NTH (__mq_open_alias, (const char *__name, int __oflag, ...), mq_open) __nonnull ((1)); + +#ifdef __va_arg_pack_len __errordecl (__mq_open_wrong_number_of_args, "mq_open can be called either with 2 or 4 arguments"); __errordecl (__mq_open_missing_mode_and_attr, @@ -55,3 +57,30 @@ __NTH (mq_open (const char *__name, int __oflag, ...)) return __mq_open_alias (__name, __oflag, __va_arg_pack ()); } +#elif __fortify_use_clang +__fortify_function_error_function __attribute_overloadable__ mqd_t +__NTH (mq_open (const char *__name, int __oflag, mode_t mode)) + __fortify_clang_unavailable ("mq_open can be called either with 2 or 4 arguments"); + +__fortify_function_error_function __attribute_overloadable__ mqd_t +__NTH (mq_open (const char *__name, int __oflag, mode_t mode, + struct mq_attr *attr, ...)) + __fortify_clang_unavailable ("mq_open can be called either with 2 or 4 arguments"); + +__fortify_function __attribute_overloadable__ mqd_t +__NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name), + int __oflag)) + __fortify_clang_prefer_this_overload + __fortify_clang_error ((__oflag & O_CREAT), + "mq_open with O_CREAT in second argument needs 4 arguments") +{ + return __mq_open_alias (__name, __oflag); +} + +__fortify_function __attribute_overloadable__ mqd_t +__NTH (mq_open (__fortify_clang_overload_arg (const char *, ,__name), + int __oflag, int __mode, struct mq_attr *__attr)) +{ + return __mq_open_alias (__name, __oflag, __mode, __attr); +} +#endif diff --git a/rt/mqueue.h b/rt/mqueue.h index 787cc36df2..d39334ba16 100644 --- a/rt/mqueue.h +++ b/rt/mqueue.h @@ -110,8 +110,7 @@ extern int __REDIRECT (mq_timedsend, (mqd_t __mqdes, #endif /* Define some inlines helping to catch common problems. */ -#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function \ - && defined __va_arg_pack_len +#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function # include #endif