atlas-probe: Fix compilation with gcc11
This uses some definitions from <sys/cdefs.h> in gcc 8.4.0, not present in musl or gcc11. Also use clock_gettime() instead of syscall(__NR_clock_gettime,...), which is not currently defined. Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
This commit is contained in:
parent
f263ed4449
commit
281df4bcf5
3 changed files with 188 additions and 0 deletions
|
@ -0,0 +1,74 @@
|
|||
From b83524b19ca6e5e58dded77fad37f17a177766ff Mon Sep 17 00:00:00 2001
|
||||
From: Eneas U de Queiroz <cotequeiroz@gmail.com>
|
||||
Date: Fri, 8 Oct 2021 14:39:52 -0300
|
||||
Subject: [PATCH 1/2] Avoid problems with 64-bit time_t
|
||||
|
||||
The clock_gettime() calls are being handled by calling
|
||||
syscall(__NR_clock_gettime, ...), which is not portable between systems
|
||||
using 32-bit and 64-bit time_t. This is being done to avoid having to
|
||||
link agains librt.
|
||||
|
||||
So, use the standard function, and add a test to see if we can compile
|
||||
a test without the library, including it otherwise.
|
||||
|
||||
Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
|
||||
|
||||
--- a/Makefile.flags
|
||||
+++ b/Makefile.flags
|
||||
@@ -124,6 +124,12 @@ CFLAGS += --sysroot=$(CONFIG_SYSROOT)
|
||||
export SYSROOT=$(CONFIG_SYSROOT)
|
||||
endif
|
||||
|
||||
+# glibc versions before 2.17 need to link with -rt to use clock_gettime
|
||||
+RT_NEEDED := $(shell echo -e '#include <time.h>\nint main(void){struct timespec tp; return clock_gettime(CLOCK_MONOTONIC, &tp);}' >rttest.c; $(CC) $(CFLAGS) -o /dev/null rttest.c >/dev/null 2>&1 || echo "y"; rm rttest.c)
|
||||
+ifeq ($(RT_NEEDED),y)
|
||||
+LDLIBS += rt
|
||||
+endif
|
||||
+
|
||||
# Android has no separate crypt library
|
||||
# gcc-4.2.1 fails if we try to feed C source on stdin:
|
||||
# echo 'int main(void){return 0;}' | $(CC) $(CFLAGS) -lcrypt -o /dev/null -xc -
|
||||
--- a/coreutils/date.c
|
||||
+++ b/coreutils/date.c
|
||||
@@ -37,7 +37,7 @@
|
||||
//config:config FEATURE_DATE_NANO
|
||||
//config: bool "Support %[num]N nanosecond format specifier"
|
||||
//config: default n
|
||||
-//config: depends on DATE # syscall(__NR_clock_gettime)
|
||||
+//config: depends on DATE # clock_gettime()
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: Support %[num]N format specifier. Adds ~250 bytes of code.
|
||||
@@ -265,9 +265,7 @@ int date_main(int argc UNUSED_PARAM, cha
|
||||
#endif
|
||||
} else {
|
||||
#if ENABLE_FEATURE_DATE_NANO
|
||||
- /* libc has incredibly messy way of doing this,
|
||||
- * typically requiring -lrt. We just skip all this mess */
|
||||
- syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
|
||||
+ clock_gettime(CLOCK_REALTIME, &ts);
|
||||
#else
|
||||
time(&ts.tv_sec);
|
||||
#endif
|
||||
--- a/libbb/time.c
|
||||
+++ b/libbb/time.c
|
||||
@@ -243,7 +243,7 @@ char* FAST_FUNC strftime_YYYYMMDDHHMMSS(
|
||||
* typically requiring -lrt. We just skip all this mess */
|
||||
static void get_mono(struct timespec *ts)
|
||||
{
|
||||
- if (syscall(__NR_clock_gettime, CLOCK_MONOTONIC, ts))
|
||||
+ if (clock_gettime(CLOCK_MONOTONIC, ts))
|
||||
bb_error_msg_and_die("clock_gettime(MONOTONIC) failed");
|
||||
}
|
||||
unsigned long long FAST_FUNC monotonic_ns(void)
|
||||
--- a/runit/runsv.c
|
||||
+++ b/runit/runsv.c
|
||||
@@ -55,7 +55,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAG
|
||||
* typically requiring -lrt. We just skip all this mess */
|
||||
static void gettimeofday_ns(struct timespec *ts)
|
||||
{
|
||||
- syscall(__NR_clock_gettime, CLOCK_REALTIME, ts);
|
||||
+ clock_gettime(CLOCK_REALTIME, ts);
|
||||
}
|
||||
#else
|
||||
static void gettimeofday_ns(struct timespec *ts)
|
82
net/atlas-probe/patches/003-Fix-compilation-with-gcc11.patch
Normal file
82
net/atlas-probe/patches/003-Fix-compilation-with-gcc11.patch
Normal file
|
@ -0,0 +1,82 @@
|
|||
From b6b3cdc16eaa50b40623f1589ea51dd43ebb456d Mon Sep 17 00:00:00 2001
|
||||
From: Eneas U de Queiroz <cotequeiroz@gmail.com>
|
||||
Date: Fri, 8 Oct 2021 14:47:08 -0300
|
||||
Subject: [PATCH 2/2] Fix compilation with gcc11
|
||||
|
||||
Currently, libbb.h counts on __THROW and __inline being defined. They
|
||||
are internal macros used by glibc not meant to be publicly used. This
|
||||
causes trouble, at least with a combination of gcc11 and musl, where
|
||||
nether have them defined.
|
||||
|
||||
Use definitions from <sys/cdefs.h> in gcc 8.4.0 if they're missing.
|
||||
|
||||
Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
|
||||
|
||||
--- a/include/libbb.h
|
||||
+++ b/include/libbb.h
|
||||
@@ -120,6 +120,65 @@
|
||||
#ifdef DMALLOC
|
||||
# include <dmalloc.h>
|
||||
#endif
|
||||
+
|
||||
+/* Compatibility with musl & gcc 11. Taken from <sys/cdefs.h> in gcc 8.4.0 */
|
||||
+#ifndef __THROW
|
||||
+#ifdef __GNUC__
|
||||
+
|
||||
+/* All functions, except those with callbacks or those that
|
||||
+ synchronize memory, are leaf functions. */
|
||||
+# if __GNUC_PREREQ (4, 6) && !defined _LIBC
|
||||
+# define __LEAF , __leaf__
|
||||
+# define __LEAF_ATTR __attribute__ ((__leaf__))
|
||||
+# else
|
||||
+# define __LEAF
|
||||
+# define __LEAF_ATTR
|
||||
+# endif
|
||||
+
|
||||
+/* GCC can always grok prototypes. For C++ programs we add throw()
|
||||
+ to help it optimize the function calls. But this works only with
|
||||
+ gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
|
||||
+ as non-throwing using a function attribute since programs can use
|
||||
+ the -fexceptions options for C code as well. */
|
||||
+# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
|
||||
+# define __THROW __attribute__ ((__nothrow__ __LEAF))
|
||||
+# define __THROWNL __attribute__ ((__nothrow__))
|
||||
+# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
|
||||
+# else
|
||||
+# if defined __cplusplus && __GNUC_PREREQ (2,8)
|
||||
+# define __THROW throw ()
|
||||
+# define __THROWNL throw ()
|
||||
+# define __NTH(fct) __LEAF_ATTR fct throw ()
|
||||
+# else
|
||||
+# define __THROW
|
||||
+# define __THROWNL
|
||||
+# define __NTH(fct) fct
|
||||
+# endif
|
||||
+# endif
|
||||
+
|
||||
+#else /* Not GCC. */
|
||||
+
|
||||
+# define __inline /* No inline functions. */
|
||||
+
|
||||
+# define __THROW
|
||||
+# define __THROWNL
|
||||
+# define __NTH(fct) fct
|
||||
+
|
||||
+#endif /* GCC. */
|
||||
+#endif /* __THROW */
|
||||
+
|
||||
+#ifndef __nonnull
|
||||
+/* The nonull function attribute allows to mark pointer parameters which
|
||||
+ must not be NULL. */
|
||||
+#if __GNUC_PREREQ (3,3)
|
||||
+# define __nonnull(params) __attribute__ ((__nonnull__ params))
|
||||
+#else
|
||||
+# define __nonnull(params)
|
||||
+#endif
|
||||
+#endif /* __nonnull */
|
||||
+
|
||||
+/* End of compatibility with musl & gcc 11. */
|
||||
+
|
||||
/* Just in case libc doesn't define some of these... */
|
||||
#ifndef _PATH_PASSWD
|
||||
#define _PATH_PASSWD "/etc/passwd"
|
32
net/atlas-probe/patches/004-Comment-out-librt-testing.patch
Normal file
32
net/atlas-probe/patches/004-Comment-out-librt-testing.patch
Normal file
|
@ -0,0 +1,32 @@
|
|||
From df50c29210f18f959186bb974c33cefff2bcc15e Mon Sep 17 00:00:00 2001
|
||||
From: Eneas U de Queiroz <cotequeiroz@gmail.com>
|
||||
Date: Fri, 8 Oct 2021 22:34:37 -0300
|
||||
Subject: [PATCH] Comment out librt testing
|
||||
|
||||
The packages feed Ci is apparently failing to execute the test:
|
||||
|
||||
Makefile.flags:128: *** unterminated call to function 'shell':
|
||||
missing ')'. Stop.
|
||||
|
||||
The call appears to be correct, but we already know that the library
|
||||
will not be needed for openwrt, so let's just leave it out.
|
||||
|
||||
Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
|
||||
|
||||
--- a/Makefile.flags
|
||||
+++ b/Makefile.flags
|
||||
@@ -125,10 +125,10 @@ export SYSROOT=$(CONFIG_SYSROOT)
|
||||
endif
|
||||
|
||||
# glibc versions before 2.17 need to link with -rt to use clock_gettime
|
||||
-RT_NEEDED := $(shell echo -e '#include <time.h>\nint main(void){struct timespec tp; return clock_gettime(CLOCK_MONOTONIC, &tp);}' >rttest.c; $(CC) $(CFLAGS) -o /dev/null rttest.c >/dev/null 2>&1 || echo "y"; rm rttest.c)
|
||||
-ifeq ($(RT_NEEDED),y)
|
||||
-LDLIBS += rt
|
||||
-endif
|
||||
+#RT_NEEDED := $(shell echo -e '#include <time.h>\nint main(void){struct timespec tp; return clock_gettime(CLOCK_MONOTONIC, &tp);}' >rttest.c; $(CC) $(CFLAGS) -o /dev/null rttest.c >/dev/null 2>&1 || echo "y"; rm rttest.c)
|
||||
+#ifeq ($(RT_NEEDED),y)
|
||||
+#LDLIBS += rt
|
||||
+#endif
|
||||
|
||||
# Android has no separate crypt library
|
||||
# gcc-4.2.1 fails if we try to feed C source on stdin:
|
Loading…
Reference in a new issue