mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 06/13] libfile: stub out file descriptor API for PBL
Date: Wed, 16 Oct 2024 11:01:43 +0200	[thread overview]
Message-ID: <20241016090150.3963002-7-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241016090150.3963002-1-a.fatoum@pengutronix.de>

To optimize out calls to undefined functions in PBL at compile-time
instead of link time, let's define stubs for the functions that
are referenced in obj-pbl-y files, but inside function sections
that are ultimately unreferenced.

We don't use IS_PROPER here as VFS support is always available
in barebox proper.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/fcntl.h   |  8 ++++++
 include/libfile.h |  7 +++++
 include/unistd.h  | 72 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+)

diff --git a/include/fcntl.h b/include/fcntl.h
index a746471411b5..ff91676119c4 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -3,6 +3,7 @@
 #define __FCNTL_H
 
 #include <linux/types.h>
+#include <errno.h>
 
 #define AT_FDCWD		-100    /* Special value used to indicate
                                            openat should use the current
@@ -38,7 +39,14 @@
 
 #define O_TMPFILE       (__O_TMPFILE | O_DIRECTORY)
 
+#ifndef __PBL__
 int openat(int dirfd, const char *pathname, int flags);
+#else
+static inline int openat(int dirfd, const char *pathname, int flags, ...)
+{
+        return -ENOSYS;
+}
+#endif
 
 static inline int open(const char *pathname, int flags, ...)
 {
diff --git a/include/libfile.h b/include/libfile.h
index f772ff8b6af2..79bef9c75fa7 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -32,7 +32,14 @@ int copy_recursive(const char *src, const char *dst);
 
 int compare_file(const char *f1, const char *f2);
 
+#ifndef __PBL__
 int open_and_lseek(const char *filename, int mode, loff_t pos);
+#else
+static inline int open_and_lseek(const char *filename, int mode, loff_t pos)
+{
+	return -ENOSYS;
+}
+#endif
 
 /* Create a directory and its parents */
 int make_directory(const char *pathname);
diff --git a/include/unistd.h b/include/unistd.h
index f3d2378687e4..7a04bc6443d6 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -4,11 +4,13 @@
 
 #include <linux/types.h>
 #include <fcntl.h>
+#include <errno.h>
 
 #define RW_BUF_SIZE	(unsigned)4096
 
 struct stat;
 
+#ifndef __PBL__
 int unlinkat(int dirfd, const char *pathname, int flags);
 int close(int fd);
 int lstatat(int dirfd, const char *filename, struct stat *s);
@@ -26,6 +28,76 @@ char *pushd(const char *dir);
 int popd(char *dir);
 const char *getcwd(void);
 int ftruncate(int fd, loff_t length);
+#else
+static inline int unlinkat(int dirfd, const char *pathname, int flags)
+{
+	return -ENOSYS;
+}
+static inline int close(int fd)
+{
+	return -ENOSYS;
+}
+static inline int lstatat(int dirfd, const char *filename, struct stat *s)
+{
+	return -ENOSYS;
+}
+static inline int statat(int dirfd, const char *filename, struct stat *s)
+{
+	return -ENOSYS;
+}
+static inline int fstat(int fd, struct stat *s)
+{
+	return -ENOSYS;
+}
+static inline ssize_t read(int fd, void *buf, size_t count)
+{
+	return -ENOSYS;
+}
+static inline ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
+{
+	return -ENOSYS;
+}
+static inline ssize_t write(int fd, const void *buf, size_t count)
+{
+	return -ENOSYS;
+}
+static inline ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset)
+{
+	return -ENOSYS;
+}
+static inline loff_t lseek(int fildes, loff_t offset, int whence)
+{
+	return -ENOSYS;
+}
+static inline int symlink(const char *pathname, const char *newpath)
+{
+	return -ENOSYS;
+}
+static inline int readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz)
+{
+	return -ENOSYS;
+}
+static inline int chdir(const char *pathname)
+{
+	return -ENOSYS;
+}
+static inline char *pushd(const char *dir)
+{
+	return NULL;
+}
+static inline int popd(char *dir)
+{
+	return -ENOSYS;
+}
+static inline const char *getcwd(void)
+{
+	return NULL;
+}
+static inline int ftruncate(int fd, loff_t length)
+{
+	return -ENOSYS;
+}
+#endif
 
 static inline int unlink(const char *pathname)
 {
-- 
2.39.5




  parent reply	other threads:[~2024-10-16  9:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16  9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 01/13] kconfig: add IS_PROPER helper Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 02/13] lib: random: add stubs for PBL Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 03/13] bootsource: stub out when in PBL Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 04/13] crypto: provide crypto_memneq for PBL Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 05/13] cdev: stub out cdev_read/write " Ahmad Fatoum
2024-10-16  9:01 ` Ahmad Fatoum [this message]
2024-10-16  9:01 ` [PATCH 07/13] environment: stub out environment API " Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 08/13] of: stub out live tree API when using PBL Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 09/13] errno: stub out perror/strerror API when built for PBL Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 10/13] xfuncs: stub out " Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 11/13] stdio: stub out basprintf and friends " Ahmad Fatoum
2024-10-16  9:40   ` [PATCH] fixup! errno: stub out perror/strerror API " Ahmad Fatoum
2024-10-16  9:40   ` [PATCH 11/13] stdio: stub out basprintf and friends " Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 12/13] memory: stub out request_barebox_region " Ahmad Fatoum
2024-10-16  9:01 ` [PATCH 13/13] malloc: add PBL stubs Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241016090150.3963002-7-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox