From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 2B5323858D32 for ; Thu, 1 Dec 2022 11:31:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2B5323858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x532.google.com with SMTP id e13so1933185edj.7 for ; Thu, 01 Dec 2022 03:31:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=r2IWf+aMyzSWyZb9lBmiRglnH3OSr6xEINZqqxuXd1g=; b=pLhyOf0/EaJVT/nqZEZOWowJnbvEAjMZR26bKF3zKg5sn0Czz2B94B6lNQNMj/D1Dl MkLKNxgHrhyJ4ro0E1jDNl0bLMeIOgtd8N2eYLlLRn3qTBGjXNYTH8r5VT8R1HrNI5zU UBbPHsvJCHdtyvMM9P02EE9FGMRr+VoHCcgPDM2/ff6nyPePNvvRSeuYc7FfeJcia+bX gQhtT/0SpBnETBd5ApAxAl0f7+nDZJzJuWtFv18unuV7Mmxe4HNd0n7XJsAzkeFqfgNh 59gxHKPabviotUoT+G2r2+fM2z+fF36sORujbaQKv+cYuChJTL+0HfXvYcqFry/kYClX ZJ/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=r2IWf+aMyzSWyZb9lBmiRglnH3OSr6xEINZqqxuXd1g=; b=Up05olWndUChLZQfzEWPA5p6BUDAVigDhjf2KIBgi7BJNgU6u7vjlIvjjK9+eXCdu+ MFpxB1oGhDW250FvFU9yEA+bXR0OJGM2+nqAsZ6DzMAcFSAayiXscXEbL+CFGuucUQAf oCdbTpt86/e5XmURl0Ogz65ZiHhx736tVPZLNx8DLb6Gs63Bo8rmbUC+waOakBe02LzF 3siROtl5ziy+yQhwPVB1M05diB1YwHA/6bRksz6ma0SbnVaVbjQitOkdvoCjXYqUdCGM Y3KeBC7BTOu4gLE3fA9hS2kduJa9jI32gujT+d3uA+ABTPN9GF7fFP93jGMq19coZwqY Y0bA== X-Gm-Message-State: ANoB5pm5zGbux/r8J7WIWM5gcIjxoBpyq3aIYM0AYPCJI9RRhL8tgyN8 u1JdsMvbkdTSRKK2qTfAQepRpN5k/vGh8Dn9Tng= X-Google-Smtp-Source: AA0mqf52tS3yo/Rh63Gbv27GZK+qVZiM3YXE3l4n9cMyp0jLFvC5PQtTGOUxkg+k6Tfo5k/hcBCwG+b/2BeSrFHUCFY= X-Received: by 2002:aa7:dbc7:0:b0:45f:b80f:1fe8 with SMTP id v7-20020aa7dbc7000000b0045fb80f1fe8mr57138192edt.118.1669894306636; Thu, 01 Dec 2022 03:31:46 -0800 (PST) MIME-Version: 1.0 References: <4366aeb5-7fdb-6fa4-b0f5-ebe74c1d4fb2@jguk.org> <178e21a7-8e34-7240-5d53-c2783451b9a9@jguk.org> In-Reply-To: <178e21a7-8e34-7240-5d53-c2783451b9a9@jguk.org> From: Jonathan Wakely Date: Thu, 1 Dec 2022 11:31:35 +0000 Message-ID: Subject: Re: Avoiding stack buffer clear being optimised out To: Jonny Grant Cc: gcc-help Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 1 Dec 2022 at 10:44, Jonny Grant wrote: > Thank you Jonathan and David for your replies. > > That "noipa" looks to have sorted this issue > > https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html > > That page also suggests "noinline" attribute which seems to suggest I'd need to add asm (""); in each wrapper of memset() I already used the noinline attribute in my example above. > I'd much rather have memset_s - Jonathan, do you think GCC could add some built-in functions for memset_s ? __builtin_memset_s() would be great. No. But C2x adds a memset_explicit function that does what you want, so that should arrive in glibc soonish. I thought it had been added, but was searching the C2x draft for "memset_secure" and other incorrect names. https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2631.htm was the proposal adding it. > > There are quite a few similar ones that should be easy to add based on existing > (memcpy_s, memmove_s, strcpy_s, strncpy_s, strcat_s, strncat_s, strtok_s, memset_s, strerror_s, strerrorlen_s, strnlen_s). They're not good APIs. See https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm and https://sourceware.org/legacy-ml/libc-help/2018-01/msg00007.html > I did speak to someone at LLVM who was considering adding built-ins to clang. > > Kind regards > Jonny > >