From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.6 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 122031F55A for ; Fri, 21 Feb 2020 21:00:09 +0000 (UTC) Received: from localhost ([::1]:36154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5FP5-0008PD-Hr for normalperson@yhbt.net; Fri, 21 Feb 2020 16:00:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57034) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5FOz-0008Ol-Un for bug-gnulib@gnu.org; Fri, 21 Feb 2020 16:00:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5FOx-0007D0-Us for bug-gnulib@gnu.org; Fri, 21 Feb 2020 16:00:01 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:48836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j5FOx-0007Cr-La for bug-gnulib@gnu.org; Fri, 21 Feb 2020 15:59:59 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id A8EF41600C5; Fri, 21 Feb 2020 12:59:57 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id PdcbvlLsDbDq; Fri, 21 Feb 2020 12:59:56 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 7D4671600C7; Fri, 21 Feb 2020 12:59:56 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 94kwG_Ce92zw; Fri, 21 Feb 2020 12:59:56 -0800 (PST) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 5FE911600C5; Fri, 21 Feb 2020 12:59:56 -0800 (PST) Subject: Re: Missing extern "C" in count-one-bits.h? To: Simon Marchi References: From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: <314f76bd-3892-b81d-9e7f-ea8865a5ac13@cs.ucla.edu> Date: Fri, 21 Feb 2020 12:59:55 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------65B338AA93A22578A80B202F" Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.179.128.68 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" This is a multi-part message in MIME format. --------------65B338AA93A22578A80B202F Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 2/20/20 12:15 PM, Simon Marchi wrote: > The disagreement between the symbol names between count-one-bits.o and arm-get-next-pcs.o > seems to show that there is a missing `extern "C"` in the count-one-bits.h header? Thanks, I'll take your word for it. (I don't use C++.) I installed the attached patch into Gnulib. Apparently these modules have been used by C code only, until now. > And apparently, gcc decided to compile the definition in the header and include > it in arm-get-next-pcs.o, while clang did not. Is that the compiler's choice, > or is it because the macros and preprocessor conditionals in count-one-bits.h > evaluated to something different for the two compilers? It's a compiler's choice whether a function is inlined. When I call count_one_bits in C, gcc -O2 doesn't create a function for count_one_bits in the calling module; it simply issues the popcnt insn, or calls the appropriate GCC library function on platforms that don't have a popcnt insn. Perhaps you were compiling with some other level of optimization, or perhaps C++ does this differently; but regardless of how the compiler does it the resulting code is supposed to work of course. --------------65B338AA93A22578A80B202F Content-Type: text/x-patch; charset=UTF-8; name="0001-Add-extern-C-to-count-one-bits.h-etc.patch" Content-Disposition: attachment; filename="0001-Add-extern-C-to-count-one-bits.h-etc.patch" Content-Transfer-Encoding: quoted-printable >From 50da3fa2a9fde4ff42cf20d3994c1095060b4ff7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 21 Feb 2020 12:41:33 -0800 Subject: [PATCH] =3D?UTF-8?q?Add=3D20=3DE2=3D80=3D98extern=3D20"C"=3DE2=3D= 80=3D99=3D20to=3D20cou?=3D =3D?UTF-8?q?nt-one-bits.h=3D20etc.?=3D MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit This ports these .h files to C++. Problem reported by Simon Marchi in: https://lists.gnu.org/r/bug-gnulib/2020-02/msg00110.html * lib/count-leading-zeros.h, lib/count-one-bits.h: * lib/count-trailing-zeros.h: Add =E2=80=98extern "C"=E2=80=99. --- ChangeLog | 9 +++++++++ lib/count-leading-zeros.h | 8 ++++++++ lib/count-one-bits.h | 8 ++++++++ lib/count-trailing-zeros.h | 8 ++++++++ 4 files changed, 33 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8649b9110..89beae3d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2020-02-21 Paul Eggert + + Add =E2=80=98extern "C"=E2=80=99 to count-one-bits.h etc. + This ports these .h files to C++. + Problem reported by Simon Marchi in: + https://lists.gnu.org/r/bug-gnulib/2020-02/msg00110.html + * lib/count-leading-zeros.h, lib/count-one-bits.h: + * lib/count-trailing-zeros.h: Add =E2=80=98extern "C"=E2=80=99. + 2020-02-19 Bruno Haible =20 uninorm/decompose-internal: Avoid "no previous prototype" warning. diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h index b548754e1..7e88c8cb9 100644 --- a/lib/count-leading-zeros.h +++ b/lib/count-leading-zeros.h @@ -30,6 +30,10 @@ _GL_INLINE_HEADER_BEGIN # define COUNT_LEADING_ZEROS_INLINE _GL_INLINE #endif =20 +#ifdef __cplusplus +extern "C" { +#endif + /* Assuming the GCC builtin is BUILTIN and the MSC builtin is MSC_BUILTI= N, expand to code that computes the number of leading zeros of the local variable 'x' of type TYPE (an unsigned integer type) and return it @@ -108,6 +112,10 @@ count_leading_zeros_ll (unsigned long long int x) unsigned long long int); } =20 +#ifdef __cplusplus +} +#endif + _GL_INLINE_HEADER_END =20 #endif /* COUNT_LEADING_ZEROS_H */ diff --git a/lib/count-one-bits.h b/lib/count-one-bits.h index 78770e424..eea56d859 100644 --- a/lib/count-one-bits.h +++ b/lib/count-one-bits.h @@ -30,6 +30,10 @@ _GL_INLINE_HEADER_BEGIN # define COUNT_ONE_BITS_INLINE _GL_INLINE #endif =20 +#ifdef __cplusplus +extern "C" { +#endif + /* Expand to code that computes the number of 1-bits of the local variable 'x' of type TYPE (an unsigned integer type) and return it from the current function. */ @@ -129,6 +133,10 @@ count_one_bits_ll (unsigned long long int x) COUNT_ONE_BITS (__builtin_popcountll, __popcnt64, unsigned long long i= nt); } =20 +#ifdef __cplusplus +} +#endif + _GL_INLINE_HEADER_END =20 #endif /* COUNT_ONE_BITS_H */ diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h index 2169f6262..1eb5fb919 100644 --- a/lib/count-trailing-zeros.h +++ b/lib/count-trailing-zeros.h @@ -30,6 +30,10 @@ _GL_INLINE_HEADER_BEGIN # define COUNT_TRAILING_ZEROS_INLINE _GL_INLINE #endif =20 +#ifdef __cplusplus +extern "C" { +#endif + /* Assuming the GCC builtin is BUILTIN and the MSC builtin is MSC_BUILTI= N, expand to code that computes the number of trailing zeros of the loca= l variable 'x' of type TYPE (an unsigned integer type) and return it @@ -100,6 +104,10 @@ count_trailing_zeros_ll (unsigned long long int x) unsigned long long int); } =20 +#ifdef __cplusplus +} +#endif + _GL_INLINE_HEADER_END =20 #endif --=20 2.24.1 --------------65B338AA93A22578A80B202F--