Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp913777pxb; Thu, 17 Feb 2022 18:20:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDOxOAKmVkoVPUyM/Jm90sPvYWXP4FjQSaGTJPxeiBUGYzmOp/CJtTxwwz1v7/HRSeaB2a X-Received: by 2002:a17:902:8b86:b0:14f:cad:38f6 with SMTP id ay6-20020a1709028b8600b0014f0cad38f6mr5397995plb.3.1645150845978; Thu, 17 Feb 2022 18:20:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645150845; cv=none; d=google.com; s=arc-20160816; b=J5+8DivLEdCwIvlZmQ9oN0WXHkj6DFMbnWdND+0ZzVjN5z/NPFHzqlvqyvTFOp1qEs o863ZNyhxjRH2PFJeftyDSTvJS6kDOYe0MaY1SO0j7kU1pU45f43sOdzp9R+4T2n2AeP tw0BoWrbdXltgLNEtg4NAvceQCOWqtBUL3c1lofFxCHuebRj9Krtpd98/+UJmArsRVci 57w6sNwyW3a2DU3+FAN1SfztDslrNQe6IwRh9J79xpDrl7xSU30XwdM4dTQJG8ULPBJA vpn3aihiVxw8rSPPAwv5IUeDuu/UY9ySqrbqActKC6fX+kFv23fP+fZIxixbnCtotbBH bs7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature:dkim-filter; bh=oTkWcaEf9jnFVKJN3p9Suk7c1bsGL0A3lknSj12v+7I=; b=lehO0eo+Twh0tSAASBcVhvlM4RnEyaahQEHx6aJAh2hBLpdwxr6QTVqlpTMOx0fzEV pfH1dinAeJmRMaKggwg+ynvBymxFg8KjohAOV2fhDsXVPqf7yH9S8S6B1Ae4ZZO1mdf+ 6K8lxk4xU3GwCHVJM/fE7o4qORs4awSklmaBNJ9FOol3SuPv6qYidpr/JtLeQ5e0746w b+krHzu+ZmGodZydrO81NzzKlEw24kY556RYrN9IdYQnNsHIUxX7HAQpOLs76hqAgc0E 4bBFJHCENJOqodR9D4iMHDeIVRSxIJlwfisJipzLYBR5VMKhGjRqfiaHRcsy+w8h7mYE 0YAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=VDAcoaHN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n1si9884448pgj.247.2022.02.17.18.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Feb 2022 18:20:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=VDAcoaHN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B85F3E686B; Thu, 17 Feb 2022 18:20:43 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231511AbiBRCU5 (ORCPT + 99 others); Thu, 17 Feb 2022 21:20:57 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:52316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231479AbiBRCU4 (ORCPT ); Thu, 17 Feb 2022 21:20:56 -0500 X-Greylist: delayed 77082 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 17 Feb 2022 18:20:39 PST Received: from conssluserg-01.nifty.com (conssluserg-01.nifty.com [210.131.2.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7579B7DF; Thu, 17 Feb 2022 18:20:39 -0800 (PST) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (authenticated) by conssluserg-01.nifty.com with ESMTP id 21I2KCNZ023307; Fri, 18 Feb 2022 11:20:12 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-01.nifty.com 21I2KCNZ023307 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1645150813; bh=oTkWcaEf9jnFVKJN3p9Suk7c1bsGL0A3lknSj12v+7I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VDAcoaHNdUsbQLowZjruNwVk9mblUqzQo6ITBxcrlZY8Ma44uNYNxVO5bNPVUCt+s 1teshno3NGiIKYkFuxIqTE0lp2tDvcQM2/1aF7ViyKuPrSAJFg+YOvDu+3AbP9ieD4 yNqvtGdNJ8EtKFAKV9jJBMfgfVWBSsjS7I1WlME1f48bRfvOd4wHHbwn01MtauNIUD FtWmkSBFYZpHKMZrFB3LjAfxv+RVB03iP0e6bV53GYDMLjTxlNEG32ibk4c0THVeFp T8pWE/bPL4ppW9+sbjsdjMlTrKurERvsQgFE80ws1vcqbHBT5DiN3vR1SAn3g47+qu wVt93TczYyScQ== X-Nifty-SrcIP: [209.85.216.54] Received: by mail-pj1-f54.google.com with SMTP id m7so7385863pjk.0; Thu, 17 Feb 2022 18:20:12 -0800 (PST) X-Gm-Message-State: AOAM532xze/2D0u2/mAzCrqinu/8uz3wvXcanIZcpWiSKN03YT5fLUkz MS6ObeFWqAusMwQEJtY/UdgQ6n2UkntUsjj/Gz8= X-Received: by 2002:a17:90a:ab17:b0:1b9:b61a:aadb with SMTP id m23-20020a17090aab1700b001b9b61aaadbmr6008892pjq.77.1645150811855; Thu, 17 Feb 2022 18:20:11 -0800 (PST) MIME-Version: 1.0 References: <20220217002843.2312603-1-keescook@chromium.org> In-Reply-To: From: Masahiro Yamada Date: Fri, 18 Feb 2022 11:19:32 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] um: Allow builds with Clang To: Nathan Chancellor Cc: Kees Cook , Jeff Dike , Richard Weinberger , Anton Ivanov , Nick Desaulniers , David Gow , linux-um@lists.infradead.org, Linux Kbuild mailing list , "open list:KERNEL SELFTEST FRAMEWORK" , kunit-dev@googlegroups.com, llvm@lists.linux.dev, Linux Kernel Mailing List , X86 ML , linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 18, 2022 at 2:41 AM Nathan Chancellor wrote: > > On Thu, Feb 17, 2022 at 01:54:58PM +0900, Masahiro Yamada wrote: > > On Thu, Feb 17, 2022 at 9:28 AM Kees Cook wrote: > > > > > > Add x86-64 target for Clang+um and update user-offsets.c to use > > > Clang-friendly assembler, similar to the fix from commit cf0c3e68aa81 > > > ("kbuild: fix asm-offset generation to work with clang"). > > > > > > This lets me run KUnit tests with Clang: > > > > > > $ ./tools/testing/kunit/kunit.py config --make_options LLVM=1 > > > ... > > > $ ./tools/testing/kunit/kunit.py run --make_options LLVM=1 > > > ... > > > > > > Cc: Jeff Dike > > > Cc: Richard Weinberger > > > Cc: Anton Ivanov > > > Cc: Masahiro Yamada > > > Cc: Nick Desaulniers > > > Cc: Nathan Chancellor > > > Cc: David Gow > > > Cc: linux-um@lists.infradead.org > > > Cc: linux-kbuild@vger.kernel.org > > > Cc: linux-kselftest@vger.kernel.org > > > Cc: kunit-dev@googlegroups.com > > > Cc: llvm@lists.linux.dev > > > Signed-off-by: Kees Cook > > > --- > > > arch/x86/um/user-offsets.c | 4 ++-- > > > scripts/Makefile.clang | 1 + > > > 2 files changed, 3 insertions(+), 2 deletions(-) > > > > > > diff --git a/arch/x86/um/user-offsets.c b/arch/x86/um/user-offsets.c > > > index bae61554abcc..d9071827b515 100644 > > > --- a/arch/x86/um/user-offsets.c > > > +++ b/arch/x86/um/user-offsets.c > > > @@ -10,10 +10,10 @@ > > > #include > > > > > > #define DEFINE(sym, val) \ > > > - asm volatile("\n->" #sym " %0 " #val : : "i" (val)) > > > + asm volatile("\n.ascii \"->" #sym " %0 " #val "\"": : "i" (val)) > > > > > > #define DEFINE_LONGS(sym, val) \ > > > - asm volatile("\n->" #sym " %0 " #val : : "i" (val/sizeof(unsigned long))) > > > + asm volatile("\n.ascii \"->" #sym " %0 " #val "\"": : "i" (val/sizeof(unsigned long))) > > > > > > void foo(void) > > > { > > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > > > index 51fc23e2e9e5..857b23de51c6 100644 > > > --- a/scripts/Makefile.clang > > > +++ b/scripts/Makefile.clang > > > @@ -10,6 +10,7 @@ CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu > > > CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu > > > CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu > > > CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu > > > +CLANG_TARGET_FLAGS_um := x86_64-linux-gnu > > > > > > Does this work for the i386 host? > > > > UML supports i386 and x86_64 as the host architecture as of now, > > but this always compiles UML for x86_64? > > I think the current code will work because arch/x86/Makefile.um includes > -m32 for CONFIG_X86_32, which will implicitly change x86_64-linux-gnu > into a 32-bit target triple: Ah, you are right! > > $ echo | clang --target=x86_64-linux-gnu -x c -c -o test.o - > > $ file test.o > test.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped > > $ echo | clang --target=x86_64-linux-gnu -m32 -x c -c -o test.o - > > $ file test.o > test.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped > > In fact, we rely on this for ARCH=i386 LLVM=1 right now, as it uses > x86_64-linux-gnu for the target flag. > > While UML only supports x86, maybe it is worth using SUBARCH instead of > hardcoding the triple? No strong opinion around that though. > > diff --git a/scripts/Makefile.clang b/scripts/Makefile.clang > index 51fc23e2e9e5..87285b76adb2 100644 > --- a/scripts/Makefile.clang > +++ b/scripts/Makefile.clang > @@ -10,6 +10,7 @@ CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu > CLANG_TARGET_FLAGS_riscv := riscv64-linux-gnu > CLANG_TARGET_FLAGS_s390 := s390x-linux-gnu > CLANG_TARGET_FLAGS_x86 := x86_64-linux-gnu > +CLANG_TARGET_FLAGS_um := $(CLANG_TARGET_FLAGS_$(SUBARCH)) LGTM. I also thought of not passing --target at all for ARCH=um, but we decided to override --target all the time (for reproducibility?). Anyway, Nathan's way is clean, and looks OK to me. > CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(SRCARCH)) > > ifeq ($(CROSS_COMPILE),) > > > > CLANG_TARGET_FLAGS := $(CLANG_TARGET_FLAGS_$(SRCARCH)) > > > > > > ifeq ($(CROSS_COMPILE),) > > > -- > > > 2.30.2 > > > > > > > > > -- > > Best Regards > > Masahiro Yamada -- Best Regards Masahiro Yamada