From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by sourceware.org (Postfix) with ESMTPS id E30943857C52 for ; Fri, 22 Oct 2021 04:04:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E30943857C52 Received: by mail-pj1-x1033.google.com with SMTP id u6-20020a17090a3fc600b001a00250584aso4731914pjm.4 for ; Thu, 21 Oct 2021 21:04:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gnwqrYCUSeNyFNcjN+c6DK7oSWbYIVvuUpQYNQH1dAY=; b=psDR211nie6UrOPAzi4P5bSEbW+Lrtz+7Y+FlsdIoDRQ9FgTDqNoxnE0KwveMsxyJj YYny7uAtxw9OjxNyQyiWGtaOy0LA9r1dGCU8wENf5UfQYL3a3j/lEC0pU2Xh2lw60OKU BuDtKJqr52QgmQ8djW+xZpfk+7NUD9bbYvjHbK1iPy3WqAfd9zBRQd3Jkn0eMhazRuif yavOBL3pjvEDSRVXGrDsHsFzXRCdiO341KwT/zBVymJJE1lfjvO/04INIPlriRn+hVG9 PnQ92vtsUB4Q9vN/PFPaOJvtS8OObNCGhWqoipBidy/MoI9QikPrMm+XPvExjc9CGkZn Y19g== X-Gm-Message-State: AOAM530jNrpQpAb4kIitbDvGDDjIlCWVmf28aBdQ96ZP2GgaJZ9c2L4K gY/B4EnJkoQ5928ixxmnOSD2IkRkRX7KF/cpbl4= X-Google-Smtp-Source: ABdhPJzDaqcmt7956GE5PpWgFRhDW6hBvJ14pz6upX4LNVP6ZFQABRqyYVqGl5g7ItV4+96ZEs8yH7UriXbokwAFyHs= X-Received: by 2002:a17:902:7c94:b0:13b:8d10:cc4f with SMTP id y20-20020a1709027c9400b0013b8d10cc4fmr9232446pll.54.1634875484008; Thu, 21 Oct 2021 21:04:44 -0700 (PDT) MIME-Version: 1.0 References: <20210927203827.2852935-1-goldstein.w.n@gmail.com> <20211021223850.415607-1-goldstein.w.n@gmail.com> In-Reply-To: From: Noah Goldstein Date: Thu, 21 Oct 2021 23:04:33 -0500 Message-ID: Subject: Re: [PATCH v8 1/3] String: Add support for __memcmpeq() ABI on all targets To: "H.J. Lu" Cc: GNU C Library , "Carlos O'Donell" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Oct 2021 04:04:46 -0000 On Thu, Oct 21, 2021 at 9:38 PM H.J. Lu wrote: > > On Thu, Oct 21, 2021 at 4:42 PM Noah Goldstein wrote: > > > > On Thu, Oct 21, 2021 at 5:50 PM H.J. Lu wrote: > > > > > > On Thu, Oct 21, 2021 at 3:38 PM Noah Goldstein wrote: > > > > > > > > No bug. > > > > > > > > This commit adds support for __memcmpeq() as a new ABI for all > > > > targets. In this commit __memcmpeq() is implemented only as an alias > > > > to the corresponding targets memcmp() implementation. __memcmpeq() is > > > > added as a new symbol starting with GLIBC_2.35 and defined in string.h > > > > with comments explaining its behavior. Basic tests that it is callable > > > > and works where added in string/tester.c > > > > > > > > As discussed in the proposal "Add new ABI '__memcmpeq()' to libc" > > > > __memcmpeq() is essentially a reserved namespace for bcmp(). The means > > > > is shares the same specifications as memcmp() except the return value > > > > for non-equal byte sequences is any non-zero value. This is less > > > > strict than memcmp()'s return value specification and can be better > > > > optimized when a boolean return is all that is needed. > > > > > > > > __memcmpeq() is meant to only be called by compilers if they can prove > > > > that the return value of a memcmp() call is only used for its boolean > > > > value. > > > > > > > > All tests in string/tester.c passed. As well build succeeds on > > > > x86_64-linux-gnu target. > > > > --- > > > > string/Versions | 3 +++ > > > > string/memcmp.c | 2 ++ > > > > string/string.h | 16 ++++++++++++++++ > > > > string/tester.c | 16 ++++++++++++++++ > > > > sysdeps/aarch64/memcmp.S | 2 ++ > > > > sysdeps/csky/abiv2/memcmp.S | 1 + > > > > sysdeps/i386/i686/memcmp.S | 2 ++ > > > > sysdeps/i386/i686/multiarch/memcmp.c | 1 + > > > > sysdeps/i386/memcmp.S | 2 ++ > > > > sysdeps/ia64/memcmp.S | 1 + > > > > sysdeps/mach/hurd/i386/libc.abilist | 1 + > > > > sysdeps/powerpc/powerpc32/405/memcmp.S | 1 + > > > > sysdeps/powerpc/powerpc32/power4/memcmp.S | 1 + > > > > sysdeps/powerpc/powerpc32/power7/memcmp.S | 1 + > > > > sysdeps/powerpc/powerpc64/le/power10/memcmp.S | 1 + > > > > sysdeps/powerpc/powerpc64/power4/memcmp.S | 1 + > > > > sysdeps/powerpc/powerpc64/power7/memcmp.S | 1 + > > > > sysdeps/powerpc/powerpc64/power8/memcmp.S | 1 + > > > > sysdeps/s390/memcmp-z900.S | 1 + > > > > sysdeps/s390/memcmp.c | 1 + > > > > sysdeps/sparc/sparc64/memcmp.S | 2 ++ > > > > sysdeps/unix/sysv/linux/aarch64/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/alpha/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/arc/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/arm/be/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/arm/le/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/csky/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/hppa/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/i386/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/ia64/libc.abilist | 1 + > > > > .../unix/sysv/linux/m68k/coldfire/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist | 1 + > > > > .../unix/sysv/linux/microblaze/be/libc.abilist | 1 + > > > > .../unix/sysv/linux/microblaze/le/libc.abilist | 1 + > > > > .../unix/sysv/linux/mips/mips32/fpu/libc.abilist | 1 + > > > > .../sysv/linux/mips/mips32/nofpu/libc.abilist | 1 + > > > > .../unix/sysv/linux/mips/mips64/n32/libc.abilist | 1 + > > > > .../unix/sysv/linux/mips/mips64/n64/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/nios2/libc.abilist | 1 + > > > > .../linux/powerpc/powerpc32/fpu/libc.abilist | 1 + > > > > .../linux/powerpc/powerpc32/nofpu/libc.abilist | 1 + > > > > .../sysv/linux/powerpc/powerpc64/be/libc.abilist | 1 + > > > > .../sysv/linux/powerpc/powerpc64/le/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist | 1 + > > > > .../unix/sysv/linux/s390/s390-32/libc.abilist | 1 + > > > > .../unix/sysv/linux/s390/s390-64/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/sh/be/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/sh/le/libc.abilist | 1 + > > > > .../unix/sysv/linux/sparc/sparc32/libc.abilist | 1 + > > > > .../unix/sysv/linux/sparc/sparc64/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/x86_64/64/libc.abilist | 1 + > > > > sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist | 1 + > > > > sysdeps/x86_64/memcmp.S | 2 ++ > > > > sysdeps/x86_64/multiarch/memcmp.c | 2 ++ > > > > 55 files changed, 94 insertions(+) > > > > > > > > diff --git a/string/Versions b/string/Versions > > > > index 298ecd401a..864c4cf7a4 100644 > > > > --- a/string/Versions > > > > +++ b/string/Versions > > > > @@ -89,4 +89,7 @@ libc { > > > > sigdescr_np; sigabbrev_np; > > > > strerrordesc_np; strerrorname_np; > > > > } > > > > + GLIBC_2.35 { > > > > + __memcmpeq; > > > > + } > > > > } > > > > diff --git a/string/memcmp.c b/string/memcmp.c > > > > index 9b46d7a905..5020be00e0 100644 > > > > --- a/string/memcmp.c > > > > +++ b/string/memcmp.c > > > > @@ -358,4 +358,6 @@ libc_hidden_builtin_def(memcmp) > > > > #ifdef weak_alias > > > > # undef bcmp > > > > weak_alias (memcmp, bcmp) > > > > +# undef __memcmpeq > > > > +weak_alias (memcmp, __memcmpeq) > > > > #endif > > > > diff --git a/string/string.h b/string/string.h > > > > index b1b083edce..e70feeaeea 100644 > > > > --- a/string/string.h > > > > +++ b/string/string.h > > > > @@ -64,6 +64,22 @@ extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1)); > > > > extern int memcmp (const void *__s1, const void *__s2, size_t __n) > > > > __THROW __attribute_pure__ __nonnull ((1, 2)); > > > > > > > > +/* Compare N bytes of S1 and S2. Return zero if S1 and S2 are equal. > > > > + Return some non-zero value otherwise. > > > > + > > > > + Essentially __memcmpeq has the exact same semantics as memcmp > > > > + except the return value is less constrained. memcmp is always a > > > > + correct implementation of __memcmpeq. As well !!memcmp, -memcmp, > > > > + or bcmp are correct implementations. > > > > + > > > > + __memcmpeq is meant to be used by compilers when memcmp return is > > > > + only used for its bolean value. > > > > + > > > > + __memcmpeq is declared only for use by compilers. Programs should > > > > + continue to use memcmp. */ > > > > +extern int __memcmpeq (const void *__s1, const void *__s2, size_t __n) > > > > + __THROW __attribute_pure__ __nonnull ((1, 2)); > > > > + > > > > /* Search N bytes of S for C. */ > > > > #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO > > > > extern "C++" > > > > diff --git a/string/tester.c b/string/tester.c > > > > index 778160ae6e..605b3f00f9 100644 > > > > --- a/string/tester.c > > > > +++ b/string/tester.c > > > > @@ -1449,6 +1449,19 @@ test_bcmp (void) > > > > check(bcmp("abc", "def", 0) == 0, 8); /* Zero count. */ > > > > } > > > > > > > > +static void > > > > +test_memcmpeq (void) > > > > +{ > > > > + it = "__memcmpeq"; > > > > + check (__memcmpeq ("a", "a", 1) == 0, 1); /* Identity. */ > > > > + check (__memcmpeq ("abc", "abc", 3) == 0, 2); /* Multicharacter. */ > > > > + check (__memcmpeq ("abcd", "abce", 4) != 0, 3); /* Honestly unequal. */ > > > > + check (__memcmpeq ("abce", "abcd", 4) != 0, 4); > > > > + check (__memcmpeq ("alph", "beta", 4) != 0, 5); > > > > + check (__memcmpeq ("abce", "abcd", 3) == 0, 6); /* Count limited. */ > > > > + check (__memcmpeq ("abc", "def", 0) == 0, 8); /* Zero count. */ > > > > +} > > > > + > > > > static void > > > > test_strerror (void) > > > > { > > > > @@ -1611,6 +1624,9 @@ main (void) > > > > /* bcmp - somewhat like memcmp. */ > > > > test_bcmp (); > > > > > > > > + /* __memcmpeq - somewhat like memcmp. */ > > > > + test_memcmpeq (); > > > > + > > > > /* strndup. */ > > > > test_strndup (); > > > > > > > > diff --git a/sysdeps/aarch64/memcmp.S b/sysdeps/aarch64/memcmp.S > > > > index c1937f6f5c..bc932eff2a 100644 > > > > --- a/sysdeps/aarch64/memcmp.S > > > > +++ b/sysdeps/aarch64/memcmp.S > > > > @@ -177,4 +177,6 @@ L(ret_0): > > > > END (memcmp) > > > > #undef bcmp > > > > weak_alias (memcmp, bcmp) > > > > +#undef __memcmpeq > > > > +weak_alias (memcmp, __memcmpeq) > > > > > > Can we use strong_alias for __memcmpeq? > > > > Think we can but not sure if its needed or we should. > > __memcmpeq shouldn't have STB_WEAK binding since it > shouldn't be preempted. Got it. Note for x86_64 the patch defined an alias from memcmp -> memcmpeq in two places. Onces in sysdeps/x86_64/memcmp.S and once in sysdeps/x86_64/multiarch/memcmp.c. The one in memcmp.c is the one that will get the IFUNC selection so I think that's the one we want to keep but will there be an issue with ld.so usage of __memcmpeq if there is no alias in memcmp.S? Should the one in memcmp.S stay weak maybe? > > > -- > H.J.