Received: by 2002:ac0:950e:0:0:0:0:0 with SMTP id f14csp8987imc; Fri, 15 Mar 2019 15:09:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqws85WOm56u73ltv8zc6ySWeIk170aKXBevkXiZd1VqYX1X0Yq7QgxhdieegvBH+9OTKyTN X-Received: by 2002:a17:902:9a83:: with SMTP id w3mr6565382plp.137.1552687767043; Fri, 15 Mar 2019 15:09:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552687767; cv=none; d=google.com; s=arc-20160816; b=b+JKCmLT3MoJB8ATaVY4nxw4KL8w3NOosP3OSIJbo2Q/udKaCwa/SlnoVcJOXkDrnr +4cn5xhmIUz/YV8GCY8T8+ZKXSp8f1saUw/JYO0euHdUegtlz20NFV+UAd5ehgrmLhtH ffuGFxYJ+aTRAYisqhGduc+0KzvjnJBMGh8Q2aFU/dMXIsnJtPeELX9MMYGMh4Tpw8mO S7h4Yf66yNeQ03QHN6JtwdHumoYefKqTrLviZ31hqV7SSAtMYgD7GMg0RTDrGZoK/Aww lkm83rPNC4eFwTqToEIET+u4TTfdWXLWHw+Gqi2UWeA5kb4TK/Ov8h4n5meMXy+vvbiK VTjw== 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=GffhP1lzT/9QnGTLJuMoGy+pwIvjorMbN0edjXFgvwA=; b=bF7zSKSWeNmhxjcMLTln018sa2AC4EF7CHCW147K2CNNDEFkDW+4nQ2qBFuxmgyW2K 9LE2RjVJzRpfwzpj6hWLK0ZOw864aS1fKqtysobbevjtpcog9Kcewnel1kkTIwASGnEo O2pZmdZkcYoygWbWLP9fS1IETcOmr3zj0u4ZF/v84DzyF905pRardUr9V15GRjMZA5BU 0p3kpyUJMxs6RPNdXxNSbtKvG8AmPor1itJA1ehHMJcXSlsYxjkn7S5nzmeBISKVI8Ip /dFv1a05AqShdMw1gWcDCmrurfgwYm7H+cy7u19lH7kDj5zlESJiepqTaZxDJfI43Uj5 IDEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=c8LYmT80; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id m133si2810207pga.314.2019.03.15.15.09.12; Fri, 15 Mar 2019 15:09:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=c8LYmT80; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727157AbfCOWGu (ORCPT + 99 others); Fri, 15 Mar 2019 18:06:50 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34173 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726671AbfCOWGt (ORCPT ); Fri, 15 Mar 2019 18:06:49 -0400 Received: by mail-pf1-f194.google.com with SMTP id v64so7255282pfb.1 for ; Fri, 15 Mar 2019 15:06:49 -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=GffhP1lzT/9QnGTLJuMoGy+pwIvjorMbN0edjXFgvwA=; b=c8LYmT80gU9Xmy923nSLf1+9R4P9q3sb11tYHIhIidZS5nyy5pT7kF1b3lkywuaiDa OYv6DWkLBt796OBSFGOrSXg6eHo3jjZaMhZj0eNkgJWyyYi8u3bKPqIubNXtRTqFh2eQ OuF54AHrG4qo7UGYytAbF3LAgpT5zQqYlHROS615ZRvWYi/pFFlh8d5CtbY1Cm9/Dl6X 8m/gcQ5W9RZ6cVc1glkjIbept6QLA260S6ny29Z9l5d5y9ZWwY6xRZw4etUnIr2ofM8x 4tAuIS2R33OyT9zN5g2zXi6RQC9XCPe+ZHJOghAw8u2+wExUdu0f60VxbwRJSBP7xKRf MC7g== 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=GffhP1lzT/9QnGTLJuMoGy+pwIvjorMbN0edjXFgvwA=; b=jf0w4RxHA/Ji5ohWvjSPZXqy8RXUHGcukSJyTG5hG/IGCHwQZ39RIbuQUVX9hHXXfm ZoYltV8TI3Ua1N1x2T4Vh73PXQIZFNIU7A8V8aL10BUT32iFF35rapZvCd12hxiY4Of7 5+2RvhVT+Co1iF/fhShlW2ftSfpp6KJ8+7je08Cz4eiCSVO0S5Wfu7ZICydsc5rzIy8s PUL28a0s97eAsihRPufiewy7uhDz5NH8e941mK623rBBBttYOvbgdrsjgipBP65oQXLC rl2dt18AWMHZevaQWPyZJq1DkWt0ezMpJpkSzfQCf7Z7x7SIwIxlfbzCzBs87oSqyVxd g5gQ== X-Gm-Message-State: APjAAAU6gk4QRxkQXUdl5Lx2d9jB55e2a0/o+R8WQRalONp9ALN3IFaX dnkK2I/c5Vwt51AllCFpMJ3stiHvaBoyXOeQO/elqg== X-Received: by 2002:a63:5a20:: with SMTP id o32mr5372773pgb.225.1552687608418; Fri, 15 Mar 2019 15:06:48 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Nick Desaulniers Date: Fri, 15 Mar 2019 15:06:37 -0700 Message-ID: Subject: Re: [PATCH] lib: Add shared copy of __lshrti3 from libgcc To: Matthias Kaehlcke Cc: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H . Peter Anvin" , x86@kernel.org, LKML , Manoj Gupta , Tiancong Wang , Stephen Hines , clang-built-linux@googlegroups.com, Miguel Ojeda 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 Fri, Mar 15, 2019 at 1:54 PM Matthias Kaehlcke wrote: > > The compiler may emit calls to __lshrti3 from the compiler runtime > library, which results in undefined references: > > arch/x86/kvm/x86.o: In function `mul_u64_u64_shr': > include/linux/math64.h:186: undefined reference to `__lshrti3' Looks like Clang will emit this at -Oz (but not -O2): https://godbolt.org/z/w1_2YC > > Add a copy of the __lshrti3 libgcc routine (from gcc v4.9.2). Has it changed since? If so why not a newer version of libgcc_s? > > Include the function for x86 builds with clang, which is the > environment where the above error was observed. > > Signed-off-by: Matthias Kaehlcke > --- > arch/x86/Kconfig | 1 + > include/linux/libgcc.h | 16 ++++++++++++++++ > lib/Kconfig | 3 +++ > lib/Makefile | 1 + > lib/lshrti3.c | 31 +++++++++++++++++++++++++++++++ > 5 files changed, 52 insertions(+) > create mode 100644 lib/lshrti3.c > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig > index c1f9b3cf437c..a5e0d923845d 100644 > --- a/arch/x86/Kconfig > +++ b/arch/x86/Kconfig > @@ -105,6 +105,7 @@ config X86 > select GENERIC_IRQ_PROBE > select GENERIC_IRQ_RESERVATION_MODE > select GENERIC_IRQ_SHOW > + select GENERIC_LIB_LSHRTI3 if CC_IS_CLANG > select GENERIC_PENDING_IRQ if SMP > select GENERIC_SMP_IDLE_THREAD > select GENERIC_STRNCPY_FROM_USER > diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h > index 32e1e0f4b2d0..a71036471838 100644 > --- a/include/linux/libgcc.h > +++ b/include/linux/libgcc.h > @@ -22,15 +22,26 @@ > #include > > typedef int word_type __attribute__ ((mode (__word__))); > +typedef int TItype __attribute__ ((mode (TI))); Well that's an interesting new compiler attribute. https://stackoverflow.com/questions/4559025/what-does-gcc-attribute-modexx-actually-do Please use `__mode(TI)` from include/linux/compiler_attributes.h ex. typedef int TItype __mode(TI); > > #ifdef __BIG_ENDIAN > struct DWstruct { > int high, low; > }; > + > +struct DWstruct128 { > + long long high, low; > +}; > + > #elif defined(__LITTLE_ENDIAN) > struct DWstruct { > int low, high; > }; > + > +struct DWstruct128 { > + long long low, high; > +}; > + > #else > #error I feel sick. > #endif > @@ -40,4 +51,9 @@ typedef union { > long long ll; > } DWunion; > > +typedef union { > + struct DWstruct128 s; > + TItype ll; > +} DWunion128; > + > #endif /* __ASM_LIBGCC_H */ > diff --git a/lib/Kconfig b/lib/Kconfig > index a9e56539bd11..369e10259ea6 100644 > --- a/lib/Kconfig > +++ b/lib/Kconfig > @@ -624,6 +624,9 @@ config GENERIC_LIB_ASHRDI3 > config GENERIC_LIB_LSHRDI3 > bool > > +config GENERIC_LIB_LSHRTI3 > + bool > + > config GENERIC_LIB_MULDI3 > bool > > diff --git a/lib/Makefile b/lib/Makefile > index 4e066120a0d6..42648411f451 100644 > --- a/lib/Makefile > +++ b/lib/Makefile > @@ -277,6 +277,7 @@ obj-$(CONFIG_PARMAN) += parman.o > obj-$(CONFIG_GENERIC_LIB_ASHLDI3) += ashldi3.o > obj-$(CONFIG_GENERIC_LIB_ASHRDI3) += ashrdi3.o > obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o > +obj-$(CONFIG_GENERIC_LIB_LSHRTI3) += lshrti3.o > obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o > obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o > obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o > diff --git a/lib/lshrti3.c b/lib/lshrti3.c > new file mode 100644 > index 000000000000..2d2123bb3030 > --- /dev/null > +++ b/lib/lshrti3.c > @@ -0,0 +1,31 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include > +#include > + > +long long __lshrti3(long long u, word_type b) > +{ > + DWunion128 uu, w; > + word_type bm; > + > + if (b == 0) > + return u; > + > + uu.ll = u; > + bm = 64 - b; > + > + if (bm <= 0) { > + w.s.high = 0; > + w.s.low = (unsigned long long) uu.s.high >> -bm; > + } else { > + const unsigned long long carries = > + (unsigned long long) uu.s.high << bm; > + w.s.high = (unsigned long long) uu.s.high >> b; > + w.s.low = ((unsigned long long) uu.s.low >> b) | carries; > + } > + > + return w.ll; > +} > +#ifndef BUILD_VDSO > +EXPORT_SYMBOL(__lshrti3); > +#endif I don't think you want this. Maybe that was carried over from https://lkml.org/lkml/2019/3/15/669 by accident? The above linkage error mentions arch/x86/kvm/x86.o which I wouldn't expect to be linked into the VDSO image? -- Thanks, ~Nick Desaulniers