* [PATCH v1] tools/nolibc/stdio: add setvbuf() to set buffering mode
@ 2023-07-26 7:06 Ryan Roberts
2023-07-26 11:46 ` Mark Brown
0 siblings, 1 reply; 3+ messages in thread
From: Ryan Roberts @ 2023-07-26 7:06 UTC (permalink / raw)
To: Willy Tarreau, Andrew Morton, Mark Brown, Naresh Kamboju
Cc: Ryan Roberts, linux-kernel, Linux Kernel Functional Testing
Add a minimal implementation of setvbuf(), which error checks the mode
argument (as required by spec) and returns. Since nolibc never buffers
output, nothing needs to be done.
The kselftest framework recently added a call to setvbuf(). As a result,
any tests that use the kselftest framework and nolibc cause a compiler
error due to missing function. This provides an urgent fix for the
problem which is preventing arm64 testing on linux-next.
Example:
clang --target=aarch64-linux-gnu -fintegrated-as
-Werror=unknown-warning-option -Werror=ignored-optimization-argument
-Werror=option-ignored -Werror=unused-command-line-argument
--target=aarch64-linux-gnu -fintegrated-as
-fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \
-include ../../../../include/nolibc/nolibc.h -I../..\
-static -ffreestanding -Wall za-fork.c
build/kselftest/arm64/fp/za-fork-asm.o
-o build/kselftest/arm64/fp/za-fork
In file included from <built-in>:1:
In file included from ./../../../../include/nolibc/nolibc.h:97:
In file included from ./../../../../include/nolibc/arch.h:25:
./../../../../include/nolibc/arch-aarch64.h:178:35: warning: unknown
attribute 'optimize' ignored [-Wunknown-attributes]
void __attribute__((weak,noreturn,optimize("omit-frame-pointer")))
__no_stack_protector _start(void)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from za-fork.c:12:
../../kselftest.h:123:2: error: call to undeclared function 'setvbuf';
ISO C99 and later do not support implicit function declarations
[-Wimplicit-function-declaration]
setvbuf(stdout, NULL, _IOLBF, 0);
^
../../kselftest.h:123:24: error: use of undeclared identifier '_IOLBF'
setvbuf(stdout, NULL, _IOLBF, 0);
^
1 warning and 2 errors generated.
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Fixes: ecb7fe2cd610 ("selftests: line buffer test program's stdout")
Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Link: https://lore.kernel.org/linux-kselftest/CA+G9fYus3Z8r2cg3zLv8uH8MRrzLFVWdnor02SNr=rCz+_WGVg@mail.gmail.com/
---
tools/include/nolibc/stdio.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
index 0eef91daf289..a3778aff4fa9 100644
--- a/tools/include/nolibc/stdio.h
+++ b/tools/include/nolibc/stdio.h
@@ -21,6 +21,11 @@
#define EOF (-1)
#endif
+/* Buffering mode used by setvbuf. */
+#define _IOFBF 0 /* Fully buffered. */
+#define _IOLBF 1 /* Line buffered. */
+#define _IONBF 2 /* No buffering. */
+
/* just define FILE as a non-empty type. The value of the pointer gives
* the FD: FILE=~fd for fd>=0 or NULL for fd<0. This way positive FILE
* are immediately identified as abnormal entries (i.e. possible copies
@@ -350,6 +355,25 @@ void perror(const char *msg)
fprintf(stderr, "%s%serrno=%d\n", (msg && *msg) ? msg : "", (msg && *msg) ? ": " : "", errno);
}
+static __attribute__((unused))
+int setvbuf(FILE *stream, char *buf, int mode, size_t size)
+{
+ /*
+ * nolibc does not support buffering so this is a nop. Just check mode
+ * is valid as required by the spec.
+ */
+ switch (mode) {
+ case _IOFBF:
+ case _IOLBF:
+ case _IONBF:
+ break;
+ default:
+ return EOF;
+ }
+
+ return 0;
+}
+
/* make sure to include all global symbols */
#include "nolibc.h"
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] tools/nolibc/stdio: add setvbuf() to set buffering mode
2023-07-26 7:06 [PATCH v1] tools/nolibc/stdio: add setvbuf() to set buffering mode Ryan Roberts
@ 2023-07-26 11:46 ` Mark Brown
2023-07-29 7:28 ` Willy Tarreau
0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2023-07-26 11:46 UTC (permalink / raw)
To: Ryan Roberts
Cc: Willy Tarreau, Andrew Morton, Naresh Kamboju, linux-kernel,
Linux Kernel Functional Testing
[-- Attachment #1: Type: text/plain, Size: 290 bytes --]
On Wed, Jul 26, 2023 at 08:06:55AM +0100, Ryan Roberts wrote:
> Add a minimal implementation of setvbuf(), which error checks the mode
> argument (as required by spec) and returns. Since nolibc never buffers
> output, nothing needs to be done.
Reviewed-by: Mark Brown <broonie@kernel.org>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] tools/nolibc/stdio: add setvbuf() to set buffering mode
2023-07-26 11:46 ` Mark Brown
@ 2023-07-29 7:28 ` Willy Tarreau
0 siblings, 0 replies; 3+ messages in thread
From: Willy Tarreau @ 2023-07-29 7:28 UTC (permalink / raw)
To: Mark Brown
Cc: Ryan Roberts, Andrew Morton, Naresh Kamboju, linux-kernel,
Linux Kernel Functional Testing
On Wed, Jul 26, 2023 at 12:46:16PM +0100, Mark Brown wrote:
> On Wed, Jul 26, 2023 at 08:06:55AM +0100, Ryan Roberts wrote:
> > Add a minimal implementation of setvbuf(), which error checks the mode
> > argument (as required by spec) and returns. Since nolibc never buffers
> > output, nothing needs to be done.
>
> Reviewed-by: Mark Brown <broonie@kernel.org>
Looks good and queued, thanks to you both!
Willy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-29 7:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-26 7:06 [PATCH v1] tools/nolibc/stdio: add setvbuf() to set buffering mode Ryan Roberts
2023-07-26 11:46 ` Mark Brown
2023-07-29 7:28 ` Willy Tarreau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox