Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3333430pxa; Tue, 18 Aug 2020 12:27:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGuk+w+YhPHxjSYQy4dFOnlUMvhmB9klQu4HoEAauECljww5QPRxgH4Olr9vLGf+O6x6/C X-Received: by 2002:a17:906:551:: with SMTP id k17mr808350eja.322.1597778849117; Tue, 18 Aug 2020 12:27:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597778849; cv=none; d=google.com; s=arc-20160816; b=hxPpnoVg6EC8RSkCQ5CIg41LXoshs22x3dBUgP3kZTz/KzoOVJSjzdtnFECqPJ2MMm NbsMq+7XsunHaM7S300IWTEsMGjxe5uLrUd48VYKsZHs3W8N9n5w5ZP0eBh+l9ILJ5Y3 Ul5fi6HqMcmiI+yiIkS1A97IpQ1e9o/nf+oBh9VWCQeJBCLYalc7EDGPcGXay/PhlFrA LeNCi9J6LGm+fFcQlaFLDjci/9IBUWpoVVvLAk5VI+/pJVgkYF38p49mfFKl4Qi7yQqd dC9XwjV7vVkcR1jonBzvd6vS8xTqGUEFSLC9IMIx/lWOwb0XqV6jyBI16N6iGyRyA7Qq ZYew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=kFeSutuGf3xw6mwr4dd80pO6ztRTSBecGX8+DwTwSdM=; b=sbeWsS+Nt55MjMEhJ7Dw2b++h5MEUruRK47LVVa2OUWbEdaiM5EVIBcjvDpTfCfBV2 FZGzjTMDIgM0mzSlKPwu2s0eihG+ItIP0sQoHzMrbsWObHZUcseFvicuFzxbDoJ5z4vg pR7+Xw3WNvPjxeSOuTFpU9YfZuQQWzsBjfBiJ8LB5VkSn3OGBlkIF3G2BRghNZ2i7iaq ANuRcBvaVsXUGOwSTu1wMgcOsD4/xPjgKWzF8h7zWOb6Te6LlR1DCZWacBteo6YjeOjD gobGmr5l0rMjNbarhETzdOLwVA9O0YL9mbD5UFjo73vhNBqWnl8DjyE0pOX8ZA+Sma9E ILbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WmSIlBtC; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ss14si13728777ejb.651.2020.08.18.12.27.05; Tue, 18 Aug 2020 12:27:29 -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=@chromium.org header.s=google header.b=WmSIlBtC; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726763AbgHRTZC (ORCPT + 99 others); Tue, 18 Aug 2020 15:25:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726682AbgHRTY7 (ORCPT ); Tue, 18 Aug 2020 15:24:59 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73264C061389 for ; Tue, 18 Aug 2020 12:24:59 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id mt12so9854503pjb.4 for ; Tue, 18 Aug 2020 12:24:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=kFeSutuGf3xw6mwr4dd80pO6ztRTSBecGX8+DwTwSdM=; b=WmSIlBtCjefOEEctRBNhcCgMoZXnSJx8HtD5fvZbdik6lJgW1rd13/4c/PNRJwTnpj Bvzg3g1m6mPzHZII1dfho8iEGO6I1+5irFAPTvBY5Fm0Pb0tomkEFPmh/Y0EqnVwsQpo Mhw8k5UYPf4oW++qErDVWgzPAL4CI9bdZEq4M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=kFeSutuGf3xw6mwr4dd80pO6ztRTSBecGX8+DwTwSdM=; b=mAIrCFiUcH62djGFOGXB7bHz/quvXDi5+KO9noCysFbRhy91CSP5Ir3iCbapB8hkV3 pOXq8aYc1+0GGD1ShPEK2/BKvoJ0AnWCHE6L6r8TnCzmvWOJkF+p4kyatFWKFPhccTOl 6wDClnM54QKUDONpTxmzkFv9ZnUt7HfZSBt/hZymSyDwPKUq+Caq7di/1KyaQkSwxCwV fvI6OIPj8gBLXubPJaNcCLdEDbjtiDJbLJ7FJqt4TyW8AXadDoILHSjRfe9j+GRyMFdM 2pkTm2oAPRs5SM5TLGO9dsT2xygRvQuW1C9TVopvM5JEEvltTye+sKCCMSRoWCFZk0eo BLew== X-Gm-Message-State: AOAM533lRG1FAHo8uA+Y46t0bqajQWm0AkC5UXNMC9qujZuE9eXIa2xP 0DmJZtj3LDseZrK27nRwRCOG0w== X-Received: by 2002:a17:90b:684:: with SMTP id m4mr1172948pjz.4.1597778699059; Tue, 18 Aug 2020 12:24:59 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x28sm25848722pfj.73.2020.08.18.12.24.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2020 12:24:58 -0700 (PDT) Date: Tue, 18 Aug 2020 12:24:57 -0700 From: Kees Cook To: Nick Desaulniers Cc: Masahiro Yamada , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Michal Marek , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Tony Luck , Dmitry Vyukov , Michael Ellerman , Joe Perches , Joel Fernandes , Daniel Axtens , Arvind Sankar , Andy Shevchenko , Alexandru Ardelean , Yury Norov , x86@kernel.org, "H . Peter Anvin" , Ard Biesheuvel , "Paul E . McKenney" , Daniel Kiper , Bruce Ashfield , Marco Elver , Vamshi K Sthambamkadi , Andi Kleen , Linus Torvalds , =?iso-8859-1?Q?D=E1vid_Bolvansk=FD?= , Eli Friedman Subject: Re: [PATCH 4/4] x86: don't build CONFIG_X86_32 as -ffreestanding Message-ID: <202008181224.096C2926E@keescook> References: <20200817220212.338670-1-ndesaulniers@google.com> <20200817220212.338670-5-ndesaulniers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200817220212.338670-5-ndesaulniers@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 17, 2020 at 03:02:12PM -0700, Nick Desaulniers wrote: > -ffreestanding typically inhibits "libcall optimizations" where calls to > certain library functions can be replaced by the compiler in certain > cases to calls to other library functions that may be more efficient. > This can be problematic for embedded targets that don't provide full > libc implementations. > > -ffreestanding inhibits all such optimizations, which is the safe > choice, but generally we want the optimizations that are performed. The > Linux kernel does implement a fair amount of libc routines. Instead of > -ffreestanding (which makes more sense in smaller images like kexec's > purgatory image), prefer -fno-builtin-* flags to disable the compiler > from emitting calls to functions which may not be defined. > > If you see a linkage failure due to a missing symbol that's typically > defined in a libc, and not explicitly called from the source code, then > the compiler may have done such a transform. You can either implement > such a function (ie. in lib/string.c) or disable the transform outright > via -fno-builtin-* flag (where * is the name of the library routine, ie. > -fno-builtin-bcmp). > > i386_defconfig build+boot tested with GCC and Clang. Removes a pretty > old TODO from the codebase. > > Fixes: 6edfba1b33c7 ("x86_64: Don't define string functions to builtin") > Suggested-by: Arvind Sankar > Signed-off-by: Nick Desaulniers Reviewed-by: Kees Cook -- Kees Cook