2023-04-06 21:56:42

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH v2 00/11] tools/nolibc: -std=c89 compatibility

This series replaces the C99 compatibility patch. (See v1 link below).
After the discussion about support C99 and/or GNU89 I came to the
conclusion supporting straight C89 is not very hard.

Instead of validating both C99 and GNU89 in some awkward way only for
somebody requesting true C89 support let's just do it this way.

Feel free to squash all the comment syntax patches together if you
prefer.

All changes in this series are cosmetic only.

To: Willy Tarreau <[email protected]>
To: Shuah Khan <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Thomas Weißschuh <[email protected]>

This series is based on the "dev" branch of the RCU tree.

---
Changes in v2:
- Target C89 instead of C99
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Thomas Weißschuh (11):
tools/nolibc: use standard __asm__ statements
tools/nolibc: use __inline__ syntax
tools/nolibc: i386: use C89 comment syntax
tools/nolibc: x86_64: use C89 comment syntax
tools/nolibc: riscv: use C89 comment syntax
tools/nolibc: aarch64: use C89 comment syntax
tools/nolibc: arm: use C89 comment syntax
tools/nolibc: mips: use C89 comment syntax
tools/nolibc: loongarch: use C89 comment syntax
tools/nolibc: use C89 comment syntax
tools/nolibc: validate C89 compatibility

tools/include/nolibc/arch-aarch64.h | 32 ++++++++--------
tools/include/nolibc/arch-arm.h | 42 ++++++++++-----------
tools/include/nolibc/arch-i386.h | 40 ++++++++++----------
tools/include/nolibc/arch-loongarch.h | 38 +++++++++----------
tools/include/nolibc/arch-mips.h | 56 ++++++++++++++--------------
tools/include/nolibc/arch-riscv.h | 40 ++++++++++----------
tools/include/nolibc/arch-x86_64.h | 34 ++++++++---------
tools/include/nolibc/stackprotector.h | 4 +-
tools/include/nolibc/stdlib.h | 18 ++++-----
tools/include/nolibc/string.h | 4 +-
tools/include/nolibc/sys.h | 8 ++--
tools/testing/selftests/nolibc/Makefile | 2 +-
tools/testing/selftests/nolibc/nolibc-test.c | 14 +++----
13 files changed, 166 insertions(+), 166 deletions(-)
---
base-commit: bd5b341f0f69eb4c958ffd48699213c5b9af8145
change-id: 20230328-nolibc-c99-59f44ea45636

Best regards,
--
Thomas Weißschuh <[email protected]>


2023-04-06 21:56:53

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH v2 01/11] tools/nolibc: use standard __asm__ statements

Most of the code was migrated to C99-conformant __asm__ statements
before. It seems string.h was missed.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
tools/include/nolibc/string.h | 4 ++--
tools/testing/selftests/nolibc/nolibc-test.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/include/nolibc/string.h b/tools/include/nolibc/string.h
index fffdaf6ff467..0c2e06c7c477 100644
--- a/tools/include/nolibc/string.h
+++ b/tools/include/nolibc/string.h
@@ -90,7 +90,7 @@ void *memset(void *dst, int b, size_t len)

while (len--) {
/* prevent gcc from recognizing memset() here */
- asm volatile("");
+ __asm__ volatile("");
*(p++) = b;
}
return dst;
@@ -139,7 +139,7 @@ size_t strlen(const char *str)
size_t len;

for (len = 0; str[len]; len++)
- asm("");
+ __asm__("");
return len;
}

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 888da60eb5ba..e692be98973a 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -984,7 +984,7 @@ int main(int argc, char **argv, char **envp)
#else
else if (ioperm(0x501, 1, 1) == 0)
#endif
- asm volatile ("outb %%al, %%dx" :: "d"(0x501), "a"(0));
+ __asm__ volatile ("outb %%al, %%dx" :: "d"(0x501), "a"(0));
/* if it does nothing, fall back to the regular panic */
#endif
}

--
2.40.0

2023-04-06 21:57:11

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH v2 03/11] tools/nolibc: i386: use C89 comment syntax

Most of nolibc is already using C89 comments.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
tools/include/nolibc/arch-i386.h | 40 ++++++++++++++++++++--------------------
1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/tools/include/nolibc/arch-i386.h b/tools/include/nolibc/arch-i386.h
index 2d98d78fd3f3..7c41897a08ce 100644
--- a/tools/include/nolibc/arch-i386.h
+++ b/tools/include/nolibc/arch-i386.h
@@ -194,31 +194,31 @@ void __attribute__((weak,noreturn,optimize("omit-frame-pointer"),no_stack_protec
{
__asm__ volatile (
#ifdef NOLIBC_STACKPROTECTOR
- "call __stack_chk_init\n" // initialize stack protector
+ "call __stack_chk_init\n" /* initialize stack protector */
#endif
- "pop %eax\n" // argc (first arg, %eax)
- "mov %esp, %ebx\n" // argv[] (second arg, %ebx)
- "lea 4(%ebx,%eax,4),%ecx\n" // then a NULL then envp (third arg, %ecx)
- "mov %ecx, environ\n" // save environ
- "xor %ebp, %ebp\n" // zero the stack frame
- "mov %ecx, %edx\n" // search for auxv (follows NULL after last env)
+ "pop %eax\n" /* argc (first arg, %eax) */
+ "mov %esp, %ebx\n" /* argv[] (second arg, %ebx) */
+ "lea 4(%ebx,%eax,4),%ecx\n" /* then a NULL then envp (third arg, %ecx) */
+ "mov %ecx, environ\n" /* save environ */
+ "xor %ebp, %ebp\n" /* zero the stack frame */
+ "mov %ecx, %edx\n" /* search for auxv (follows NULL after last env) */
"0:\n"
- "add $4, %edx\n" // search for auxv using edx, it follows the
- "cmp -4(%edx), %ebp\n" // ... NULL after last env (ebp is zero here)
+ "add $4, %edx\n" /* search for auxv using edx, it follows the */
+ "cmp -4(%edx), %ebp\n" /* ... NULL after last env (ebp is zero here) */
"jnz 0b\n"
- "mov %edx, _auxv\n" // save it into _auxv
- "and $-16, %esp\n" // x86 ABI : esp must be 16-byte aligned before
- "sub $4, %esp\n" // the call instruction (args are aligned)
- "push %ecx\n" // push all registers on the stack so that we
- "push %ebx\n" // support both regparm and plain stack modes
+ "mov %edx, _auxv\n" /* save it into _auxv */
+ "and $-16, %esp\n" /* x86 ABI : esp must be 16-byte aligned before */
+ "sub $4, %esp\n" /* the call instruction (args are aligned) */
+ "push %ecx\n" /* push all registers on the stack so that we */
+ "push %ebx\n" /* support both regparm and plain stack modes */
"push %eax\n"
- "call main\n" // main() returns the status code in %eax
- "mov %eax, %ebx\n" // retrieve exit code (32-bit int)
- "movl $1, %eax\n" // NR_exit == 1
- "int $0x80\n" // exit now
- "hlt\n" // ensure it does not
+ "call main\n" /* main() returns the status code in %eax */
+ "mov %eax, %ebx\n" /* retrieve exit code (32-bit int) */
+ "movl $1, %eax\n" /* NR_exit == 1 */
+ "int $0x80\n" /* exit now */
+ "hlt\n" /* ensure it does not */
);
__builtin_unreachable();
}

-#endif // _NOLIBC_ARCH_I386_H
+#endif /* _NOLIBC_ARCH_I386_H */

--
2.40.0

2023-04-06 21:57:23

by Thomas Weißschuh

[permalink] [raw]
Subject: [PATCH v2 10/11] tools/nolibc: use C89 comment syntax

Most of nolibc is already using C89 comments.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
tools/include/nolibc/stackprotector.h | 4 ++--
tools/include/nolibc/sys.h | 8 ++++----
tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++------
3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/tools/include/nolibc/stackprotector.h b/tools/include/nolibc/stackprotector.h
index d119cbbbc256..77e5251c4490 100644
--- a/tools/include/nolibc/stackprotector.h
+++ b/tools/include/nolibc/stackprotector.h
@@ -48,6 +48,6 @@ void __stack_chk_init(void)
/* a bit more randomness in case getrandom() fails */
__stack_chk_guard ^= (uintptr_t) &__stack_chk_guard;
}
-#endif // defined(NOLIBC_STACKPROTECTOR)
+#endif /* defined(NOLIBC_STACKPROTECTOR) */

-#endif // _NOLIBC_STACKPROTECTOR_H
+#endif /* _NOLIBC_STACKPROTECTOR_H */
diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h
index bea9760dbd16..1b9b91cd8b57 100644
--- a/tools/include/nolibc/sys.h
+++ b/tools/include/nolibc/sys.h
@@ -12,15 +12,15 @@

/* system includes */
#include <asm/unistd.h>
-#include <asm/signal.h> // for SIGCHLD
+#include <asm/signal.h> /* for SIGCHLD */
#include <asm/ioctls.h>
#include <asm/mman.h>
#include <linux/fs.h>
#include <linux/loop.h>
#include <linux/time.h>
#include <linux/auxvec.h>
-#include <linux/fcntl.h> // for O_* and AT_*
-#include <linux/stat.h> // for statx()
+#include <linux/fcntl.h> /* for O_* and AT_* */
+#include <linux/stat.h> /* for statx() */

#include "arch.h"
#include "errno.h"
@@ -322,7 +322,7 @@ static __attribute__((noreturn,unused))
void sys_exit(int status)
{
my_syscall1(__NR_exit, status & 255);
- while(1); // shut the "noreturn" warnings.
+ while(1); /* shut the "noreturn" warnings. */
}

static __attribute__((noreturn,unused))
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index e692be98973a..f06b38cfe38a 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0
+/* SPDX-License-Identifier: GPL-2.0 */

#define _GNU_SOURCE

@@ -46,8 +46,8 @@ char **environ;

/* definition of a series of tests */
struct test {
- const char *name; // test name
- int (*func)(int min, int max); // handler
+ const char *name; /* test name */
+ int (*func)(int min, int max); /* handler */
};

#ifndef _NOLIBC_STDLIB_H
@@ -494,7 +494,7 @@ int run_syscall(int min, int max)
euid0 = geteuid() == 0;

for (test = min; test >= 0 && test <= max; test++) {
- int llen = 0; // line length
+ int llen = 0; /* line length */

/* avoid leaving empty lines below, this will insert holes into
* test numbers.
@@ -584,7 +584,7 @@ int run_stdlib(int min, int max)
void *p1, *p2;

for (test = min; test >= 0 && test <= max; test++) {
- int llen = 0; // line length
+ int llen = 0; /* line length */

/* avoid leaving empty lines below, this will insert holes into
* test numbers.
@@ -731,7 +731,7 @@ static int run_vfprintf(int min, int max)
void *p1, *p2;

for (test = min; test >= 0 && test <= max; test++) {
- int llen = 0; // line length
+ int llen = 0; /* line length */

/* avoid leaving empty lines below, this will insert holes into
* test numbers.

--
2.40.0

2023-04-09 09:47:25

by Willy Tarreau

[permalink] [raw]
Subject: Re: [PATCH v2 00/11] tools/nolibc: -std=c89 compatibility

Hi Thomas,

On Thu, Apr 06, 2023 at 09:54:46PM +0000, Thomas Wei?schuh wrote:
> This series replaces the C99 compatibility patch. (See v1 link below).
> After the discussion about support C99 and/or GNU89 I came to the
> conclusion supporting straight C89 is not very hard.
>
> Instead of validating both C99 and GNU89 in some awkward way only for
> somebody requesting true C89 support let's just do it this way.
>
> Feel free to squash all the comment syntax patches together if you
> prefer.

I gave it some thought, at first considering that going lower than GNU89
was possibly not very useful, but given that the changes are very small
in the end (mostly comments formating), I think that you're right. The
cost of reaching this level of portability is basically zero once the
patch is applied so I think it's worth doing it now. However I think I
will indeed squash all the comments patch together as you suggest.

Thank you!
Willy

2023-04-15 14:56:05

by Willy Tarreau

[permalink] [raw]
Subject: Re: [PATCH v2 00/11] tools/nolibc: -std=c89 compatibility

Hi Thomas,

On Sun, Apr 09, 2023 at 11:28:46AM +0200, Willy Tarreau wrote:
> Hi Thomas,
>
> On Thu, Apr 06, 2023 at 09:54:46PM +0000, Thomas Wei?schuh wrote:
> > This series replaces the C99 compatibility patch. (See v1 link below).
> > After the discussion about support C99 and/or GNU89 I came to the
> > conclusion supporting straight C89 is not very hard.
> >
> > Instead of validating both C99 and GNU89 in some awkward way only for
> > somebody requesting true C89 support let's just do it this way.
> >
> > Feel free to squash all the comment syntax patches together if you
> > prefer.
>
> I gave it some thought, at first considering that going lower than GNU89
> was possibly not very useful, but given that the changes are very small
> in the end (mostly comments formating), I think that you're right. The
> cost of reaching this level of portability is basically zero once the
> patch is applied so I think it's worth doing it now. However I think I
> will indeed squash all the comments patch together as you suggest.

I've now squashed the ones about comments together, fixed the declaration
inside the for statement in nolibc-test and tested with gcc 4.7 & 4.8 and
confirmed it works as expected. I've queued it there for now:

https://git.kernel.org/pub/scm/linux/kernel/git/wtarreau/nolibc.git/log/?h=20230415-nolibc-updates-4a

Thank you!
Willy

2023-04-15 15:56:05

by Thomas Weißschuh

[permalink] [raw]
Subject: Re: [PATCH v2 00/11] tools/nolibc: -std=c89 compatibility

On 2023-04-15 16:47:03+0200, Willy Tarreau wrote:
> On Sun, Apr 09, 2023 at 11:28:46AM +0200, Willy Tarreau wrote:
> > On Thu, Apr 06, 2023 at 09:54:46PM +0000, Thomas Weißschuh wrote:
> > > This series replaces the C99 compatibility patch. (See v1 link below).
> > > After the discussion about support C99 and/or GNU89 I came to the
> > > conclusion supporting straight C89 is not very hard.
> > >
> > > Instead of validating both C99 and GNU89 in some awkward way only for
> > > somebody requesting true C89 support let's just do it this way.
> > >
> > > Feel free to squash all the comment syntax patches together if you
> > > prefer.
> >
> > I gave it some thought, at first considering that going lower than GNU89
> > was possibly not very useful, but given that the changes are very small
> > in the end (mostly comments formating), I think that you're right. The
> > cost of reaching this level of portability is basically zero once the
> > patch is applied so I think it's worth doing it now. However I think I
> > will indeed squash all the comments patch together as you suggest.
>
> I've now squashed the ones about comments together, fixed the declaration
> inside the for statement in nolibc-test and tested with gcc 4.7 & 4.8 and
> confirmed it works as expected. I've queued it there for now:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/wtarreau/nolibc.git/log/?h=20230415-nolibc-updates-4a

Thanks!

I noticed today that I did not adapt the comments in arch-s390.h;
because the start() comments were already correct.

But the last line of arch-s390.h still contains a C99 comment.

Do you want me to send a patch or could you just push one?
(Or fold it into my patch)

Thanks,
Thomas

2023-04-15 17:14:57

by Willy Tarreau

[permalink] [raw]
Subject: Re: [PATCH v2 00/11] tools/nolibc: -std=c89 compatibility

On Sat, Apr 15, 2023 at 05:15:27PM +0200, Thomas Wei?schuh wrote:
> On 2023-04-15 16:47:03+0200, Willy Tarreau wrote:
> > On Sun, Apr 09, 2023 at 11:28:46AM +0200, Willy Tarreau wrote:
> > > On Thu, Apr 06, 2023 at 09:54:46PM +0000, Thomas Wei?schuh wrote:
> > > > This series replaces the C99 compatibility patch. (See v1 link below).
> > > > After the discussion about support C99 and/or GNU89 I came to the
> > > > conclusion supporting straight C89 is not very hard.
> > > >
> > > > Instead of validating both C99 and GNU89 in some awkward way only for
> > > > somebody requesting true C89 support let's just do it this way.
> > > >
> > > > Feel free to squash all the comment syntax patches together if you
> > > > prefer.
> > >
> > > I gave it some thought, at first considering that going lower than GNU89
> > > was possibly not very useful, but given that the changes are very small
> > > in the end (mostly comments formating), I think that you're right. The
> > > cost of reaching this level of portability is basically zero once the
> > > patch is applied so I think it's worth doing it now. However I think I
> > > will indeed squash all the comments patch together as you suggest.
> >
> > I've now squashed the ones about comments together, fixed the declaration
> > inside the for statement in nolibc-test and tested with gcc 4.7 & 4.8 and
> > confirmed it works as expected. I've queued it there for now:
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/wtarreau/nolibc.git/log/?h=20230415-nolibc-updates-4a
>
> Thanks!
>
> I noticed today that I did not adapt the comments in arch-s390.h;
> because the start() comments were already correct.
>
> But the last line of arch-s390.h still contains a C99 comment.

ah, I must have missed it because I checked using git grep //.

> Do you want me to send a patch or could you just push one?
> (Or fold it into my patch)

I'll do it and force-push. Thanks for checking and notifying me!

Cheers,
Willy