Message ID | c61f64c4d1f69c19b41efae8fef5a94547089ca7.1688134399.git.falcon@tinylab.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10430979vqr; Fri, 30 Jun 2023 07:59:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlGgFJt+InX4LRJZZg9YwhlmfU8uj7a0fTiCWj5n931c4FHLE7wTYQDXih/1/R9LC5mtSfEt X-Received: by 2002:a92:cc09:0:b0:345:df7f:efc4 with SMTP id s9-20020a92cc09000000b00345df7fefc4mr2531317ilp.27.1688137194345; Fri, 30 Jun 2023 07:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688137194; cv=none; d=google.com; s=arc-20160816; b=G50OzVg/UX3AnR8Eofz2vU1+9i40S6WJu5cHRQmGX12asEkQUy6CsRYBBM6BzHfeXw 67pN7pvuPcQ+h4jAogHWtL6Z/96+FLqzBjOnluLVgu0nF0H8k+KLpgw7Q/vuIAq+IxYX tNpxhBG8vETK/vkYuElw1YVNRYTsWfO0e6xH1j7OhOuJ8rJfcRO5jWMU1QPDHU0hnDJn uUmmwtyHZB6CcBH8KAQj7TAsgOMBWrvU7nIhcQKF5mQYRZ8vt5nsebxOK1MSb2Sq5Fwi SkjjUnaomTPVoSOxtWhEboMSzOVY7GBoZ6up961Slwqjrpm2t5NJXickZOFDjIU2WR1e +LKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=EpTYZp97ibAtozsC+vqUAe03Cyxec2RLz761MoQ6Gd8=; fh=49fx4+cYYT2jkB1G9v6CSOY1nO+RV0JwAuF3mNCzENI=; b=DInca/bDqGZHs+g8o2AJ8AuRqtGZxM0Jbtacuwqn2jw9iK4tNk/Qi0t7+q6CAL4MPQ tIKuga3/d4zBU9WWvouUbyV0ggM/la4P5WtC0Y+BCTZZC20j1qE6aQLC3QzeCj6fJgj6 0krlM6z+3hiuEmSwSzVT8KX7/GusWhi+JXeWZMjKZBS7Mmdhoo4EnpfkbeAfiqNnZOyT QX0R9cTZx5V1ZQ7uQ5flpoTr+W7jtm0Z+koWMrFxrSI8jh9RPQa45c84I3UyZAqaWDDW wp6zAZQCuaCyTtrZCugF62uxhY/oeU3MvdZTt/jFeOjY/6vcn4mDyG41oAhXSCA7kAUe bBZg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n7-20020a6543c7000000b0055b635c3f6fsi1303563pgp.458.2023.06.30.07.59.39; Fri, 30 Jun 2023 07:59:54 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232347AbjF3Opg (ORCPT <rfc822;nicolai.engesland@gmail.com> + 99 others); Fri, 30 Jun 2023 10:45:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229787AbjF3Opa (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 30 Jun 2023 10:45:30 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAEC199; Fri, 30 Jun 2023 07:45:28 -0700 (PDT) X-QQ-mid: bizesmtp81t1688136303tkq6bgyc Received: from linux-lab-host.localdomain ( [119.123.131.49]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 30 Jun 2023 22:45:01 +0800 (CST) X-QQ-SSF: 00200000000000D0W000000A0000000 X-QQ-FEAT: eSZ1CZgv+JCNNmiaGU+xCx+Rwo8I6Yp2+gMQj7gkCsAkjSccXgiKv0mViWWtQ 4Dsis6SCLBuuG7h8PbrFr5H6niurTsRSpLvA0m22HVFOIdb1VDnJjE92o9Rg/QunBgTXNh6 R64hR4VIwoajaEBwaqym8LBpeDshvH5pSmJyvecPk9ST3nEAQoVyyt5pOlF2Ok7mfY+79KY 4cLKLjEmwDcAIX8HB2TGzWeODijFUj0ERJnabnlqX6XXgUygoSneTU3UUYIdMSHw0GmnTC2 Gv4fMGhBDJsps6ccLeZUy9qrMk/P2C35ock98RAvKTm43AHc++Sf1A+WvKW7Sgbze05toW3 SiEzENKQ3ZjzKT9/rzE5DWGB0CgMzpPKs4CrO6cPjDceBzowtlSGOnzoV4WW2d5IPgsHBwB X-QQ-GoodBg: 0 X-BIZMAIL-ID: 650073420441935089 From: Zhangjin Wu <falcon@tinylab.org> To: thomas@t-8ch.de, w@1wt.eu Cc: arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= <linux@weissschuh.net> Subject: [PATCH v3 03/14] selftests/nolibc: add _LARGEFILE64_SOURCE for musl Date: Fri, 30 Jun 2023 22:44:56 +0800 Message-Id: <c61f64c4d1f69c19b41efae8fef5a94547089ca7.1688134399.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <cover.1688134399.git.falcon@tinylab.org> References: <cover.1688134399.git.falcon@tinylab.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770140146655057102?= X-GMAIL-MSGID: =?utf-8?q?1770140146655057102?= |
Series |
selftests/nolibc: allow run with minimal kernel config
|
|
Commit Message
Zhangjin Wu
June 30, 2023, 2:44 p.m. UTC
_GNU_SOURCE Implies _LARGEFILE64_SOURCE in glibc, but in musl, the default configuration doesn't enable _LARGEFILE64_SOURCE. From include/dirent.h of musl, getdents64 is provided as getdents when _LARGEFILE64_SOURCE is defined. #if defined(_LARGEFILE64_SOURCE) ... #define getdents64 getdents #endif Let's define _LARGEFILE64_SOURCE to fix up this compile error: tools/testing/selftests/nolibc/nolibc-test.c: In function ‘test_getdents64’: tools/testing/selftests/nolibc/nolibc-test.c:453:8: warning: implicit declaration of function ‘getdents64’; did you mean ‘getdents’? [-Wimplicit-function-declaration] 453 | ret = getdents64(fd, (void *)buffer, sizeof(buffer)); | ^~~~~~~~~~ | getdents /usr/bin/ld: /tmp/ccKILm5u.o: in function `test_getdents64': nolibc-test.c:(.text+0xe3e): undefined reference to `getdents64' collect2: error: ld returned 1 exit status Reviewed-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Zhangjin Wu <falcon@tinylab.org> --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+)
Comments
On Fri, Jun 30, 2023, at 16:44, Zhangjin Wu wrote: > _GNU_SOURCE Implies _LARGEFILE64_SOURCE in glibc, but in musl, the > default configuration doesn't enable _LARGEFILE64_SOURCE. > > From include/dirent.h of musl, getdents64 is provided as getdents when > _LARGEFILE64_SOURCE is defined. > > #if defined(_LARGEFILE64_SOURCE) > ... > #define getdents64 getdents > #endif > > Let's define _LARGEFILE64_SOURCE to fix up this compile error: I think a better solution would be to use the normal getdents() instead of glibc getdents64(), but then define _FILE_OFFSET_BITS=64 to tell glibc to use the modern version of all filesystem syscalls. Arnd
Hi, Arnd > On Fri, Jun 30, 2023, at 16:44, Zhangjin Wu wrote: > > _GNU_SOURCE Implies _LARGEFILE64_SOURCE in glibc, but in musl, the > > default configuration doesn't enable _LARGEFILE64_SOURCE. > > > > From include/dirent.h of musl, getdents64 is provided as getdents when > > _LARGEFILE64_SOURCE is defined. > > > > #if defined(_LARGEFILE64_SOURCE) > > ... > > #define getdents64 getdents > > #endif > > > > Let's define _LARGEFILE64_SOURCE to fix up this compile error: > > I think a better solution would be to use the normal getdents() instead > of glibc getdents64(), but then define _FILE_OFFSET_BITS=64 to tell > glibc to use the modern version of all filesystem syscalls. > Just checked the getdents manpage[1] and the nolibc code, both of glibc and nolibc don't provide the getdents() library routine but both of them provide the getdents64(), only musl provide getdents() by default. And as the manpage shows, it is not easy to call getdents() with glibc, we need manually call syscall() and define the 'dirent' struct ourselves: glibc does not provide a wrapper for getdents(); call getdents() using syscall(2). In that case you will need to define the linux_dirent or linux_dirent64 structure yourself. And for nolibc, a getdents64() with linux_dirent64 struct (with int64_t offset) is provided, there is either no getdents() currently. This patch aims to let nolibc-test at least compile for musl and therefore we can easily check the new tests for musl, glibc and nolibc together. For the 64bit offset related stuff, we'd better delay it in another patchset (part of full rv32 support), which will convert the off_t to 64bit by default. Thanks, Zhangjin [1]: https://man7.org/linux/man-pages/man2/getdents.2.html > Arnd
On Fri, Jun 30, 2023, at 20:01, Zhangjin Wu wrote: > Hi, Arnd > >> On Fri, Jun 30, 2023, at 16:44, Zhangjin Wu wrote: >> > _GNU_SOURCE Implies _LARGEFILE64_SOURCE in glibc, but in musl, the >> > default configuration doesn't enable _LARGEFILE64_SOURCE. >> > >> > From include/dirent.h of musl, getdents64 is provided as getdents when >> > _LARGEFILE64_SOURCE is defined. >> > >> > #if defined(_LARGEFILE64_SOURCE) >> > ... >> > #define getdents64 getdents >> > #endif >> > >> > Let's define _LARGEFILE64_SOURCE to fix up this compile error: >> >> I think a better solution would be to use the normal getdents() instead >> of glibc getdents64(), but then define _FILE_OFFSET_BITS=64 to tell >> glibc to use the modern version of all filesystem syscalls. >> > > Just checked the getdents manpage[1] and the nolibc code, both of glibc and > nolibc don't provide the getdents() library routine but both of them provide > the getdents64(), only musl provide getdents() by default. > > And as the manpage shows, it is not easy to call getdents() with glibc, we > need manually call syscall() and define the 'dirent' struct ourselves: > > glibc does not provide a wrapper for getdents(); call getdents() > using syscall(2). In that case you will need to define the > linux_dirent or linux_dirent64 structure yourself. > > And for nolibc, a getdents64() with linux_dirent64 struct (with int64_t offset) > is provided, there is either no getdents() currently. > > This patch aims to let nolibc-test at least compile for musl and therefore we > can easily check the new tests for musl, glibc and nolibc together. Ok, I see. Your current approach should be fine then. > For the 64bit offset related stuff, we'd better delay it in another patchset > (part of full rv32 support), which will convert the off_t to 64bit by default. Right, makes sense. ARnd
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index be7614c897b4..d9644244fc95 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ #define _GNU_SOURCE +#define _LARGEFILE64_SOURCE /* libc-specific include files * The program may be built in 3 ways: