]> xenbits.xensource.com Git - unikraft/libs/newlib.git/commitdiff
include/endian.h: Remove bswap* duplicate definitions
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 18 Sep 2020 11:32:51 +0000 (14:32 +0300)
committerSimon Kuenzer <simon.kuenzer@neclab.eu>
Sun, 22 Nov 2020 00:05:19 +0000 (01:05 +0100)
Using Clang results in compilation errors regarding the `__bswapXY` and
`__builtin_bswapXY` functions. There are simultaneously a definition of
a macro `__bswapXY` and a definition of a function `__bswapXY`; GCC
doesn't complain, but Clang does.

This is happening in Unikraft because the Unikraft core libraries are
using a minimized Unikraft newlib library[4], while the Unikraft app is
using the upstream (complete) newlib library[5]. In the end there are
two `endian.h` files: one in the Unikraft newlib[6], another one in the
upstream newlib (<repo>/newlib/libc/include/machine/endian.h). The
Unikraft newlib version of `endian.h` defines `__bswapXY` as inline
functions, whereas the upstream newlib defines them as macros. This
results in an error from Clang; GCC doesn't mind, though it's an issue
having multiple definitions for the same thing (even if one is a macro
or one is a function).

This commit fixes the issue. It removes the `__bswapXY` parts from the
Unikraft version of `endian.h` and includes the upstream version of
`endian.h`.

Signed-off-by: Razvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Reviewed-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@upb.ro>
include/endian.h

index 3c8a7520a0efdd3bcbd45dd88c85fe9d7401544c..f09c3127fbc18c9025b5b06e649830622802e676 100644 (file)
@@ -27,6 +27,8 @@
 #ifndef _ENDIAN_H
 #define _ENDIAN_H
 
+#include <machine/endian.h>
+
 #define __LITTLE_ENDIAN 1234
 #define __BIG_ENDIAN 4321
 #define __PDP_ENDIAN 3412
 
 #include <stdint.h>
 
-static inline uint16_t __bswap16(uint16_t __x)
-{
-       return __x<<8 | __x>>8;
-}
-
-static inline uint32_t __bswap32(uint32_t __x)
-{
-       return __x>>24 | (__x>>8&0xff00) | (__x<<8&0xff0000) | __x<<24;
-}
-
-static inline uint64_t __bswap64(uint64_t __x)
-{
-       return (__bswap32(__x)+0ULL)<<32 | __bswap32(__x>>32);
-}
-
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 #define htobe16(x) __bswap16(x)
 #define be16toh(x) __bswap16(x)