From patchwork Wed Jul 26 07:06:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 126145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp230981vqo; Wed, 26 Jul 2023 00:25:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlFIyzwSQ4VkAMrJvH6AmKiiH1QM9Xc5mhv3sPZ7k+3lL/BwI/MM5mOcXTqxOGGnxYsrRO9u X-Received: by 2002:a05:6a20:8f1d:b0:135:66d9:a52f with SMTP id b29-20020a056a208f1d00b0013566d9a52fmr1708096pzk.7.1690356348666; Wed, 26 Jul 2023 00:25:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690356348; cv=none; d=google.com; s=arc-20160816; b=CVeqSTMcY1kGs31+WIR5ZFvusDhsRWx7od1j+VNalCOIaeZNY1fIdMBMpahkDK58dG hstEVrDoBM5n18ji+08R+3dlagb8xFvMGJjOaSb/pnE5zNol0gZwzgNx2Ktsn01DgWvj IX/D6SXVZKXcNqLPWACINlxXW8N4fu6uSBEhQY+nwqmqMXd+DwSfkRnIacm80Gy+JrJa A636KxkYt+QCvv5A9pZsYOABwqaFanY2hMU9eWNaSMh2dzQOR0vCLAkUn03At1dfGzOy zGDlBGWa0tWiO9VDva4NA80g1nzL38Ip1J7O2QuexHSQZ/+a/9vfOQ9mhRXLD0JE2kRc JaHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=hDg03n+SEXjisBetwp5xJW160enKt+n46/YnP1rs2Uk=; fh=qBXGQBTtX56O/x+7PHe+JSN9TsiK5K0QADb/0fbsPPQ=; b=WkHSm1oEhNWwxTHVwGPKpCLTeWi3ToSkN+z32mMTdiOdQxYntqmRvoSdVlR8uAIFTP VSx0HYk2MVQu+VnSfLz3AQv7iBgHJPjTH2QnT6Z9MJondlnm1Vfby+bwGRGfEUz9mb8N LvOnmBVI80YjgnNKC2+uigMPBcljn3J136xA746f/HLpX1oAytE4W3heBF4LKirBwDUS ZJqUmWvNWXVYeOATIR6XmxVEcD5iIQl9zPi/2I1QO4Qw6JH67K00Y7Arnw4xKiqPfDI7 dp4LQ6jS0+e2gXcYP2HFWKTcmVMD5vfXJanaxPzQ3Eh4tHTm2Z6u1tmpRhuw0sP09xF4 cqFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t20-20020a63b254000000b00563ea7bc4ffsi253427pgo.196.2023.07.26.00.25.35; Wed, 26 Jul 2023 00:25:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232442AbjGZHLU (ORCPT + 99 others); Wed, 26 Jul 2023 03:11:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232435AbjGZHKx (ORCPT ); Wed, 26 Jul 2023 03:10:53 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5AB5D2727 for ; Wed, 26 Jul 2023 00:07:44 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6726011FB; Wed, 26 Jul 2023 00:07:47 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 587463F5A1; Wed, 26 Jul 2023 00:07:03 -0700 (PDT) From: Ryan Roberts To: Willy Tarreau , Andrew Morton , Mark Brown , Naresh Kamboju Cc: Ryan Roberts , linux-kernel@vger.kernel.org, Linux Kernel Functional Testing Subject: [PATCH v1] tools/nolibc/stdio: add setvbuf() to set buffering mode Date: Wed, 26 Jul 2023 08:06:55 +0100 Message-Id: <20230726070655.2713530-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772467098792421982 X-GMAIL-MSGID: 1772467098792421982 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 :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 Fixes: ecb7fe2cd610 ("selftests: line buffer test program's stdout") Reported-by: Linux Kernel Functional Testing Link: https://lore.kernel.org/linux-kselftest/CA+G9fYus3Z8r2cg3zLv8uH8MRrzLFVWdnor02SNr=rCz+_WGVg@mail.gmail.com/ Reviewed-by: Mark Brown --- tools/include/nolibc/stdio.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) -- 2.25.1 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"