mailing list of musl libc
 help / color / mirror / code / Atom feed
* compatability: bits/syscall.h requires C99
@ 2012-08-23  5:07 idunham
  2012-08-23  6:11 ` [PATCH] Problem is static inline idunham
  2012-08-23 12:31 ` compatability: bits/syscall.h requires C99 John Spencer
  0 siblings, 2 replies; 19+ messages in thread
From: idunham @ 2012-08-23  5:07 UTC (permalink / raw)
  To: musl

I've been trying to get musl compatability patches for libuv merged
upstream, and I have it building, but there's one sticking point:
Upstream insists on using --std=c89 (I guess for portability to other
platforms).
This makes GCC choke on "long" in <bits/syscall.h>.
Per make -i, this is the only problem.

Would it be possible to eliminate this requirement?

Thanks,
Isaac Dunham




^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH] Problem is static inline
  2012-08-23  5:07 compatability: bits/syscall.h requires C99 idunham
@ 2012-08-23  6:11 ` idunham
  2012-08-23  6:20   ` [PATCH 2/1] " idunham
                     ` (2 more replies)
  2012-08-23 12:31 ` compatability: bits/syscall.h requires C99 John Spencer
  1 sibling, 3 replies; 19+ messages in thread
From: idunham @ 2012-08-23  6:11 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 526 bytes --]

> I've been trying to get musl compatability patches for libuv merged
> upstream, and I have it building, but there's one sticking point:
> Upstream insists on using --std=c89 (I guess for portability to other
> platforms).
> This makes GCC choke on "long" in <bits/syscall.h>.
I tried fixing it, and ended up finding that the issue was the "static
inline" in the header.

For future reference:
sed -e 's/static inline/#if __STDC_VERSION__ >=
199901L\ninline\n#endif\nstatic/g' -i <filename>
is what I used.

HTH,
Isaac Dunham

[-- Attachment #2: inline.diff --]
[-- Type: text/plain, Size: 11416 bytes --]

diff --git a/arch/arm/bits/syscall.h b/arch/arm/bits/syscall.h
index 9932c9e..18cbbc2 100644
--- a/arch/arm/bits/syscall.h
+++ b/arch/arm/bits/syscall.h
@@ -7,37 +7,58 @@
 
 long (__syscall)(long, ...);
 
-static inline long __syscall0(long n)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall0(long n)
 {
 	return (__syscall)(n);
 }
 
-static inline long __syscall1(long n, long a)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall1(long n, long a)
 {
 	return (__syscall)(n, a);
 }
 
-static inline long __syscall2(long n, long a, long b)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall2(long n, long a, long b)
 {
 	return (__syscall)(n, a, b);
 }
 
-static inline long __syscall3(long n, long a, long b, long c)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall3(long n, long a, long b, long c)
 {
 	return (__syscall)(n, a, b, c);
 }
 
-static inline long __syscall4(long n, long a, long b, long c, long d)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall4(long n, long a, long b, long c, long d)
 {
 	return (__syscall)(n, a, b, c, d);
 }
 
-static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall5(long n, long a, long b, long c, long d, long e)
 {
 	return (__syscall)(n, a, b, c, d, e);
 }
 
-static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall6(long n, long a, long b, long c, long d, long e, long f)
 {
 	return (__syscall)(n, a, b, c, d, e, f);
 }
diff --git a/arch/i386/bits/syscall.h b/arch/i386/bits/syscall.h
index 4b574e9..f37eca0 100644
--- a/arch/i386/bits/syscall.h
+++ b/arch/i386/bits/syscall.h
@@ -5,7 +5,10 @@
 
 #define __SYSCALL_SSLEN 8
 
-static inline long __syscall0(long __n)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall0(long __n)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n) : "memory");
@@ -14,42 +17,60 @@ static inline long __syscall0(long __n)
 
 #ifndef __PIC__
 
-static inline long __syscall1(long __n, long __a1)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1) : "memory");
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2) : "memory");
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3) : "memory");
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4) : "memory");
 	return __ret;
 }
 
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4), "D"(__a5) : "memory");
 	return __ret;
 }
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("pushl %7 ; pushl %%ebp ; mov 4(%%esp),%%ebp ; int $128 ; popl %%ebp ; popl %%ecx"
@@ -59,7 +80,10 @@ static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __
 
 #else
 
-static inline long __syscall1(long __n, long __a1)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -67,7 +91,10 @@ static inline long __syscall1(long __n, long __a1)
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -75,7 +102,10 @@ static inline long __syscall2(long __n, long __a1, long __a2)
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -83,7 +113,10 @@ static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -92,7 +125,10 @@ static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __
 }
 
 #if 0
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("pushl %2 ; pushl %%ebx ; mov 4(%%esp),%%ebx ; int $128 ; popl %%ebx ; popl %%ecx"
@@ -100,13 +136,19 @@ static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 #else
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5);
 }
 #endif
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5, __a6);
 }
diff --git a/arch/mips/bits/syscall.h b/arch/mips/bits/syscall.h
index 6c51bab..418630b 100644
--- a/arch/mips/bits/syscall.h
+++ b/arch/mips/bits/syscall.h
@@ -7,37 +7,58 @@
 
 long (__syscall)(long, ...);
 
-static inline long __syscall0(long n)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall0(long n)
 {
 	return (__syscall)(n);
 }
 
-static inline long __syscall1(long n, long a)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall1(long n, long a)
 {
 	return (__syscall)(n, a);
 }
 
-static inline long __syscall2(long n, long a, long b)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall2(long n, long a, long b)
 {
 	return (__syscall)(n, a, b);
 }
 
-static inline long __syscall3(long n, long a, long b, long c)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall3(long n, long a, long b, long c)
 {
 	return (__syscall)(n, a, b, c);
 }
 
-static inline long __syscall4(long n, long a, long b, long c, long d)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall4(long n, long a, long b, long c, long d)
 {
 	return (__syscall)(n, a, b, c, d);
 }
 
-static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall5(long n, long a, long b, long c, long d, long e)
 {
 	return (__syscall)(n, a, b, c, d, e);
 }
 
-static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall6(long n, long a, long b, long c, long d, long e, long f)
 {
 	return (__syscall)(n, a, b, c, d, e, f);
 }
diff --git a/arch/x86_64/bits/syscall.h b/arch/x86_64/bits/syscall.h
index 567cfcb..9f58d6f 100644
--- a/arch/x86_64/bits/syscall.h
+++ b/arch/x86_64/bits/syscall.h
@@ -3,21 +3,30 @@
 
 #define __SYSCALL_SSLEN 8
 
-static inline long __syscall0(long __n)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall0(long __n)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n) : "rcx", "r11", "memory");
 	return __ret;
 }
 
-static inline long __syscall1(long __n, long __a1)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1) : "rcx", "r11", "memory");
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2)
@@ -25,7 +34,10 @@ static inline long __syscall2(long __n, long __a1, long __a2)
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2),
@@ -33,7 +45,10 @@ static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;
@@ -42,7 +57,10 @@ static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;
@@ -52,7 +70,10 @@ static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 2/1] Problem is static inline
  2012-08-23  6:11 ` [PATCH] Problem is static inline idunham
@ 2012-08-23  6:20   ` idunham
  2012-08-23  6:43     ` Szabolcs Nagy
  2012-08-23  6:51   ` [PATCH] " Szabolcs Nagy
  2012-08-23 12:18   ` Rich Felker
  2 siblings, 1 reply; 19+ messages in thread
From: idunham @ 2012-08-23  6:20 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 681 bytes --]

>> I've been trying to get musl compatability patches for libuv merged
>> upstream, and I have it building, but there's one sticking point:
>> Upstream insists on using --std=c89 (I guess for portability to other
>> platforms).
>> This makes GCC choke on "long" in <bits/syscall.h>.
> I tried fixing it, and ended up finding that the issue was the "static
> inline" in the header.
>
> For future reference:
> sed -e 's/static inline/#if __STDC_VERSION__ >=
> 199901L\ninline\n#endif\nstatic/g' -i <filename>
> is what I used.
>
> HTH,
> Isaac Dunham

I grepped and found that there were three other headers in each arch that
shared the same problem.
Here's the patch.

Isaac Dunham

[-- Attachment #2: inline2.diff --]
[-- Type: text/plain, Size: 21362 bytes --]

diff --git a/arch/arm/atomic.h b/arch/arm/atomic.h
index f434a0c..2312aca 100644
--- a/arch/arm/atomic.h
+++ b/arch/arm/atomic.h
@@ -3,7 +3,10 @@
 
 #include <stdint.h>
 
-static inline int a_ctz_l(unsigned long x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_ctz_l(unsigned long x)
 {
 	static const char debruijn32[32] = {
 		0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
@@ -12,7 +15,10 @@ static inline int a_ctz_l(unsigned long x)
 	return debruijn32[(x&-x)*0x076be629 >> 27];
 }
 
-static inline int a_ctz_64(uint64_t x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_ctz_64(uint64_t x)
 {
 	uint32_t y = x;
 	if (!y) {
@@ -22,7 +28,10 @@ static inline int a_ctz_64(uint64_t x)
 	return a_ctz_l(y);
 }
 
-static inline int a_cas(volatile int *p, int t, int s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_cas(volatile int *p, int t, int s)
 {
 	int old;
 	for (;;) {
@@ -33,17 +42,26 @@ static inline int a_cas(volatile int *p, int t, int s)
 	}
 }
 
-static inline void *a_cas_p(volatile void *p, void *t, void *s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void *a_cas_p(volatile void *p, void *t, void *s)
 {
 	return (void *)a_cas(p, (int)t, (int)s);
 }
 
-static inline long a_cas_l(volatile void *p, long t, long s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long a_cas_l(volatile void *p, long t, long s)
 {
 	return a_cas(p, t, s);
 }
 
-static inline int a_swap(volatile int *x, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_swap(volatile int *x, int v)
 {
 	int old;
 	do old = *x;
@@ -51,7 +69,10 @@ static inline int a_swap(volatile int *x, int v)
 	return old;
 }
 
-static inline int a_fetch_add(volatile int *x, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_fetch_add(volatile int *x, int v)
 {
 	int old;
 	do old = *x;
@@ -59,52 +80,79 @@ static inline int a_fetch_add(volatile int *x, int v)
 	return old;
 }
 
-static inline void a_inc(volatile int *x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_inc(volatile int *x)
 {
 	a_fetch_add(x, 1);
 }
 
-static inline void a_dec(volatile int *x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_dec(volatile int *x)
 {
 	a_fetch_add(x, -1);
 }
 
-static inline void a_store(volatile int *p, int x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_store(volatile int *p, int x)
 {
 	*p=x;
 }
 
-static inline void a_spin()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_spin()
 {
 }
 
-static inline void a_crash()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_crash()
 {
 	*(volatile char *)0=0;
 }
 
-static inline void a_and(volatile int *p, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_and(volatile int *p, int v)
 {
 	int old;
 	do old = *p;
 	while (a_cas(p, old, old&v) != old);
 }
 
-static inline void a_or(volatile int *p, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_or(volatile int *p, int v)
 {
 	int old;
 	do old = *p;
 	while (a_cas(p, old, old|v) != old);
 }
 
-static inline void a_and_64(volatile uint64_t *p, uint64_t v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_and_64(volatile uint64_t *p, uint64_t v)
 {
 	union { uint64_t v; uint32_t r[2]; } u = { v };
 	a_and((int *)p, u.r[0]);
 	a_and((int *)p+1, u.r[1]);
 }
 
-static inline void a_or_64(volatile uint64_t *p, uint64_t v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_or_64(volatile uint64_t *p, uint64_t v)
 {
 	union { uint64_t v; uint32_t r[2]; } u = { v };
 	a_or((int *)p, u.r[0]);
diff --git a/arch/arm/reloc.h b/arch/arm/reloc.h
index 10e89aa..9c79a75 100644
--- a/arch/arm/reloc.h
+++ b/arch/arm/reloc.h
@@ -6,7 +6,10 @@
 #define IS_COPY(x) ((x)==R_ARM_COPY)
 #define IS_PLT(x) ((x)==R_ARM_JUMP_SLOT)
 
-static inline void do_single_reloc(size_t *reloc_addr, int type, size_t sym_val, size_t sym_size, unsigned char *base_addr, size_t addend)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void do_single_reloc(size_t *reloc_addr, int type, size_t sym_val, size_t sym_size, unsigned char *base_addr, size_t addend)
 {
 	switch(type) {
 	case R_ARM_ABS32:
diff --git a/arch/i386/atomic.h b/arch/i386/atomic.h
index 77b0b3b..7588b79 100644
--- a/arch/i386/atomic.h
+++ b/arch/i386/atomic.h
@@ -3,7 +3,10 @@
 
 #include <stdint.h>
 
-static inline int a_ctz_64(uint64_t x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_ctz_64(uint64_t x)
 {
 	int r;
 	__asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; addl $32,%0\n1:"
@@ -11,81 +14,120 @@ static inline int a_ctz_64(uint64_t x)
 	return r;
 }
 
-static inline int a_ctz_l(unsigned long x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_ctz_l(unsigned long x)
 {
 	long r;
 	__asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
 	return r;
 }
 
-static inline void a_and_64(volatile uint64_t *p, uint64_t v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_and_64(volatile uint64_t *p, uint64_t v)
 {
 	__asm__( "lock ; andl %1, (%0) ; lock ; andl %2, 4(%0)"
 		: : "r"((long *)p), "r"((unsigned)v), "r"((unsigned)(v>>32)) : "memory" );
 }
 
-static inline void a_or_64(volatile uint64_t *p, uint64_t v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_or_64(volatile uint64_t *p, uint64_t v)
 {
 	__asm__( "lock ; orl %1, (%0) ; lock ; orl %2, 4(%0)"
 		: : "r"((long *)p), "r"((unsigned)v), "r"((unsigned)(v>>32)) : "memory" );
 }
 
-static inline void a_store_l(volatile void *p, long x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_store_l(volatile void *p, long x)
 {
 	__asm__( "movl %1, %0" : "=m"(*(long *)p) : "r"(x) : "memory" );
 }
 
-static inline void a_or_l(volatile void *p, long v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_or_l(volatile void *p, long v)
 {
 	__asm__( "lock ; orl %1, %0"
 		: "=m"(*(long *)p) : "r"(v) : "memory" );
 }
 
-static inline void *a_cas_p(volatile void *p, void *t, void *s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void *a_cas_p(volatile void *p, void *t, void *s)
 {
 	__asm__( "lock ; cmpxchg %3, %1"
 		: "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
 	return t;
 }
 
-static inline long a_cas_l(volatile void *p, long t, long s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long a_cas_l(volatile void *p, long t, long s)
 {
 	__asm__( "lock ; cmpxchg %3, %1"
 		: "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
 	return t;
 }
 
-static inline int a_cas(volatile int *p, int t, int s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_cas(volatile int *p, int t, int s)
 {
 	__asm__( "lock ; cmpxchg %3, %1"
 		: "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
 	return t;
 }
 
-static inline void *a_swap_p(void *volatile *x, void *v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void *a_swap_p(void *volatile *x, void *v)
 {
 	__asm__( "xchg %0, %1" : "=r"(v), "=m"(*(void **)x) : "0"(v) : "memory" );
 	return v;
 }
-static inline long a_swap_l(volatile void *x, long v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long a_swap_l(volatile void *x, long v)
 {
 	__asm__( "xchg %0, %1" : "=r"(v), "=m"(*(long *)x) : "0"(v) : "memory" );
 	return v;
 }
 
-static inline void a_or(volatile void *p, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_or(volatile void *p, int v)
 {
 	__asm__( "lock ; orl %1, %0"
 		: "=m"(*(int *)p) : "r"(v) : "memory" );
 }
 
-static inline void a_and(volatile void *p, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_and(volatile void *p, int v)
 {
 	__asm__( "lock ; andl %1, %0"
 		: "=m"(*(int *)p) : "r"(v) : "memory" );
 }
 
-static inline int a_swap(volatile int *x, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_swap(volatile int *x, int v)
 {
 	__asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
 	return v;
@@ -93,33 +135,51 @@ static inline int a_swap(volatile int *x, int v)
 
 #define a_xchg a_swap
 
-static inline int a_fetch_add(volatile int *x, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_fetch_add(volatile int *x, int v)
 {
 	__asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
 	return v;
 }
 
-static inline void a_inc(volatile int *x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_inc(volatile int *x)
 {
 	__asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
 }
 
-static inline void a_dec(volatile int *x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_dec(volatile int *x)
 {
 	__asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
 }
 
-static inline void a_store(volatile int *p, int x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_store(volatile int *p, int x)
 {
 	__asm__( "movl %1, %0" : "=m"(*p) : "r"(x) : "memory" );
 }
 
-static inline void a_spin()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_spin()
 {
 	__asm__ __volatile__( "pause" : : : "memory" );
 }
 
-static inline void a_crash()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_crash()
 {
 	__asm__ __volatile__( "hlt" : : : "memory" );
 }
diff --git a/arch/i386/pthread_arch.h b/arch/i386/pthread_arch.h
index 0ea0aac..86568e8 100644
--- a/arch/i386/pthread_arch.h
+++ b/arch/i386/pthread_arch.h
@@ -1,4 +1,7 @@
-static inline struct pthread *__pthread_self()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static struct pthread *__pthread_self()
 {
 	struct pthread *self;
 	__asm__ __volatile__ ("movl %%gs:0,%0" : "=r" (self) );
diff --git a/arch/i386/reloc.h b/arch/i386/reloc.h
index 490113a..aacfd82 100644
--- a/arch/i386/reloc.h
+++ b/arch/i386/reloc.h
@@ -6,7 +6,10 @@
 #define IS_COPY(x) ((x)==R_386_COPY)
 #define IS_PLT(x) ((x)==R_386_JMP_SLOT)
 
-static inline void do_single_reloc(size_t *reloc_addr, int type, size_t sym_val, size_t sym_size, unsigned char *base_addr, size_t addend)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void do_single_reloc(size_t *reloc_addr, int type, size_t sym_val, size_t sym_size, unsigned char *base_addr, size_t addend)
 {
 	switch(type) {
 	case R_386_32:
diff --git a/arch/mips/atomic.h b/arch/mips/atomic.h
index f3478ef..e8db4c1 100644
--- a/arch/mips/atomic.h
+++ b/arch/mips/atomic.h
@@ -3,7 +3,10 @@
 
 #include <stdint.h>
 
-static inline int a_ctz_l(unsigned long x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_ctz_l(unsigned long x)
 {
 	static const char debruijn32[32] = {
 		0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
@@ -12,7 +15,10 @@ static inline int a_ctz_l(unsigned long x)
 	return debruijn32[(x&-x)*0x076be629 >> 27];
 }
 
-static inline int a_ctz_64(uint64_t x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_ctz_64(uint64_t x)
 {
 	uint32_t y = x;
 	if (!y) {
@@ -22,7 +28,10 @@ static inline int a_ctz_64(uint64_t x)
 	return a_ctz_l(y);
 }
 
-static inline int a_cas(volatile int *p, int t, int s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_cas(volatile int *p, int t, int s)
 {
 	int dummy;
 	__asm__ __volatile__(
@@ -41,18 +50,27 @@ static inline int a_cas(volatile int *p, int t, int s)
         return t;
 }
 
-static inline void *a_cas_p(volatile void *p, void *t, void *s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void *a_cas_p(volatile void *p, void *t, void *s)
 {
 	return (void *)a_cas(p, (int)t, (int)s);
 }
 
-static inline long a_cas_l(volatile void *p, long t, long s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long a_cas_l(volatile void *p, long t, long s)
 {
 	return a_cas(p, t, s);
 }
 
 
-static inline int a_swap(volatile int *x, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_swap(volatile int *x, int v)
 {
 	int old, dummy;
 	__asm__ __volatile__(
@@ -70,7 +88,10 @@ static inline int a_swap(volatile int *x, int v)
         return old;
 }
 
-static inline int a_fetch_add(volatile int *x, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_fetch_add(volatile int *x, int v)
 {
 	int old, dummy;
 	__asm__ __volatile__(
@@ -88,7 +109,10 @@ static inline int a_fetch_add(volatile int *x, int v)
         return old;
 }
 
-static inline void a_inc(volatile int *x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_inc(volatile int *x)
 {
 	int dummy;
 	__asm__ __volatile__(
@@ -105,7 +129,10 @@ static inline void a_inc(volatile int *x)
 		: "=&r"(dummy) : "r"(x) : "memory" );
 }
 
-static inline void a_dec(volatile int *x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_dec(volatile int *x)
 {
 	int dummy;
 	__asm__ __volatile__(
@@ -122,7 +149,10 @@ static inline void a_dec(volatile int *x)
 		: "=&r"(dummy) : "r"(x) : "memory" );
 }
 
-static inline void a_store(volatile int *p, int x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_store(volatile int *p, int x)
 {
 	int dummy;
 	__asm__ __volatile__(
@@ -139,16 +169,25 @@ static inline void a_store(volatile int *p, int x)
 		: "=&r"(dummy) : "r"(p), "r"(x) : "memory" );
 }
 
-static inline void a_spin()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_spin()
 {
 }
 
-static inline void a_crash()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_crash()
 {
 	*(volatile char *)0=0;
 }
 
-static inline void a_and(volatile int *p, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_and(volatile int *p, int v)
 {
 	int dummy;
 	__asm__ __volatile__(
@@ -165,7 +204,10 @@ static inline void a_and(volatile int *p, int v)
 		: "=&r"(dummy) : "r"(p), "r"(v) : "memory" );
 }
 
-static inline void a_or(volatile int *p, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_or(volatile int *p, int v)
 {
 	int dummy;
 	__asm__ __volatile__(
@@ -182,14 +224,20 @@ static inline void a_or(volatile int *p, int v)
 		: "=&r"(dummy) : "r"(p), "r"(v) : "memory" );
 }
 
-static inline void a_and_64(volatile uint64_t *p, uint64_t v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_and_64(volatile uint64_t *p, uint64_t v)
 {
 	union { uint64_t v; uint32_t r[2]; } u = { v };
 	a_and((int *)p, u.r[0]);
 	a_and((int *)p+1, u.r[1]);
 }
 
-static inline void a_or_64(volatile uint64_t *p, uint64_t v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_or_64(volatile uint64_t *p, uint64_t v)
 {
 	union { uint64_t v; uint32_t r[2]; } u = { v };
 	a_or((int *)p, u.r[0]);
diff --git a/arch/mips/pthread_arch.h b/arch/mips/pthread_arch.h
index f75379c..204c217 100644
--- a/arch/mips/pthread_arch.h
+++ b/arch/mips/pthread_arch.h
@@ -1,4 +1,7 @@
-static inline struct pthread *__pthread_self()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static struct pthread *__pthread_self()
 {
 	struct pthread *self;
 	__asm__ __volatile__ (".word 0x7c03e83b" : "=v" (self) );
diff --git a/arch/mips/reloc.h b/arch/mips/reloc.h
index e892526..d748416 100644
--- a/arch/mips/reloc.h
+++ b/arch/mips/reloc.h
@@ -6,7 +6,10 @@
 #define IS_COPY(x) ((x)==R_MIPS_COPY)
 #define IS_PLT(x) 1
 
-static inline void do_single_reloc(size_t *reloc_addr, int type, size_t sym_val, size_t sym_size, unsigned char *base_addr, size_t addend)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void do_single_reloc(size_t *reloc_addr, int type, size_t sym_val, size_t sym_size, unsigned char *base_addr, size_t addend)
 {
 	switch(type) {
 	case R_MIPS_JUMP_SLOT:
diff --git a/arch/x86_64/atomic.h b/arch/x86_64/atomic.h
index 0d3da6f..1d9d9f9 100644
--- a/arch/x86_64/atomic.h
+++ b/arch/x86_64/atomic.h
@@ -3,88 +3,130 @@
 
 #include <stdint.h>
 
-static inline int a_ctz_64(uint64_t x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_ctz_64(uint64_t x)
 {
 	long r;
 	__asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
 	return r;
 }
 
-static inline int a_ctz_l(unsigned long x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_ctz_l(unsigned long x)
 {
 	long r;
 	__asm__( "bsf %1,%0" : "=r"(r) : "r"(x) );
 	return r;
 }
 
-static inline void a_and_64(volatile uint64_t *p, uint64_t v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_and_64(volatile uint64_t *p, uint64_t v)
 {
 	__asm__( "lock ; andq %1, %0"
 			 : "=m"(*(long *)p) : "r"(v) : "memory" );
 }
 
-static inline void a_or_64(volatile uint64_t *p, uint64_t v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_or_64(volatile uint64_t *p, uint64_t v)
 {
 	__asm__( "lock ; orq %1, %0"
 			 : "=m"(*(long *)p) : "r"(v) : "memory" );
 }
 
-static inline void a_store_l(volatile void *p, long x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_store_l(volatile void *p, long x)
 {
 	__asm__( "movq %1, %0" : "=m"(*(long *)p) : "r"(x) : "memory" );
 }
 
-static inline void a_or_l(volatile void *p, long v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_or_l(volatile void *p, long v)
 {
 	__asm__( "lock ; orq %1, %0"
 		: "=m"(*(long *)p) : "r"(v) : "memory" );
 }
 
-static inline void *a_cas_p(volatile void *p, void *t, void *s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void *a_cas_p(volatile void *p, void *t, void *s)
 {
 	__asm__( "lock ; cmpxchg %3, %1"
 		: "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
 	return t;
 }
 
-static inline long a_cas_l(volatile void *p, long t, long s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long a_cas_l(volatile void *p, long t, long s)
 {
 	__asm__( "lock ; cmpxchg %3, %1"
 		: "=a"(t), "=m"(*(long *)p) : "a"(t), "r"(s) : "memory" );
 	return t;
 }
 
-static inline int a_cas(volatile int *p, int t, int s)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_cas(volatile int *p, int t, int s)
 {
 	__asm__( "lock ; cmpxchgl %3, %1"
 		: "=a"(t), "=m"(*p) : "a"(t), "r"(s) : "memory" );
 	return t;
 }
 
-static inline void *a_swap_p(void *volatile *x, void *v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void *a_swap_p(void *volatile *x, void *v)
 {
 	__asm__( "xchg %0, %1" : "=r"(v), "=m"(*(void **)x) : "0"(v) : "memory" );
 	return v;
 }
-static inline long a_swap_l(volatile void *x, long v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static long a_swap_l(volatile void *x, long v)
 {
 	__asm__( "xchg %0, %1" : "=r"(v), "=m"(*(long *)x) : "0"(v) : "memory" );
 	return v;
 }
 
-static inline void a_or(volatile void *p, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_or(volatile void *p, int v)
 {
 	__asm__( "lock ; orl %1, %0"
 		: "=m"(*(int *)p) : "r"(v) : "memory" );
 }
 
-static inline void a_and(volatile void *p, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_and(volatile void *p, int v)
 {
 	__asm__( "lock ; andl %1, %0"
 		: "=m"(*(int *)p) : "r"(v) : "memory" );
 }
 
-static inline int a_swap(volatile int *x, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_swap(volatile int *x, int v)
 {
 	__asm__( "xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
 	return v;
@@ -92,33 +134,51 @@ static inline int a_swap(volatile int *x, int v)
 
 #define a_xchg a_swap
 
-static inline int a_fetch_add(volatile int *x, int v)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static int a_fetch_add(volatile int *x, int v)
 {
 	__asm__( "lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory" );
 	return v;
 }
 
-static inline void a_inc(volatile int *x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_inc(volatile int *x)
 {
 	__asm__( "lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory" );
 }
 
-static inline void a_dec(volatile int *x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_dec(volatile int *x)
 {
 	__asm__( "lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory" );
 }
 
-static inline void a_store(volatile int *p, int x)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_store(volatile int *p, int x)
 {
 	__asm__( "movl %1, %0" : "=m"(*p) : "r"(x) : "memory" );
 }
 
-static inline void a_spin()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_spin()
 {
 	__asm__ __volatile__( "pause" : : : "memory" );
 }
 
-static inline void a_crash()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void a_crash()
 {
 	__asm__ __volatile__( "hlt" : : : "memory" );
 }
diff --git a/arch/x86_64/pthread_arch.h b/arch/x86_64/pthread_arch.h
index 836187f..83d1447 100644
--- a/arch/x86_64/pthread_arch.h
+++ b/arch/x86_64/pthread_arch.h
@@ -1,4 +1,7 @@
-static inline struct pthread *__pthread_self()
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static struct pthread *__pthread_self()
 {
 	struct pthread *self;
 	__asm__ __volatile__ ("movq %%fs:0,%0" : "=r" (self) );
diff --git a/arch/x86_64/reloc.h b/arch/x86_64/reloc.h
index b0bbfb3..8825fcd 100644
--- a/arch/x86_64/reloc.h
+++ b/arch/x86_64/reloc.h
@@ -7,7 +7,10 @@
 #define IS_COPY(x) ((x)==R_X86_64_COPY)
 #define IS_PLT(x) ((x)==R_X86_64_JUMP_SLOT)
 
-static inline void do_single_reloc(size_t *reloc_addr, int type, size_t sym_val, size_t sym_size, unsigned char *base_addr, size_t addend)
+#if __STDC_VERSION__ >= 199901L
+inline
+#endif
+static void do_single_reloc(size_t *reloc_addr, int type, size_t sym_val, size_t sym_size, unsigned char *base_addr, size_t addend)
 {
 	switch(type) {
 	case R_X86_64_GLOB_DAT:

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/1] Problem is static inline
  2012-08-23  6:20   ` [PATCH 2/1] " idunham
@ 2012-08-23  6:43     ` Szabolcs Nagy
  0 siblings, 0 replies; 19+ messages in thread
From: Szabolcs Nagy @ 2012-08-23  6:43 UTC (permalink / raw)
  To: musl

* idunham@lavabit.com <idunham@lavabit.com> [2012-08-22 23:20:22 -0700]:
> I grepped and found that there were three other headers in each arch that
> shared the same problem.
> Here's the patch.

> diff --git a/arch/arm/atomic.h b/arch/arm/atomic.h
...

these are all internal headers

musl code itself is not supposed to be compiled
with a c89 compiler


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Problem is static inline
  2012-08-23  6:11 ` [PATCH] Problem is static inline idunham
  2012-08-23  6:20   ` [PATCH 2/1] " idunham
@ 2012-08-23  6:51   ` Szabolcs Nagy
  2012-08-23 12:18   ` Rich Felker
  2 siblings, 0 replies; 19+ messages in thread
From: Szabolcs Nagy @ 2012-08-23  6:51 UTC (permalink / raw)
  To: musl

* idunham@lavabit.com <idunham@lavabit.com> [2012-08-22 23:11:38 -0700]:
> > I've been trying to get musl compatability patches for libuv merged
> > upstream, and I have it building, but there's one sticking point:
> > Upstream insists on using --std=c89 (I guess for portability to other
> > platforms).
> > This makes GCC choke on "long" in <bits/syscall.h>.
> I tried fixing it, and ended up finding that the issue was the "static
> inline" in the header.
> 

note that there are other c99isms in header files

eg any header that references a 64 bit int type
will pull in long long which is not c89

and in math.h a compound literal is used to
manipulate floatingpoint representation

these can be worked around with some ifdefs
if strict ansi c support is needed..


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH] Problem is static inline
  2012-08-23  6:11 ` [PATCH] Problem is static inline idunham
  2012-08-23  6:20   ` [PATCH 2/1] " idunham
  2012-08-23  6:51   ` [PATCH] " Szabolcs Nagy
@ 2012-08-23 12:18   ` Rich Felker
  2 siblings, 0 replies; 19+ messages in thread
From: Rich Felker @ 2012-08-23 12:18 UTC (permalink / raw)
  To: musl

On Wed, Aug 22, 2012 at 11:11:38PM -0700, idunham@lavabit.com wrote:
> > I've been trying to get musl compatability patches for libuv merged
> > upstream, and I have it building, but there's one sticking point:
> > Upstream insists on using --std=c89 (I guess for portability to other
> > platforms).
> > This makes GCC choke on "long" in <bits/syscall.h>.
> I tried fixing it, and ended up finding that the issue was the "static
> inline" in the header.
> 
> For future reference:
> sed -e 's/static inline/#if __STDC_VERSION__ >=
> 199901L\ninline\n#endif\nstatic/g' -i <filename>
> is what I used.

I really dislike this type of fix because it potentially generates
much worse code on compilers where c89 is the default but not strictly
enforced (e.g. gnu89 is the default). (While inline is usually ignored
for inlining purposes, lots of gcc versions seem to avoid eliminating
dead static functions from the .o file unless they're also marked
inline.)

Is there an easy way to detect gcc's obnoxious strict c89 mode?

By the way, I also wonder if it wouldn't be easier to do:

#if [strict c89 mode]
#define inline
#endif

or

#if [strict c89 mode]
#define inline __inline
#endif

in headers that will use it, rather than repeating the #if over and
over for each use.

We're going to need something like this for adding restrict at a later
time, anyway...

Perhaps (but I also find this really ugly...) it would be better to
do it the other way around: use __inline in the headers, and do

#if __STDC_VERSION__ >= 199901L
#define __inline inline
#endif

This would support any C99 compiler that does not need __inline for
its own purposes separate from inline, as well as any compiler in
legacy mode that has __inline as an extension.

Rich


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: compatability: bits/syscall.h requires C99
  2012-08-23  5:07 compatability: bits/syscall.h requires C99 idunham
  2012-08-23  6:11 ` [PATCH] Problem is static inline idunham
@ 2012-08-23 12:31 ` John Spencer
  2012-08-23 12:34   ` Rich Felker
  1 sibling, 1 reply; 19+ messages in thread
From: John Spencer @ 2012-08-23 12:31 UTC (permalink / raw)
  To: musl

On 08/23/2012 07:07 AM, idunham@lavabit.com wrote:
> I've been trying to get musl compatability patches for libuv merged
> upstream, and I have it building, but there's one sticking point:
> Upstream insists on using --std=c89

insisting on c89 sounds really stupid.

(and your musl patch is very ugly, if not entirely pointless)

do you have a link to the original discussion on the upstream maillist?


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: compatability: bits/syscall.h requires C99
  2012-08-23 12:31 ` compatability: bits/syscall.h requires C99 John Spencer
@ 2012-08-23 12:34   ` Rich Felker
  2012-08-24  0:25     ` Isaac Dunham
  0 siblings, 1 reply; 19+ messages in thread
From: Rich Felker @ 2012-08-23 12:34 UTC (permalink / raw)
  To: musl

On Thu, Aug 23, 2012 at 02:31:48PM +0200, John Spencer wrote:
> On 08/23/2012 07:07 AM, idunham@lavabit.com wrote:
> >I've been trying to get musl compatability patches for libuv merged
> >upstream, and I have it building, but there's one sticking point:
> >Upstream insists on using --std=c89
> 
> insisting on c89 sounds really stupid.

Agreed. This does not improve compatibility; it breaks compatibility,
especially if they happen to #include any third-party library header
which is not _documented_ as being c89 compatible. (Even if it happens
to work with -std=c89 now, unless it's documented that it does and
always will, this might change in a future version.)

> (and your musl patch is very ugly, if not entirely pointless)

I had some potential ideas for other ways to do this. Anyway the
discussion is not entirely pointless since we need to address
"restrict" at some point too, and the mechanisms for doing so will be
similar (but worse, since "restrict" is not a keyword by default in
most compilers without -std=c99, unlike "inline" which works unless
you intentionally enable strict-mode)...

Rich


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: compatability: bits/syscall.h requires C99
  2012-08-23 12:34   ` Rich Felker
@ 2012-08-24  0:25     ` Isaac Dunham
  2012-08-24  2:07       ` Rich Felker
  0 siblings, 1 reply; 19+ messages in thread
From: Isaac Dunham @ 2012-08-24  0:25 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 2360 bytes --]

On Thu, 23 Aug 2012 08:34:53 -0400
Rich Felker <dalias@aerifal.cx> wrote:

> On Thu, Aug 23, 2012 at 02:31:48PM +0200, John Spencer wrote:
> > On 08/23/2012 07:07 AM, idunham@lavabit.com wrote:
> > >Upstream insists on using --std=c89
> > insisting on c89 sounds really stupid.
> 
> Agreed. This does not improve compatibility; it breaks compatibility,
> especially if they happen to #include any third-party library header
> which is not _documented_ as being c89 compatible. (Even if it happens
> to work with -std=c89 now, unless it's documented that it does and
> always will, this might change in a future version.)

1- Per grep, they don't use third-party headers.

2- I believe the point is prevent breaking C89 platforms, by making
non-C89 code FTBFS anywhere. Since they build-test every pull request
automatically, there's little chance of non-C89 code getting merged.

This will work unless a libc breaks C89 compatability in its headers,
and musl is the only libc yet that does this.
(If you're providing the only case where C89 is broken, it's rather
hard to argue that a musl-specific workaround is inappropriate...
time to get a flamesuit on)

> > (and your musl patch is very ugly, if not entirely pointless)
just following the advice I was given on IRC re: <bits/io.h> !
> I had some potential ideas for other ways to do this. Anyway the
> discussion is not entirely pointless since we need to address
> "restrict" at some point too, and the mechanisms for doing so will be
> similar (but worse, since "restrict" is not a keyword by default in
> most compilers without -std=c99, unlike "inline" which works unless
> you intentionally enable strict-mode)...

macros available in different modes 
(courtesy of gcc -E -dM - < /dev/null ):
std=c89,c99:
__STRICT_ANSI__ 1
std=c89, gnu89
__GNUC_GNU_INLINE__ 1
std=c99,gnu99:
__GNUC_STDC_INLINE__ 1
__STDC_VERSION__ 199901L

So putting ~ this at the top of the header should work
(not verbatim, just the general concept!):
#if !(__STDC_VERSION__ >= 199901L) && __STRICT_ANSI__
#define inline __inline
#define restrict /* fallback for C89 compilers */
#endif

OTOH, s/inline/__inline/g is probably better/more universal, since
__inline is supported on some alternate compilers.


Here's a patch that will make the latter change to
arch/*/bits/syscall.h; I've left arch/*/*.h alone.

HTH,
Isaac Dunham

[-- Attachment #2: inline.diff --]
[-- Type: text/x-patch, Size: 10004 bytes --]

diff --git a/arch/arm/bits/syscall.h b/arch/arm/bits/syscall.h
index 9932c9e..c5e25b7 100644
--- a/arch/arm/bits/syscall.h
+++ b/arch/arm/bits/syscall.h
@@ -7,37 +7,37 @@
 
 long (__syscall)(long, ...);
 
-static inline long __syscall0(long n)
+static __inline long __syscall0(long n)
 {
 	return (__syscall)(n);
 }
 
-static inline long __syscall1(long n, long a)
+static __inline long __syscall1(long n, long a)
 {
 	return (__syscall)(n, a);
 }
 
-static inline long __syscall2(long n, long a, long b)
+static __inline long __syscall2(long n, long a, long b)
 {
 	return (__syscall)(n, a, b);
 }
 
-static inline long __syscall3(long n, long a, long b, long c)
+static __inline long __syscall3(long n, long a, long b, long c)
 {
 	return (__syscall)(n, a, b, c);
 }
 
-static inline long __syscall4(long n, long a, long b, long c, long d)
+static __inline long __syscall4(long n, long a, long b, long c, long d)
 {
 	return (__syscall)(n, a, b, c, d);
 }
 
-static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+static __inline long __syscall5(long n, long a, long b, long c, long d, long e)
 {
 	return (__syscall)(n, a, b, c, d, e);
 }
 
-static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
+static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
 {
 	return (__syscall)(n, a, b, c, d, e, f);
 }
diff --git a/arch/i386/bits/syscall.h b/arch/i386/bits/syscall.h
index 4b574e9..77c7f11 100644
--- a/arch/i386/bits/syscall.h
+++ b/arch/i386/bits/syscall.h
@@ -5,7 +5,7 @@
 
 #define __SYSCALL_SSLEN 8
 
-static inline long __syscall0(long __n)
+static __inline long __syscall0(long __n)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n) : "memory");
@@ -14,42 +14,42 @@ static inline long __syscall0(long __n)
 
 #ifndef __PIC__
 
-static inline long __syscall1(long __n, long __a1)
+static __inline long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1) : "memory");
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+static __inline long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2) : "memory");
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+static __inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3) : "memory");
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4) : "memory");
 	return __ret;
 }
 
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4), "D"(__a5) : "memory");
 	return __ret;
 }
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("pushl %7 ; pushl %%ebp ; mov 4(%%esp),%%ebp ; int $128 ; popl %%ebp ; popl %%ecx"
@@ -59,7 +59,7 @@ static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __
 
 #else
 
-static inline long __syscall1(long __n, long __a1)
+static __inline long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -67,7 +67,7 @@ static inline long __syscall1(long __n, long __a1)
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+static __inline long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -75,7 +75,7 @@ static inline long __syscall2(long __n, long __a1, long __a2)
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+static __inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -83,7 +83,7 @@ static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -92,7 +92,7 @@ static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __
 }
 
 #if 0
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("pushl %2 ; pushl %%ebx ; mov 4(%%esp),%%ebx ; int $128 ; popl %%ebx ; popl %%ecx"
@@ -100,13 +100,13 @@ static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 #else
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5);
 }
 #endif
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5, __a6);
 }
diff --git a/arch/mips/bits/syscall.h b/arch/mips/bits/syscall.h
index 6c51bab..9a2de2e 100644
--- a/arch/mips/bits/syscall.h
+++ b/arch/mips/bits/syscall.h
@@ -7,37 +7,37 @@
 
 long (__syscall)(long, ...);
 
-static inline long __syscall0(long n)
+static __inline long __syscall0(long n)
 {
 	return (__syscall)(n);
 }
 
-static inline long __syscall1(long n, long a)
+static __inline long __syscall1(long n, long a)
 {
 	return (__syscall)(n, a);
 }
 
-static inline long __syscall2(long n, long a, long b)
+static __inline long __syscall2(long n, long a, long b)
 {
 	return (__syscall)(n, a, b);
 }
 
-static inline long __syscall3(long n, long a, long b, long c)
+static __inline long __syscall3(long n, long a, long b, long c)
 {
 	return (__syscall)(n, a, b, c);
 }
 
-static inline long __syscall4(long n, long a, long b, long c, long d)
+static __inline long __syscall4(long n, long a, long b, long c, long d)
 {
 	return (__syscall)(n, a, b, c, d);
 }
 
-static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+static __inline long __syscall5(long n, long a, long b, long c, long d, long e)
 {
 	return (__syscall)(n, a, b, c, d, e);
 }
 
-static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
+static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
 {
 	return (__syscall)(n, a, b, c, d, e, f);
 }
diff --git a/arch/x86_64/bits/syscall.h b/arch/x86_64/bits/syscall.h
index 567cfcb..217515f 100644
--- a/arch/x86_64/bits/syscall.h
+++ b/arch/x86_64/bits/syscall.h
@@ -3,21 +3,21 @@
 
 #define __SYSCALL_SSLEN 8
 
-static inline long __syscall0(long __n)
+static __inline long __syscall0(long __n)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n) : "rcx", "r11", "memory");
 	return __ret;
 }
 
-static inline long __syscall1(long __n, long __a1)
+static __inline long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1) : "rcx", "r11", "memory");
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+static __inline long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2)
@@ -25,7 +25,7 @@ static inline long __syscall2(long __n, long __a1, long __a2)
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+static __inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2),
@@ -33,7 +33,7 @@ static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;
@@ -42,7 +42,7 @@ static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;
@@ -52,7 +52,7 @@ static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: compatability: bits/syscall.h requires C99
  2012-08-24  0:25     ` Isaac Dunham
@ 2012-08-24  2:07       ` Rich Felker
  2012-08-24  2:34         ` Rich Felker
  0 siblings, 1 reply; 19+ messages in thread
From: Rich Felker @ 2012-08-24  2:07 UTC (permalink / raw)
  To: musl

On Thu, Aug 23, 2012 at 05:25:19PM -0700, Isaac Dunham wrote:
> On Thu, 23 Aug 2012 08:34:53 -0400
> Rich Felker <dalias@aerifal.cx> wrote:
> 
> > On Thu, Aug 23, 2012 at 02:31:48PM +0200, John Spencer wrote:
> > > On 08/23/2012 07:07 AM, idunham@lavabit.com wrote:
> > > >Upstream insists on using --std=c89
> > > insisting on c89 sounds really stupid.
> > 
> > Agreed. This does not improve compatibility; it breaks compatibility,
> > especially if they happen to #include any third-party library header
> > which is not _documented_ as being c89 compatible. (Even if it happens
> > to work with -std=c89 now, unless it's documented that it does and
> > always will, this might change in a future version.)
> 
> 1- Per grep, they don't use third-party headers.
> 
> 2- I believe the point is prevent breaking C89 platforms, by making
> non-C89 code FTBFS anywhere. Since they build-test every pull request
> automatically, there's little chance of non-C89 code getting merged.

I still think this is really bad policy, akin to the bad policy in GNU
binutils of putting -Werror in their CFLAGS. You never know when
strict/pedantic/Werror/etc. type options will raise an issue on end
user systems that causes the build to break. Strict options should
only be turned on in their test environment, not in the default
configuration shipped to users.

> macros available in different modes 
> (courtesy of gcc -E -dM - < /dev/null ):

Thanks!

> So putting ~ this at the top of the header should work
> (not verbatim, just the general concept!):
> #if !(__STDC_VERSION__ >= 199901L) && __STRICT_ANSI__
> #define inline __inline
> #define restrict /* fallback for C89 compilers */
> #endif

This won't work for restrict. Unlike inline, restrict is not
recognized even in non-strict mode unless __STDC_VERSION__ is >=C99.

> OTOH, s/inline/__inline/g is probably better/more universal, since
> __inline is supported on some alternate compilers.

No, that reduces musl's public interface from portable C99 to
compiler-specific crap.

Rich


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: compatability: bits/syscall.h requires C99
  2012-08-24  2:07       ` Rich Felker
@ 2012-08-24  2:34         ` Rich Felker
  2012-08-24  3:31           ` [PATCH/RFC] __inline for C89 compilers (take 3?) Isaac Dunham
  2012-08-24  7:53           ` compatability: bits/syscall.h requires C99 Szabolcs Nagy
  0 siblings, 2 replies; 19+ messages in thread
From: Rich Felker @ 2012-08-24  2:34 UTC (permalink / raw)
  To: musl

On Thu, Aug 23, 2012 at 10:07:49PM -0400, Rich Felker wrote:
> > OTOH, s/inline/__inline/g is probably better/more universal, since
> > __inline is supported on some alternate compilers.
> 
> No, that reduces musl's public interface from portable C99 to
> compiler-specific crap.

OK, after discussion on IRC, the 2 options under consideration are:

#if __STDC_VERSION__ < 199901L && defined(__GNUC__)
#define inline __inline
#define restrict __restrict
#elif __STDC_VERSION__ < 199901L
#define inline
#define restrict
#endif

and

#if __STDC_VERSION__ >= 199901L
#define __inline inline
#define __restrict restrict
#endif

added near the top of headers that need to use inline and/or restrict.

The former version has the benefit that the "inline" and "restrict"
keywords can be used as-is later in the header, without any __
uglification. The latter version has the benefit that it's fewer lines
of spam, does not explicitly refer to "GNU C", and that it does not
break the gratuitously-C99-incompatible C89 programs like

int main(int inline, char **restrict) { }

I'm not sure if this last issue really matters; certainly there are
plenty unfixable ways C89 programs can fail on a C99 implementation,
like:

assert(strtod("0x1",0)==0);

I'm kind of leaning towards the latter but I'd like to hear some
opinions before a final change is made. Whichever way we decide, I
think it'll make it possible to go and retrofit "restrict" everwhere
it belongs in the headers, which will in turn lead to better code in
some parts of musl.

Rich


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH/RFC] __inline for C89 compilers (take 3?)
  2012-08-24  2:34         ` Rich Felker
@ 2012-08-24  3:31           ` Isaac Dunham
  2012-08-24  7:53           ` compatability: bits/syscall.h requires C99 Szabolcs Nagy
  1 sibling, 0 replies; 19+ messages in thread
From: Isaac Dunham @ 2012-08-24  3:31 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1005 bytes --]

On Thu, 23 Aug 2012 22:34:25 -0400
Rich Felker <dalias@aerifal.cx> wrote:

> On Thu, Aug 23, 2012 at 10:07:49PM -0400, Rich Felker wrote:
> #if __STDC_VERSION__ < 199901L && defined(__GNUC__)
> #define inline __inline
> #define restrict __restrict
> #elif __STDC_VERSION__ < 199901L
> #define inline
> #define restrict
> #endif

> #if __STDC_VERSION__ >= 199901L
> #define __inline inline
> #define __restrict restrict
> #endif
> 
> added near the top of headers that need to use inline and/or restrict.
> 
> The former version has the benefit that the "inline" and "restrict"
> keywords can be used as-is later in the header, without any __
> uglification. The latter version has the benefit that it's fewer lines
> of spam, does not explicitly refer to "GNU C", and 
..
This patch takes the second approach.
It will clean up include/{math,byteswap,endian}.h, and make syscall.h
somewhat more portable.

As far as I could tell, restrict is not used in any of these headers.

Please comment.

Isaac Dunham

[-- Attachment #2: inline.diff --]
[-- Type: text/x-patch, Size: 13314 bytes --]

diff --git a/arch/arm/bits/syscall.h b/arch/arm/bits/syscall.h
index 9932c9e..1c9f436 100644
--- a/arch/arm/bits/syscall.h
+++ b/arch/arm/bits/syscall.h
@@ -1,3 +1,7 @@
+#if (__STDC_VERSION__ >= 199901L)
+#define __inline inline
+#endif
+
 #define __SYSCALL_LL_E(x) \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
@@ -7,37 +11,37 @@
 
 long (__syscall)(long, ...);
 
-static inline long __syscall0(long n)
+static __inline long __syscall0(long n)
 {
 	return (__syscall)(n);
 }
 
-static inline long __syscall1(long n, long a)
+static __inline long __syscall1(long n, long a)
 {
 	return (__syscall)(n, a);
 }
 
-static inline long __syscall2(long n, long a, long b)
+static __inline long __syscall2(long n, long a, long b)
 {
 	return (__syscall)(n, a, b);
 }
 
-static inline long __syscall3(long n, long a, long b, long c)
+static __inline long __syscall3(long n, long a, long b, long c)
 {
 	return (__syscall)(n, a, b, c);
 }
 
-static inline long __syscall4(long n, long a, long b, long c, long d)
+static __inline long __syscall4(long n, long a, long b, long c, long d)
 {
 	return (__syscall)(n, a, b, c, d);
 }
 
-static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+static __inline long __syscall5(long n, long a, long b, long c, long d, long e)
 {
 	return (__syscall)(n, a, b, c, d, e);
 }
 
-static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
+static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
 {
 	return (__syscall)(n, a, b, c, d, e, f);
 }
diff --git a/arch/i386/bits/syscall.h b/arch/i386/bits/syscall.h
index 4b574e9..12e0da2 100644
--- a/arch/i386/bits/syscall.h
+++ b/arch/i386/bits/syscall.h
@@ -1,3 +1,7 @@
+#if (__STDC_VERSION__ >= 199901L)
+#define __inline inline
+#endif
+
 #define __SYSCALL_LL_E(x) \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
@@ -5,7 +9,7 @@
 
 #define __SYSCALL_SSLEN 8
 
-static inline long __syscall0(long __n)
+static __inline long __syscall0(long __n)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n) : "memory");
@@ -14,42 +18,42 @@ static inline long __syscall0(long __n)
 
 #ifndef __PIC__
 
-static inline long __syscall1(long __n, long __a1)
+static __inline long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1) : "memory");
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+static __inline long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2) : "memory");
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+static __inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3) : "memory");
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4) : "memory");
 	return __ret;
 }
 
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4), "D"(__a5) : "memory");
 	return __ret;
 }
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("pushl %7 ; pushl %%ebp ; mov 4(%%esp),%%ebp ; int $128 ; popl %%ebp ; popl %%ecx"
@@ -59,7 +63,7 @@ static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __
 
 #else
 
-static inline long __syscall1(long __n, long __a1)
+static __inline long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -67,7 +71,7 @@ static inline long __syscall1(long __n, long __a1)
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+static __inline long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -75,7 +79,7 @@ static inline long __syscall2(long __n, long __a1, long __a2)
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+static __inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -83,7 +87,7 @@ static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -92,7 +96,7 @@ static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __
 }
 
 #if 0
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("pushl %2 ; pushl %%ebx ; mov 4(%%esp),%%ebx ; int $128 ; popl %%ebx ; popl %%ecx"
@@ -100,13 +104,13 @@ static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 #else
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5);
 }
 #endif
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5, __a6);
 }
diff --git a/arch/mips/bits/syscall.h b/arch/mips/bits/syscall.h
index 6c51bab..f5e2e39 100644
--- a/arch/mips/bits/syscall.h
+++ b/arch/mips/bits/syscall.h
@@ -1,3 +1,7 @@
+#if (__STDC_VERSION__ >= 199901L)
+#define __inline inline
+#endif
+
 #define __SYSCALL_LL_E(x) \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
@@ -7,37 +11,37 @@
 
 long (__syscall)(long, ...);
 
-static inline long __syscall0(long n)
+static __inline long __syscall0(long n)
 {
 	return (__syscall)(n);
 }
 
-static inline long __syscall1(long n, long a)
+static __inline long __syscall1(long n, long a)
 {
 	return (__syscall)(n, a);
 }
 
-static inline long __syscall2(long n, long a, long b)
+static __inline long __syscall2(long n, long a, long b)
 {
 	return (__syscall)(n, a, b);
 }
 
-static inline long __syscall3(long n, long a, long b, long c)
+static __inline long __syscall3(long n, long a, long b, long c)
 {
 	return (__syscall)(n, a, b, c);
 }
 
-static inline long __syscall4(long n, long a, long b, long c, long d)
+static __inline long __syscall4(long n, long a, long b, long c, long d)
 {
 	return (__syscall)(n, a, b, c, d);
 }
 
-static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+static __inline long __syscall5(long n, long a, long b, long c, long d, long e)
 {
 	return (__syscall)(n, a, b, c, d, e);
 }
 
-static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
+static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
 {
 	return (__syscall)(n, a, b, c, d, e, f);
 }
diff --git a/arch/x86_64/bits/syscall.h b/arch/x86_64/bits/syscall.h
index 567cfcb..e69d386 100644
--- a/arch/x86_64/bits/syscall.h
+++ b/arch/x86_64/bits/syscall.h
@@ -1,23 +1,27 @@
+#if (__STDC_VERSION__ >= 199901L)
+#define __inline inline
+#endif
+
 #define __SYSCALL_LL_E(x) (x)
 #define __SYSCALL_LL_O(x) (x)
 
 #define __SYSCALL_SSLEN 8
 
-static inline long __syscall0(long __n)
+static __inline long __syscall0(long __n)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n) : "rcx", "r11", "memory");
 	return __ret;
 }
 
-static inline long __syscall1(long __n, long __a1)
+static __inline long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1) : "rcx", "r11", "memory");
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+static __inline long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2)
@@ -25,7 +29,7 @@ static inline long __syscall2(long __n, long __a1, long __a2)
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+static __inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2),
@@ -33,7 +37,7 @@ static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;
@@ -42,7 +46,7 @@ static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;
@@ -52,7 +56,7 @@ static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;
diff --git a/include/byteswap.h b/include/byteswap.h
index 8689cd5..a20e9d0 100644
--- a/include/byteswap.h
+++ b/include/byteswap.h
@@ -3,26 +3,21 @@
 
 #include <stdint.h>
 
-#if __STDC_VERSION__ >= 199901L
-inline
+#if (__STDC_VERSION__ >= 199901L)
+#define __inline inline
 #endif
-static uint16_t __bswap_16(uint16_t __x)
+
+__inline static uint16_t __bswap_16(uint16_t __x)
 {
 	return __x<<8 | __x>>8;
 }
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static uint32_t __bswap_32(uint32_t __x)
+__inline static uint32_t __bswap_32(uint32_t __x)
 {
 	return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;
 }
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static uint64_t __bswap_64(uint64_t __x)
+__inline static uint64_t __bswap_64(uint64_t __x)
 {
 	return __bswap_32(__x)+0ULL<<32 | __bswap_32(__x>>32);
 }
diff --git a/include/endian.h b/include/endian.h
index 41ca171..f92e0ee 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -1,6 +1,10 @@
 #ifndef _ENDIAN_H
 #define _ENDIAN_H
 
+#if (__STDC_VERSION__ >= 199901L)
+#define __inline inline
+#endif
+
 #define __LITTLE_ENDIAN 1234
 #define __BIG_ENDIAN 4321
 #define __PDP_ENDIAN 3412
@@ -20,26 +24,17 @@
 
 #include <stdint.h>
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static uint16_t __bswap16(uint16_t __x)
+__inline static uint16_t __bswap16(uint16_t __x)
 {
 	return __x<<8 | __x>>8;
 }
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static uint32_t __bswap32(uint32_t __x)
+__inline static uint32_t __bswap32(uint32_t __x)
 {
 	return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;
 }
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static uint64_t __bswap64(uint64_t __x)
+__inline static uint64_t __bswap64(uint64_t __x)
 {
 	return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32);
 }
diff --git a/include/math.h b/include/math.h
index 2fdcb7b..2d10979 100644
--- a/include/math.h
+++ b/include/math.h
@@ -5,6 +5,10 @@
 extern "C" {
 #endif
 
+#if (__STDC_VERSION__ >= 199901L)
+#define __inline inline
+#endif
+
 #define __NEED_float_t
 #define __NEED_double_t
 #define __NEED___uint16_t
@@ -83,10 +87,7 @@ int __signbitl(long double);
 
 #define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y)))
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static int __isrel(long double __x, long double __y, int __rel)
+__inline static int __isrel(long double __x, long double __y, int __rel)
 {
 	if (isunordered(__x, __y)) return 0;
 	if (__rel==-2) return __x < __y;

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: compatability: bits/syscall.h requires C99
  2012-08-24  2:34         ` Rich Felker
  2012-08-24  3:31           ` [PATCH/RFC] __inline for C89 compilers (take 3?) Isaac Dunham
@ 2012-08-24  7:53           ` Szabolcs Nagy
  2012-08-30 22:45             ` [PATCH/RFC] inline cleanup/C89 support Isaac Dunham
  1 sibling, 1 reply; 19+ messages in thread
From: Szabolcs Nagy @ 2012-08-24  7:53 UTC (permalink / raw)
  To: musl

* Rich Felker <dalias@aerifal.cx> [2012-08-23 22:34:25 -0400]:
> OK, after discussion on IRC, the 2 options under consideration are:
> 
> #if __STDC_VERSION__ < 199901L && defined(__GNUC__)
> #define inline __inline
> #define restrict __restrict
> #elif __STDC_VERSION__ < 199901L
> #define inline
> #define restrict
> #endif
> 
> and
> 
> #if __STDC_VERSION__ >= 199901L
> #define __inline inline
> #define __restrict restrict
> #endif
> 
> added near the top of headers that need to use inline and/or restrict.

this won't work with c++, nor old strict c compilers
without __inline and __restrict and can break various
c parsing tools (ctags, swig, various lints, ..)

i'd use

#ifdef __cplusplus
#define __inline inline
#define __restrict
#elif __STDC_VERSION__ >= 199901L
#define __inline inline
#define __restrict restrict
#elif !defined(__GNUC__)
#define __inline
#define __restrict
#endif

so any standard c99 compiler will get the inline/restrict
(tcc, pcc, gcc -std=c99, clang -std=c99) and any gnu c
compiler will get __inline/__restrict (gcc, clang)
but other tools won't see anything



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH/RFC] inline cleanup/C89 support
  2012-08-24  7:53           ` compatability: bits/syscall.h requires C99 Szabolcs Nagy
@ 2012-08-30 22:45             ` Isaac Dunham
  2012-08-31  8:34               ` Szabolcs Nagy
  2012-09-02 16:51               ` Rich Felker
  0 siblings, 2 replies; 19+ messages in thread
From: Isaac Dunham @ 2012-08-30 22:45 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1451 bytes --]

On Fri, 24 Aug 2012 09:53:16 +0200
Szabolcs Nagy <nsz@port70.net> wrote:

> * Rich Felker <dalias@aerifal.cx> [2012-08-23 22:34:25 -0400]:
..
> > #if __STDC_VERSION__ >= 199901L
> > #define __inline inline
> > #define __restrict restrict
> > #endif
> > 
> > added near the top of headers that need to use inline and/or
> > restrict.
(As previously stated, it appears-per a grep of glibc-that restrict is
not needed in these headers.) 
This patch is updated for C++:

#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
#define __inline inline
#endif

> this won't work with c++, nor old strict c compilers
> without __inline and __restrict and can break various
> c parsing tools (ctags, swig, various lints, ..)

1. Do any of these "old strict c compilers" exist on Linux? Are any of
them worth supporting? 
The Linux compilers I'm aware of are all nominally C99 capable (pcc,
tcc, gcc, clang, llvm-gcc, icc, OpenWatcom...), support __inline
(gcc-compatibles), or are hopelessly incomplete/outdated and buggy
(TenDRA, dev86 bcc). The latter ones probably wouldn't work properly
with musl, period.

2. Have you tested those C parsing tools? Have they been updated to
support C99?

3. Would OpenWatcom + musl be usable? Last I knew, OpenWatcom wasn't
compatible with the standard Linux ABI, and ISTR it had to use its own
libc.
If it is a realistic combination (can produce a working hello world),
then it *might* be worth supporting.

Isaac Dunham

[-- Attachment #2: inline.diff --]
[-- Type: text/x-patch, Size: 13468 bytes --]

diff --git a/arch/arm/bits/syscall.h b/arch/arm/bits/syscall.h
index 9932c9e..b84db9b 100644
--- a/arch/arm/bits/syscall.h
+++ b/arch/arm/bits/syscall.h
@@ -1,3 +1,7 @@
+#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
+#define __inline inline
+#endif
+
 #define __SYSCALL_LL_E(x) \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
@@ -7,37 +11,37 @@
 
 long (__syscall)(long, ...);
 
-static inline long __syscall0(long n)
+static __inline long __syscall0(long n)
 {
 	return (__syscall)(n);
 }
 
-static inline long __syscall1(long n, long a)
+static __inline long __syscall1(long n, long a)
 {
 	return (__syscall)(n, a);
 }
 
-static inline long __syscall2(long n, long a, long b)
+static __inline long __syscall2(long n, long a, long b)
 {
 	return (__syscall)(n, a, b);
 }
 
-static inline long __syscall3(long n, long a, long b, long c)
+static __inline long __syscall3(long n, long a, long b, long c)
 {
 	return (__syscall)(n, a, b, c);
 }
 
-static inline long __syscall4(long n, long a, long b, long c, long d)
+static __inline long __syscall4(long n, long a, long b, long c, long d)
 {
 	return (__syscall)(n, a, b, c, d);
 }
 
-static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+static __inline long __syscall5(long n, long a, long b, long c, long d, long e)
 {
 	return (__syscall)(n, a, b, c, d, e);
 }
 
-static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
+static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
 {
 	return (__syscall)(n, a, b, c, d, e, f);
 }
diff --git a/arch/i386/bits/syscall.h b/arch/i386/bits/syscall.h
index 4b574e9..b9335b3 100644
--- a/arch/i386/bits/syscall.h
+++ b/arch/i386/bits/syscall.h
@@ -1,3 +1,7 @@
+#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
+#define __inline inline
+#endif
+
 #define __SYSCALL_LL_E(x) \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
@@ -5,7 +9,7 @@
 
 #define __SYSCALL_SSLEN 8
 
-static inline long __syscall0(long __n)
+static __inline long __syscall0(long __n)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n) : "memory");
@@ -14,42 +18,42 @@ static inline long __syscall0(long __n)
 
 #ifndef __PIC__
 
-static inline long __syscall1(long __n, long __a1)
+static __inline long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1) : "memory");
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+static __inline long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2) : "memory");
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+static __inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3) : "memory");
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4) : "memory");
 	return __ret;
 }
 
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("int $128" : "=a"(__ret) : "a"(__n), "b"(__a1), "c"(__a2), "d"(__a3), "S"(__a4), "D"(__a5) : "memory");
 	return __ret;
 }
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("pushl %7 ; pushl %%ebp ; mov 4(%%esp),%%ebp ; int $128 ; popl %%ebp ; popl %%ecx"
@@ -59,7 +63,7 @@ static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __
 
 #else
 
-static inline long __syscall1(long __n, long __a1)
+static __inline long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -67,7 +71,7 @@ static inline long __syscall1(long __n, long __a1)
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+static __inline long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -75,7 +79,7 @@ static inline long __syscall2(long __n, long __a1, long __a2)
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+static __inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -83,7 +87,7 @@ static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("xchg %2,%%ebx ; int $128 ; xchg %2,%%ebx"
@@ -92,7 +96,7 @@ static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __
 }
 
 #if 0
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("pushl %2 ; pushl %%ebx ; mov 4(%%esp),%%ebx ; int $128 ; popl %%ebx ; popl %%ecx"
@@ -100,13 +104,13 @@ static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 #else
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5);
 }
 #endif
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	return (__syscall)(__n, __a1, __a2, __a3, __a4, __a5, __a6);
 }
diff --git a/arch/mips/bits/syscall.h b/arch/mips/bits/syscall.h
index 6c51bab..795f432 100644
--- a/arch/mips/bits/syscall.h
+++ b/arch/mips/bits/syscall.h
@@ -1,3 +1,7 @@
+#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
+#define __inline inline
+#endif
+
 #define __SYSCALL_LL_E(x) \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[0], \
 ((union { long long ll; long l[2]; }){ .ll = x }).l[1]
@@ -7,37 +11,37 @@
 
 long (__syscall)(long, ...);
 
-static inline long __syscall0(long n)
+static __inline long __syscall0(long n)
 {
 	return (__syscall)(n);
 }
 
-static inline long __syscall1(long n, long a)
+static __inline long __syscall1(long n, long a)
 {
 	return (__syscall)(n, a);
 }
 
-static inline long __syscall2(long n, long a, long b)
+static __inline long __syscall2(long n, long a, long b)
 {
 	return (__syscall)(n, a, b);
 }
 
-static inline long __syscall3(long n, long a, long b, long c)
+static __inline long __syscall3(long n, long a, long b, long c)
 {
 	return (__syscall)(n, a, b, c);
 }
 
-static inline long __syscall4(long n, long a, long b, long c, long d)
+static __inline long __syscall4(long n, long a, long b, long c, long d)
 {
 	return (__syscall)(n, a, b, c, d);
 }
 
-static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+static __inline long __syscall5(long n, long a, long b, long c, long d, long e)
 {
 	return (__syscall)(n, a, b, c, d, e);
 }
 
-static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
+static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f)
 {
 	return (__syscall)(n, a, b, c, d, e, f);
 }
diff --git a/arch/x86_64/bits/syscall.h b/arch/x86_64/bits/syscall.h
index 567cfcb..e19efb9 100644
--- a/arch/x86_64/bits/syscall.h
+++ b/arch/x86_64/bits/syscall.h
@@ -1,23 +1,27 @@
+#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
+#define __inline inline
+#endif
+
 #define __SYSCALL_LL_E(x) (x)
 #define __SYSCALL_LL_O(x) (x)
 
 #define __SYSCALL_SSLEN 8
 
-static inline long __syscall0(long __n)
+static __inline long __syscall0(long __n)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n) : "rcx", "r11", "memory");
 	return __ret;
 }
 
-static inline long __syscall1(long __n, long __a1)
+static __inline long __syscall1(long __n, long __a1)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1) : "rcx", "r11", "memory");
 	return __ret;
 }
 
-static inline long __syscall2(long __n, long __a1, long __a2)
+static __inline long __syscall2(long __n, long __a1, long __a2)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2)
@@ -25,7 +29,7 @@ static inline long __syscall2(long __n, long __a1, long __a2)
 	return __ret;
 }
 
-static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
+static __inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 {
 	unsigned long __ret;
 	__asm__ __volatile__ ("syscall" : "=a"(__ret) : "a"(__n), "D"(__a1), "S"(__a2),
@@ -33,7 +37,7 @@ static inline long __syscall3(long __n, long __a1, long __a2, long __a3)
 	return __ret;
 }
 
-static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
+static __inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __a4)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;
@@ -42,7 +46,7 @@ static inline long __syscall4(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 
-static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
+static __inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __a4, long __a5)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;
@@ -52,7 +56,7 @@ static inline long __syscall5(long __n, long __a1, long __a2, long __a3, long __
 	return __ret;
 }
 
-static inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
+static __inline long __syscall6(long __n, long __a1, long __a2, long __a3, long __a4, long __a5, long __a6)
 {
 	unsigned long __ret;
 	register long __r10 __asm__("r10") = __a4;
diff --git a/include/byteswap.h b/include/byteswap.h
index 8689cd5..347ceb4 100644
--- a/include/byteswap.h
+++ b/include/byteswap.h
@@ -3,26 +3,21 @@
 
 #include <stdint.h>
 
-#if __STDC_VERSION__ >= 199901L
-inline
+#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
+#define __inline inline
 #endif
-static uint16_t __bswap_16(uint16_t __x)
+
+__inline static uint16_t __bswap_16(uint16_t __x)
 {
 	return __x<<8 | __x>>8;
 }
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static uint32_t __bswap_32(uint32_t __x)
+__inline static uint32_t __bswap_32(uint32_t __x)
 {
 	return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;
 }
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static uint64_t __bswap_64(uint64_t __x)
+__inline static uint64_t __bswap_64(uint64_t __x)
 {
 	return __bswap_32(__x)+0ULL<<32 | __bswap_32(__x>>32);
 }
diff --git a/include/endian.h b/include/endian.h
index 41ca171..0f68b1f 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -1,6 +1,10 @@
 #ifndef _ENDIAN_H
 #define _ENDIAN_H
 
+#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
+#define __inline inline
+#endif
+
 #define __LITTLE_ENDIAN 1234
 #define __BIG_ENDIAN 4321
 #define __PDP_ENDIAN 3412
@@ -20,26 +24,17 @@
 
 #include <stdint.h>
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static uint16_t __bswap16(uint16_t __x)
+__inline static uint16_t __bswap16(uint16_t __x)
 {
 	return __x<<8 | __x>>8;
 }
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static uint32_t __bswap32(uint32_t __x)
+__inline static uint32_t __bswap32(uint32_t __x)
 {
 	return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24;
 }
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static uint64_t __bswap64(uint64_t __x)
+__inline static uint64_t __bswap64(uint64_t __x)
 {
 	return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32);
 }
diff --git a/include/math.h b/include/math.h
index 2fdcb7b..f752a35 100644
--- a/include/math.h
+++ b/include/math.h
@@ -5,6 +5,10 @@
 extern "C" {
 #endif
 
+#if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
+#define __inline inline
+#endif
+
 #define __NEED_float_t
 #define __NEED_double_t
 #define __NEED___uint16_t
@@ -83,10 +87,7 @@ int __signbitl(long double);
 
 #define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y)))
 
-#if __STDC_VERSION__ >= 199901L
-inline
-#endif
-static int __isrel(long double __x, long double __y, int __rel)
+__inline static int __isrel(long double __x, long double __y, int __rel)
 {
 	if (isunordered(__x, __y)) return 0;
 	if (__rel==-2) return __x < __y;

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH/RFC] inline cleanup/C89 support
  2012-08-30 22:45             ` [PATCH/RFC] inline cleanup/C89 support Isaac Dunham
@ 2012-08-31  8:34               ` Szabolcs Nagy
  2012-08-31 19:27                 ` Isaac Dunham
  2012-09-02 16:51               ` Rich Felker
  1 sibling, 1 reply; 19+ messages in thread
From: Szabolcs Nagy @ 2012-08-31  8:34 UTC (permalink / raw)
  To: musl

* Isaac Dunham <idunham@lavabit.com> [2012-08-30 15:45:34 -0700]:
> On Fri, 24 Aug 2012 09:53:16 +0200
> Szabolcs Nagy <nsz@port70.net> wrote:
> > this won't work with c++, nor old strict c compilers
> > without __inline and __restrict and can break various
> > c parsing tools (ctags, swig, various lints, ..)
> 
> 1. Do any of these "old strict c compilers" exist on Linux?

yes
(eg sdcc for microcontrollers, plan9 cc used for the go runtime)

> Are any of them worth supporting? 

probably no

> 2. Have you tested those C parsing tools? Have they been updated to
> support C99?
> 

i used some of them, i know ctags handles __restrict
while swig (1.3) does not

many of the c (and c++) parsing tools dont do correct
preprocessing or don't define all the macros like
__STDC_VERSION__ so even if c99 grammar is mostly
supported i wouldnt be surprised if doxygen or indent
or similar tools had problems with __restrict

> If it is a realistic combination (can produce a working hello world),
> then it *might* be worth supporting.

the headers are not only for compiling musl

of course glibc uses __restrict so it should work
most of the time


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH/RFC] inline cleanup/C89 support
  2012-08-31  8:34               ` Szabolcs Nagy
@ 2012-08-31 19:27                 ` Isaac Dunham
  0 siblings, 0 replies; 19+ messages in thread
From: Isaac Dunham @ 2012-08-31 19:27 UTC (permalink / raw)
  To: musl

On Fri, 31 Aug 2012 10:34:18 +0200
Szabolcs Nagy <nsz@port70.net> wrote:

> * Isaac Dunham <idunham@lavabit.com> [2012-08-30 15:45:34 -0700]:
> > On Fri, 24 Aug 2012 09:53:16 +0200
> > Szabolcs Nagy <nsz@port70.net> wrote:
> > > this won't work with c++, nor old strict c compilers
> > > without __inline and __restrict and can break various
> > > c parsing tools (ctags, swig, various lints, ..)
> > 
> > 1. Do any of these "old strict c compilers" exist on Linux?
> 
> yes
> (eg sdcc for microcontrollers, plan9 cc used for the go runtime)
 
sdcc is not relevant: it doesn't link against the system libc, so it
shouldn't use system headers.
I thought I heard plan9 cc used its own libc?
 
> > 2. Have you tested those C parsing tools? Have they been updated to
> > support C99?
> > 
> i used some of them, i know ctags handles __restrict
> while swig (1.3) does not
> 
> many of the c (and c++) parsing tools dont do correct
> preprocessing or don't define all the macros like
> __STDC_VERSION__ so even if c99 grammar is mostly
> supported i wouldnt be surprised if doxygen or indent
> or similar tools had problems with __restrict

Ah.

> > If it is a realistic combination (can produce a working hello
> > world), then it *might* be worth supporting.
> 
> the headers are not only for compiling musl

But they are only for compiling *against* musl (ie, if it uses its own
libc or cannot produce working binaries linked against musl, it
shouldn't be using musl headers). 

> of course glibc uses __restrict so it should work
> most of the time

In case you didn't notice, this patch addresses uses __inline if
pre-c99 C is used, and __restrict is not involved. __restrict is
something that does need to be considered, however.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH/RFC] inline cleanup/C89 support
  2012-08-30 22:45             ` [PATCH/RFC] inline cleanup/C89 support Isaac Dunham
  2012-08-31  8:34               ` Szabolcs Nagy
@ 2012-09-02 16:51               ` Rich Felker
  2012-09-04 15:49                 ` philomath
  1 sibling, 1 reply; 19+ messages in thread
From: Rich Felker @ 2012-09-02 16:51 UTC (permalink / raw)
  To: musl

On Thu, Aug 30, 2012 at 03:45:34PM -0700, Isaac Dunham wrote:
> On Fri, 24 Aug 2012 09:53:16 +0200
> Szabolcs Nagy <nsz@port70.net> wrote:
> 
> > * Rich Felker <dalias@aerifal.cx> [2012-08-23 22:34:25 -0400]:
> ...
> > > #if __STDC_VERSION__ >= 199901L
> > > #define __inline inline
> > > #define __restrict restrict
> > > #endif
> > > 
> > > added near the top of headers that need to use inline and/or
> > > restrict.
> (As previously stated, it appears-per a grep of glibc-that restrict is
> not needed in these headers.) 
> This patch is updated for C++:
> 
> #if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
> #define __inline inline
> #endif
> [...]

Committed, with minor changes.

Rich


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH/RFC] inline cleanup/C89 support
  2012-09-02 16:51               ` Rich Felker
@ 2012-09-04 15:49                 ` philomath
  2012-09-04 17:44                   ` Rich Felker
  0 siblings, 1 reply; 19+ messages in thread
From: philomath @ 2012-09-04 15:49 UTC (permalink / raw)
  To: musl

On Sun, 2 Sep 2012 12:51:26 -0400
Rich Felker <dalias@aerifal.cx> wrote:

> On Thu, Aug 30, 2012 at 03:45:34PM -0700, Isaac Dunham wrote:
> > On Fri, 24 Aug 2012 09:53:16 +0200
> > Szabolcs Nagy <nsz@port70.net> wrote:
> > 
> > > * Rich Felker <dalias@aerifal.cx> [2012-08-23 22:34:25 -0400]:
> > ...
> > > > #if __STDC_VERSION__ >= 199901L
> > > > #define __inline inline
> > > > #define __restrict restrict
> > > > #endif
> > > > 
> > > > added near the top of headers that need to use inline and/or
> > > > restrict.
> > (As previously stated, it appears-per a grep of glibc-that restrict is
> > not needed in these headers.) 
> > This patch is updated for C++:
> > 
> > #if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
> > #define __inline inline
> > #endif
> > [...]
> 
> Committed, with minor changes.
> 
> Rich


Sorry for asking after the fact, but why the whole code-duplication? why not
have an internal header (like glibc's cdefs.h) for these kind of things (inline,
restrict, noreturn, etc) and include it where needed?

Thanks.


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH/RFC] inline cleanup/C89 support
  2012-09-04 15:49                 ` philomath
@ 2012-09-04 17:44                   ` Rich Felker
  0 siblings, 0 replies; 19+ messages in thread
From: Rich Felker @ 2012-09-04 17:44 UTC (permalink / raw)
  To: musl

On Tue, Sep 04, 2012 at 05:49:12PM +0200, philomath wrote:
> On Sun, 2 Sep 2012 12:51:26 -0400
> Rich Felker <dalias@aerifal.cx> wrote:
> 
> > On Thu, Aug 30, 2012 at 03:45:34PM -0700, Isaac Dunham wrote:
> > > On Fri, 24 Aug 2012 09:53:16 +0200
> > > Szabolcs Nagy <nsz@port70.net> wrote:
> > > 
> > > > * Rich Felker <dalias@aerifal.cx> [2012-08-23 22:34:25 -0400]:
> > > ...
> > > > > #if __STDC_VERSION__ >= 199901L
> > > > > #define __inline inline
> > > > > #define __restrict restrict
> > > > > #endif
> > > > > 
> > > > > added near the top of headers that need to use inline and/or
> > > > > restrict.
> > > (As previously stated, it appears-per a grep of glibc-that restrict is
> > > not needed in these headers.) 
> > > This patch is updated for C++:
> > > 
> > > #if __STDC_VERSION__ >= 199901L || defined(__cplusplus)
> > > #define __inline inline
> > > #endif
> > > [...]
> > 
> > Committed, with minor changes.
> > 
> > Rich
> 
> 
> Sorry for asking after the fact, but why the whole code-duplication? why not
> have an internal header (like glibc's cdefs.h) for these kind of things (inline,
> restrict, noreturn, etc) and include it where needed?

It's really a matter of weighing the costs against the benefits. The
duplication is minimal and it's not code that should require
maintenance; even if it did, maintenance would be simple pattern
replacement. On the other hand, the cost is pretty high. For compiling
small C files, the whole compile job is dominated O(# calls to open)
and adding an extra junk header just to do this trivial definition of
__inline would increase compile times measurably.

Rich


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2012-09-04 17:44 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-23  5:07 compatability: bits/syscall.h requires C99 idunham
2012-08-23  6:11 ` [PATCH] Problem is static inline idunham
2012-08-23  6:20   ` [PATCH 2/1] " idunham
2012-08-23  6:43     ` Szabolcs Nagy
2012-08-23  6:51   ` [PATCH] " Szabolcs Nagy
2012-08-23 12:18   ` Rich Felker
2012-08-23 12:31 ` compatability: bits/syscall.h requires C99 John Spencer
2012-08-23 12:34   ` Rich Felker
2012-08-24  0:25     ` Isaac Dunham
2012-08-24  2:07       ` Rich Felker
2012-08-24  2:34         ` Rich Felker
2012-08-24  3:31           ` [PATCH/RFC] __inline for C89 compilers (take 3?) Isaac Dunham
2012-08-24  7:53           ` compatability: bits/syscall.h requires C99 Szabolcs Nagy
2012-08-30 22:45             ` [PATCH/RFC] inline cleanup/C89 support Isaac Dunham
2012-08-31  8:34               ` Szabolcs Nagy
2012-08-31 19:27                 ` Isaac Dunham
2012-09-02 16:51               ` Rich Felker
2012-09-04 15:49                 ` philomath
2012-09-04 17:44                   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).