Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp63525pxa; Tue, 18 Aug 2020 16:02:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj/lPPIx4szMxvTtRhVjJznO3Z4FjMPLuM29ugailEIqE744fkWtTQl0Ftj+fcuTO83TnC X-Received: by 2002:a17:906:d930:: with SMTP id rn16mr23211906ejb.330.1597791737600; Tue, 18 Aug 2020 16:02:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597791737; cv=none; d=google.com; s=arc-20160816; b=EZxqGDV9RTKCr9hg4yccGOtT5oX+jkn8Tn2GfXoKjxLtWgvadTzqEx7GB6kseh/sOL 9OtJyzlWbR+NkWmjlTdhD51ujnaGu3+eypCX6L6G0Zy16KBqY13OdKHrLfcFyamtgjWD zde1tAO/1i96PKSfHJwE/kCBrOwrdZqcytnrizgUxjPhoUOgUSI3hLqTeGxu07TIcv6r xurfzyABK8R3QuanTSx5WbQ5yowU1cXdsJQZ22NG9JyJR/bSsmJlZRRZ2snVOvnQA7VX XoLvfo81G1HFHQjrDNYmbxv7+VDrb3odbF0sOP5Y8yMYow1G3dLZe80gRsIbzZM/QQi+ 59Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=J2pGygoF7KWIJaR/BRx/jtL9q1tfpvhnVW6lipaKLMs=; b=gaYlgdBylL/J/2Y6q5DO8CQZ5wkKSm44+KAK2t+R9z6nx9Pvl8OEqK2Jgk/poikIBK IBI4uh73liVoNueGPlBHEnARH4k+9DjohA1MI/0UIygT4X3Fhs4BveGB+xfcYo9/m/4w 3OgR1VLgHYPTurLJ4C9MYQWZSv9LOKRfkzZ5OkoMVO3kj+ombuXStaKhJJMBksqrvIKf RQ7tvgJ+gClfZrhi1nfdzEIYmz7RUwX5NQfa65ZM5/KtqZogb0Q6v1/x8xcbVEgIOAqF 824vW8HzaeRlnf30AVRxBAOlh10FZ31cZTtV21U7md7KQlntFF+Hh/YvowEk6OdvfZSQ ktNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oejoDBdo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mb5si14325908ejb.206.2020.08.18.16.01.38; Tue, 18 Aug 2020 16:02:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oejoDBdo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727076AbgHRXAB (ORCPT + 99 others); Tue, 18 Aug 2020 19:00:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726799AbgHRW76 (ORCPT ); Tue, 18 Aug 2020 18:59:58 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F079C061389 for ; Tue, 18 Aug 2020 15:59:58 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id ep8so210850pjb.3 for ; Tue, 18 Aug 2020 15:59:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=J2pGygoF7KWIJaR/BRx/jtL9q1tfpvhnVW6lipaKLMs=; b=oejoDBdod/XT+qS47scwauhM7mYjpU0xiMBgXoVFwRvfIQGA4CTvTu3fRHibAUtHYd 5ZnK/LUTYhDUsPwtLNERJIXEuV0Gke43W8JfC95l4XD/oiDTEkMVCtxPinAqBBD+m3l3 kp6gsNCvw90h/jV0F+nSQNqISP54PMPFFV/fi1ST66IQrnHoqICZjF+ipxb6IoSisNRo ZYZQ+zVDIB8CxkfWs4lnk/xItWAQAOdPXOv9kfM63gpchjZoijeoA4gPkuLlWryvirhb pq1hYuuByYHQeONpW24gozAzS8d2sUaS4pE2K3iUlSOyFrqcAl69HC8XD695CdRECSmP UIuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=J2pGygoF7KWIJaR/BRx/jtL9q1tfpvhnVW6lipaKLMs=; b=k3LW+wwZakM0oNC0y3pJ+xtP6GT5pIQBx6lKUWFmqEe+8CT4y0Me99bBwH+vovwy1N Irxf4ILJbXCle1cdVSdcodFYSoOLYgiD/NGwlFLEijEhB76cw4k+99YYqrNIhdcub9qS tydcyqqHx6e1Zka7wYi60zVCaKAPfoMaMD7Hi+Ethv5YG+1vWpVs/PDU0UQFv3yeUxJP Uj1+cUrdeU6z5JRqUkkn6cRhZBqR8wtYXGNF0nNtQ7qAn9V9+gF/mrN0Hcf0gIRONK3Q svLD458Jeze4lC7UvrOmxHe3Wl/8JrtKK4EgzIsC4RGtpPn0+fgxPVupN/lsCkhGnJyw b09Q== X-Gm-Message-State: AOAM533e7TkId47i2X9s1ZiXo3U5nr2gjmrNFszeDw/pGgcPc1/UN6D8 TFTCHsJW5mY7ceIjoMGel/OVUeTfm6CX6W9CLvAPRQ== X-Received: by 2002:a17:902:7c8b:: with SMTP id y11mr16352038pll.119.1597791597450; Tue, 18 Aug 2020 15:59:57 -0700 (PDT) MIME-Version: 1.0 References: <20200817220212.338670-1-ndesaulniers@google.com> <20200818222542.GA3254379@rani.riverdale.lan> In-Reply-To: <20200818222542.GA3254379@rani.riverdale.lan> From: Nick Desaulniers Date: Tue, 18 Aug 2020 15:59:45 -0700 Message-ID: Subject: Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches To: Arvind Sankar , Eli Friedman Cc: Masahiro Yamada , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Michal Marek , Linux Kbuild mailing list , LKML , Kees Cook , Tony Luck , Dmitry Vyukov , Michael Ellerman , Joe Perches , Joel Fernandes , Daniel Axtens , Andy Shevchenko , Alexandru Ardelean , Yury Norov , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H . Peter Anvin" , Ard Biesheuvel , "Paul E . McKenney" , Daniel Kiper , Bruce Ashfield , Marco Elver , Vamshi K Sthambamkadi , Andi Kleen , Linus Torvalds , =?UTF-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 18, 2020 at 3:25 PM Arvind Sankar wrote: > > Another thing that needs to be fixed is that at least lib/string.c needs > to be compiled with -ffreestanding. > > gcc-10 optimizes the generic memset implementation in there into a call > to memset. Now that's on x86 which doesn't use the generic > implementation, but this is just waiting to bite us. > > https://godbolt.org/z/6EhG15 I'll let you send the patch for that this time. (It's too bad godbolt doesn't have newer versions of GCC for cross compilation...cant test aarch64 gcc-10, for example.) It would be interesting for sure to see resulting differences in disassembly observed in lib/string.o with -ffreestanding. But, oof, that's not good. Certainly impressive and powerful loop idiom recognition, but wouldn't you consider it a bug that this optimization should probably first check that it's not replacing part of a loop with a potentially recursive call to itself? Admittedly, we've had the same shenanigans with memcpy implemented in terms of calls to __builtin_memcpy being lowered to infinitely recursive calls...which feels like the same kind of bug. ("You wanted infinite recursion in the kexec purgatory image, right?" "No, compiler, I did not.") example: https://godbolt.org/z/MzrTaM (probably should fix this in both implementations; at the least I feel like Clang's -Winfinite-recursion should try to help us out here). Feels almost like it may be difficult to provide an implementation of memset without stepping on a landmine. One thing I'd be curious about is whether all of lib/string.c would need -ffreestanding, or if you could move just memset to its own TU then use -ffreestanding on that. A free standing environment must always provide a core set of functions like memset, memcpy, memcmp, memmove, according to https://gcc.gnu.org/onlinedocs/gcc/Standards.html. Maybe those four should be in a separate TU compiled as -ffreestanding, so that they can never be lowered to calls to themselves (potentially infinitely recursive)? -- Thanks, ~Nick Desaulniers