gnunet-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Improve bswap portability


From: Schanzenbach, Martin
Subject: Re: [PATCH] Improve bswap portability
Date: Sun, 19 Sep 2021 18:11:46 +0000


> On 19. Sep 2021, at 19:41, Malte Voos <malte@malvo.org> wrote:
> 
> Hi!
> 
> Thanks for the explanation. This may be a stupid question, but why not
> just use the bswap_* definitions from the libc?

I do not know why it is/was done in this way, possibly because there are 
platforms that use gcc but not glibc.
Maybe historically for win32 support.

> In glibc's case, bswap_*
> becomes __bswap_* (which is still not a compiler builtin, but a glibc
> internal name), which in turn becomes __builtin_bswap* if the GCC is
> recent enough. [1] In bionic's case, bswap_* always becomes
> __builtin_bswap* [2] [3]. Only musl doesn't use the builtins [4]. In my
> view, we have three options here:
> 
> * Use the bswap_* definitions provided by the libc and accept that some
>  might not use compiler builtins
> * Use __builtin_bswap*, which is supported by both non-ancient GCC [5]
>  and Clang [6]
> * Keep rolling our own bswap compatibility layer to support obscure
>  compilers. In this case, I'd suggest that we check if __builtin_bswap*
>  is available, and if not, use the manual implementations we already
>  have.
> 
> I don't think sticking with __bswap* is a good idea, since it is
> basically an implementation detail of glibc and musl, not a compiler
> builtin.

I changed it to this for now: 
https://git.gnunet.org/gnunet.git/commit/?id=83c0efff026598098addfabdf72698d5d13b7b48
May break *BSDs and obscure byteswap.h.
It uses and libc/OS bytesswap.h now if present, otherwise the fallback 
implementation.

BR

> 
> -malvo
> 
> [1] 
> https://sourceware.org/git/?p=glibc.git;a=blob;f=string/byteswap.h;h=e9da7a4f68a095866966fafcaf09456910f40018;hb=HEAD
> [2] 
> https://android.googlesource.com/platform/bionic/+/master/libc/include/byteswap.h
> [3] 
> https://android.googlesource.com/platform/bionic/+/824f914/libc/include/sys/endian.h
> [4] https://git.musl-libc.org/cgit/musl/tree/include/byteswap.h
> [5] https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
> [6] 
> https://github.com/llvm/llvm-project/blob/2ca637c9769ff50e94ace3083075a97b50d147f0/clang/include/clang/Basic/Builtins.def#L514

Attachment: signature.asc
Description: Message signed with OpenPGP


reply via email to

[Prev in Thread] Current Thread [Next in Thread]