* [PATCH 00/13] Remove dependency on ld --gc-section in PBL
@ 2024-10-16 9:01 Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 01/13] kconfig: add IS_PROPER helper Ahmad Fatoum
` (12 more replies)
0 siblings, 13 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox
We depend on -ffunction-sections -fdata-sections at a lot of places and
fail the link without due to undefined references. This is especially
needed for obj-pbl-y code as the files usually have other functions
depending on barebox proper infrastructure, but that is never called.
This works so far, but breaks for two things: LTO and using PBL on
sandbox. Both I have not managed to get the linker not to complain about
the undefined references in the ultimately unreferenced code.
Therefore, let's solve this a different way: Adjust the relevant headers
to define stubs when built for sandbox.
This has the nice side effect of compile testing the stubs during PBL
build, so forgotten semicolons are more likely to be noticed during
development instead of CI run.
Ahmad Fatoum (13):
kconfig: add IS_PROPER helper
lib: random: add stubs for PBL
bootsource: stub out when in PBL
crypto: provide crypto_memneq for PBL
cdev: stub out cdev_read/write for PBL
libfile: stub out file descriptor API for PBL
environment: stub out environment API for PBL
of: stub out live tree API when using PBL
errno: stub out perror/strerror API when built for PBL
xfuncs: stub out API when built for PBL
stdio: stub out basprintf and friends when built for PBL
memory: stub out request_barebox_region for PBL
malloc: add PBL stubs
common/bootsource.c | 2 +-
crypto/Makefile | 2 +-
include/driver.h | 24 ++++++++++++--
include/environment.h | 2 +-
include/errno.h | 10 ++++++
include/fcntl.h | 8 +++++
include/libfile.h | 7 ++++
include/linux/kconfig.h | 10 ++++++
include/linux/string.h | 7 ++++
include/malloc.h | 37 +++++++++++++++++++++
include/memory.h | 10 ++++++
include/of.h | 2 +-
include/stdio.h | 24 ++++++++++++--
include/stdlib.h | 19 ++++++++++-
include/unistd.h | 72 +++++++++++++++++++++++++++++++++++++++++
include/xfuncs.h | 19 +++++++++++
16 files changed, 246 insertions(+), 9 deletions(-)
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 01/13] kconfig: add IS_PROPER helper
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
@ 2024-10-16 9:01 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 02/13] lib: random: add stubs for PBL Ahmad Fatoum
` (11 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
We depend on -ffunction-sections -fdata-sections at a lot of places and
fail the link without due to undefined references. This is especially
needed for obj-pbl-y code as the files usually have other functions
depending on barebox proper infrastructure, but that is never called.
This works so far, but breaks for two things: LTO and using PBL on
sandbox. Both I have not managed to get the linker not to complain about
the undefined references in the ultimately unreferenced code.
Therefore, let's solve this a different way: Add an IS_PROPER macro and
have the stubs defined when !IS_PROPER.
This has the nice side effect of compile testing the stubs during PBL
build, so forgotten semicolons are more likely to be noticed during
development instead of CI run.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/kconfig.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index 58f68adbbadf..8d31584c0c2a 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -33,4 +33,14 @@
*/
#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
+/*
+ * IS_PROPER(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', or 'm'
+ * and file is being compiled for barebox proper, 0 otherwise.
+ */
+#ifndef __PBL__
+#define IS_PROPER(option) IS_ENABLED(option)
+#else
+#define IS_PROPER(option) 0
+#endif
+
#endif /* __LINUX_KCONFIG_H */
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 02/13] lib: random: add stubs for PBL
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 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 03/13] bootsource: stub out when in PBL Ahmad Fatoum
` (10 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox
From: Ahmad Fatoum <ahmad@a3f.at>
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 we want to fail the build in barebox
proper as before, when HWRNG support is missing.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
include/stdlib.h | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/include/stdlib.h b/include/stdlib.h
index c427cbc87f6e..9d54241cf45d 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -2,6 +2,7 @@
#ifndef __STDLIB_H
#define __STDLIB_H
+#include <linux/bug.h>
#include <types.h>
#include <malloc.h>
@@ -13,11 +14,27 @@ unsigned int rand(void);
/* set the seed for rand () */
void srand(unsigned int seed);
+struct hwrng;
+
/* fill a buffer with pseudo-random data */
+#ifndef __PBL__
void get_random_bytes(void *buf, int len);
int get_crypto_bytes(void *buf, int len);
-struct hwrng;
int hwrng_get_crypto_bytes(struct hwrng *rng, void *buf, int len);
+#else
+static inline void get_random_bytes(void *buf, int len)
+{
+ BUG();
+}
+static inline int get_crypto_bytes(void *buf, int len)
+{
+ return -ENOSYS;
+}
+static inline int hwrng_get_crypto_bytes(struct hwrng *rng, void *buf, int len)
+{
+ return -ENOSYS;
+}
+#endif
static inline u32 random32(void)
{
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 03/13] bootsource: stub out when in PBL
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 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 04/13] crypto: provide crypto_memneq for PBL Ahmad Fatoum
` (9 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
To optimize out calls to undefined functions in PBL at compile-time
instead of link time, let's use IS_PROPER instead of IS_ENABELED(),
so the remainder of the code is skipped in PBL build instead of relying
on linker garbage collection.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/bootsource.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/bootsource.c b/common/bootsource.c
index 6808c9c51d88..ef90bd8d7dc4 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -158,7 +158,7 @@ int bootsource_of_alias_xlate(enum bootsource src, int instance)
struct device_node *np;
int alias_id;
- if (!IS_ENABLED(CONFIG_OFDEVICE))
+ if (!IS_PROPER(CONFIG_OFDEVICE))
return BOOTSOURCE_INSTANCE_UNKNOWN;
if (src == BOOTSOURCE_UNKNOWN ||
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 04/13] crypto: provide crypto_memneq for PBL
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (2 preceding siblings ...)
2024-10-16 9:01 ` [PATCH 03/13] bootsource: stub out when in PBL Ahmad Fatoum
@ 2024-10-16 9:01 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 05/13] cdev: stub out cdev_read/write " Ahmad Fatoum
` (8 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
crypto_memneq has no external dependency and can be equally useful in
PBL, so build it there as well for use by early code.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
crypto/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/crypto/Makefile b/crypto/Makefile
index 0354e4568373..7148aecb4a8e 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_DIGEST_SHA256_GENERIC) += sha2.o
pbl-y += sha2.o digest.o
obj-$(CONFIG_DIGEST_SHA384_GENERIC) += sha4.o
obj-$(CONFIG_DIGEST_SHA512_GENERIC) += sha4.o
-obj-y += memneq.o
+obj-pbl-y += memneq.o
obj-$(CONFIG_CRYPTO_PBKDF2) += pbkdf2.o
obj-$(CONFIG_CRYPTO_RSA) += rsa.o
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 05/13] cdev: stub out cdev_read/write for PBL
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (3 preceding siblings ...)
2024-10-16 9:01 ` [PATCH 04/13] crypto: provide crypto_memneq for PBL Ahmad Fatoum
@ 2024-10-16 9:01 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 06/13] libfile: stub out file descriptor API " Ahmad Fatoum
` (7 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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 cdev support is always available
in barebox proper.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/driver.h | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/include/driver.h b/include/driver.h
index c4067d531cc7..04d7125ac786 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -14,6 +14,7 @@
#include <device.h>
#include <of.h>
#include <init.h>
+#include <errno.h>
#include <filetype.h>
#define FORMAT_DRIVER_NAME_ID "%s%d"
@@ -514,21 +515,40 @@ int devfs_create_link(struct cdev *, const char *name);
int devfs_remove(struct cdev *);
int cdev_find_free_index(const char *);
struct cdev *device_find_partition(struct device *dev, const char *name);
-struct cdev *cdev_by_name(const char *filename);
struct cdev *lcdev_by_name(const char *filename);
struct cdev *cdev_readlink(struct cdev *cdev);
struct cdev *cdev_by_device_node(struct device_node *node);
struct cdev *cdev_by_partuuid(const char *partuuid);
struct cdev *cdev_by_diskuuid(const char *partuuid);
-struct cdev *cdev_open_by_name(const char *name, unsigned long flags);
struct cdev *cdev_create_loop(const char *path, ulong flags, loff_t offset);
void cdev_remove_loop(struct cdev *cdev);
int cdev_open(struct cdev *, unsigned long flags);
int cdev_fdopen(struct cdev *cdev, unsigned long flags);
int cdev_close(struct cdev *cdev);
int cdev_flush(struct cdev *cdev);
+#ifndef __PBL__
ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags);
ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags);
+struct cdev *cdev_by_name(const char *filename);
+struct cdev *cdev_open_by_name(const char *name, unsigned long flags);
+#else
+static inline ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
+{
+ return -ENOSYS;
+}
+static inline ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, loff_t offset, ulong flags)
+{
+ return -ENOSYS;
+}
+static inline struct cdev *cdev_by_name(const char *filename)
+{
+ return NULL;
+}
+static inline struct cdev *cdev_open_by_name(const char *name, unsigned long flags)
+{
+ return NULL;
+}
+#endif
int cdev_ioctl(struct cdev *cdev, unsigned int cmd, void *buf);
int cdev_erase(struct cdev *cdev, loff_t count, loff_t offset);
int cdev_lseek(struct cdev*, loff_t);
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 06/13] libfile: stub out file descriptor API for PBL
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (4 preceding siblings ...)
2024-10-16 9:01 ` [PATCH 05/13] cdev: stub out cdev_read/write " Ahmad Fatoum
@ 2024-10-16 9:01 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 07/13] environment: stub out environment " Ahmad Fatoum
` (6 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 07/13] environment: stub out environment API for PBL
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (5 preceding siblings ...)
2024-10-16 9:01 ` [PATCH 06/13] libfile: stub out file descriptor API " Ahmad Fatoum
@ 2024-10-16 9:01 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 08/13] of: stub out live tree API when using PBL Ahmad Fatoum
` (5 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/environment.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/environment.h b/include/environment.h
index 8b143c16b7ad..d8871109362a 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -29,7 +29,7 @@ struct env_context *get_current_context(void);
char *var_val(struct variable_d *);
char *var_name(struct variable_d *);
-#ifdef CONFIG_ENVIRONMENT_VARIABLES
+#if IS_PROPER(CONFIG_ENVIRONMENT_VARIABLES)
const char *getenv(const char *);
int setenv(const char *, const char *);
int pr_setenv(const char *, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 08/13] of: stub out live tree API when using PBL
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (6 preceding siblings ...)
2024-10-16 9:01 ` [PATCH 07/13] environment: stub out environment " Ahmad Fatoum
@ 2024-10-16 9:01 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 09/13] errno: stub out perror/strerror API when built for PBL Ahmad Fatoum
` (4 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/of.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/of.h b/include/of.h
index 05e92d41b9f0..46eb18a91576 100644
--- a/include/of.h
+++ b/include/of.h
@@ -131,7 +131,7 @@ struct cdev;
/* Maximum score returned by of_device_is_compatible() */
#define OF_DEVICE_COMPATIBLE_MAX_SCORE (INT_MAX / 2)
-#ifdef CONFIG_OFTREE
+#if IS_PROPER(CONFIG_OFTREE)
extern struct device_node *of_read_file(const char *filename);
extern struct of_reserve_map *of_get_reserve_map(void);
extern int of_bus_n_addr_cells(struct device_node *np);
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 09/13] errno: stub out perror/strerror API when built for PBL
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (7 preceding siblings ...)
2024-10-16 9:01 ` [PATCH 08/13] of: stub out live tree API when using PBL Ahmad Fatoum
@ 2024-10-16 9:01 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 10/13] xfuncs: stub out " Ahmad Fatoum
` (3 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/errno.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/errno.h b/include/errno.h
index 12e526a0d7ed..9a008e375221 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -7,8 +7,18 @@
extern int errno;
+#ifndef __PBL__
void perror(const char *s);
const char *strerror(int errnum);
+#else
+static inline void perror(const char *s)
+{
+}
+static inline const char *strerror(int errnum)
+{
+ return NULL;
+}
+#endif
static inline int errno_set(int err)
{
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 10/13] xfuncs: stub out API when built for PBL
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (8 preceding siblings ...)
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 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 11/13] stdio: stub out basprintf and friends " Ahmad Fatoum
` (2 subsequent siblings)
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/xfuncs.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/include/xfuncs.h b/include/xfuncs.h
index 9e09b88141a1..e6a781ef708e 100644
--- a/include/xfuncs.h
+++ b/include/xfuncs.h
@@ -4,10 +4,12 @@
#include <linux/types.h>
#include <linux/compiler.h>
+#include <linux/bug.h>
#include <stdarg.h>
#include <wchar.h>
#include <malloc.h>
+#ifndef __PBL__
void *xmalloc(size_t size) __xalloc_size(1);
void *xrealloc(void *ptr, size_t size) __xrealloc_size(2);
void *xzalloc(size_t size) __xalloc_size(1);
@@ -22,4 +24,21 @@ wchar_t *xstrdup_wchar(const wchar_t *src);
wchar_t *xstrdup_char_to_wchar(const char *src);
char *xstrdup_wchar_to_char(const wchar_t *src);
+#else
+
+static inline void *xmalloc(size_t size) { BUG(); }
+static inline void *xrealloc(void *ptr, size_t size) { BUG(); }
+static inline void *xzalloc(size_t size) { BUG(); }
+static inline char *xstrdup(const char *s) { BUG(); }
+static inline char *xstrndup(const char *s, size_t size) { BUG(); }
+static inline void* xmemalign(size_t alignment, size_t bytes) { BUG(); }
+static inline void* xmemdup(const void *orig, size_t size) { BUG(); }
+static inline char *xasprintf(const char *fmt, ...) { BUG(); }
+static inline char *xvasprintf(const char *fmt, va_list ap) { BUG(); }
+
+static inline wchar_t *xstrdup_wchar(const wchar_t *src) { BUG(); }
+static inline wchar_t *xstrdup_char_to_wchar(const char *src) { BUG(); }
+static inline char *xstrdup_wchar_to_char(const wchar_t *src) { BUG(); }
+#endif
+
#endif /* __XFUNCS_H */
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 11/13] stdio: stub out basprintf and friends when built for PBL
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (9 preceding siblings ...)
2024-10-16 9:01 ` [PATCH 10/13] xfuncs: stub out " Ahmad Fatoum
@ 2024-10-16 9:01 ` 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
12 siblings, 2 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/stdio.h | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/include/stdio.h b/include/stdio.h
index 1ed7e1d3e38b..64deec64e66c 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -17,12 +17,32 @@ int sprintf(char *buf, const char *fmt, ...) __attribute__ ((format(__printf__,
int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4)));
int scnprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4)));
int vsprintf(char *buf, const char *fmt, va_list args);
+int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
+int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
+
+#ifndef __PBL__
char *basprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
int asprintf(char **strp, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
char *bvasprintf(const char *fmt, va_list ap);
int vasprintf(char **strp, const char *fmt, va_list ap);
-int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
-int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
+#else
+static inline char *basprintf(const char *fmt, ...)
+{
+ return NULL;
+}
+static inline int asprintf(char **strp, const char *fmt, ...)
+{
+ return -ENOMEM;
+}
+static inline char *bvasprintf(const char *fmt, va_list ap)
+{
+ return NULL;
+}
+static inline int vasprintf(char **strp, const char *fmt, va_list ap)
+{
+ return -ENOMEM;
+}
+#endif
#ifdef CONFIG_ARCH_HAS_CTRLC
int arch_ctrlc(void);
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 12/13] memory: stub out request_barebox_region for PBL
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (10 preceding siblings ...)
2024-10-16 9:01 ` [PATCH 11/13] stdio: stub out basprintf and friends " Ahmad Fatoum
@ 2024-10-16 9:01 ` Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 13/13] malloc: add PBL stubs Ahmad Fatoum
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/memory.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/memory.h b/include/memory.h
index 571effd3b0d6..d5934e3ec533 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -63,8 +63,18 @@ static inline u64 memory_sdram_size(unsigned int cols,
void register_barebox_area(resource_size_t start, resource_size_t size);
+#ifndef __PBL__
struct resource *request_barebox_region(const char *name,
resource_size_t start,
resource_size_t size);
+#else
+static inline struct resource *request_barebox_region(const char *name,
+ resource_size_t start,
+ resource_size_t size)
+{
+
+ return ERR_PTR(-ENOSYS);
+}
+#endif
#endif
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 13/13] malloc: add PBL stubs
2024-10-16 9:01 [PATCH 00/13] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (11 preceding siblings ...)
2024-10-16 9:01 ` [PATCH 12/13] memory: stub out request_barebox_region " Ahmad Fatoum
@ 2024-10-16 9:01 ` Ahmad Fatoum
12 siblings, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:01 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/string.h | 7 +++++++
include/malloc.h | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/include/linux/string.h b/include/linux/string.h
index 3b8775c9a57d..38077da95d13 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -161,7 +161,14 @@ static inline const char *kbasename(const char *path)
}
#endif
+#ifndef __PBL__
void *memdup(const void *, size_t);
+#else
+static inline void *memdup(const void *buf, size_t size)
+{
+ return NULL;
+}
+#endif
#define memdup_array(arr, count) memdup(arr, array_size(count, sizeof(*arr)));
diff --git a/include/malloc.h b/include/malloc.h
index fc0c94855e05..682f724fb4fa 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,6 +5,7 @@
#include <linux/compiler.h>
#include <types.h>
+#ifndef __PBL__
void *malloc(size_t) __alloc_size(1);
size_t malloc_usable_size(void *);
void free(void *);
@@ -16,5 +17,41 @@ void malloc_stats(void);
void *sbrk(ptrdiff_t increment);
int mem_malloc_is_initialized(void);
+#else
+static inline void *malloc(size_t nbytes)
+{
+ return NULL;
+}
+static inline void free(void *buf)
+{
+}
+static inline void free_sensitive(void *buf)
+{
+}
+static inline void *realloc(void *orig, size_t nbytes)
+{
+ return NULL;
+}
+static inline void *memalign(size_t align, size_t size)
+{
+ return NULL;
+}
+static inline void *calloc(size_t num, size_t size)
+{
+ return NULL;
+}
+static inline void malloc_stats(void)
+{
+}
+static inline void *sbrk(ptrdiff_t increment)
+{
+ return NULL;
+}
+
+static inline int mem_malloc_is_initialized(void)
+{
+ return 0;
+}
+#endif
#endif /* __MALLOC_H */
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH] fixup! errno: stub out perror/strerror API when built for PBL
2024-10-16 9:01 ` [PATCH 11/13] stdio: stub out basprintf and friends " Ahmad Fatoum
@ 2024-10-16 9:40 ` Ahmad Fatoum
2024-10-16 9:40 ` [PATCH 11/13] stdio: stub out basprintf and friends " Ahmad Fatoum
1 sibling, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:40 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Otherwise some compilers may complain that the result is passed directly
to printf("%s").
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/errno.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/errno.h b/include/errno.h
index 9a008e375221..ea6a76a354ac 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -16,7 +16,7 @@ static inline void perror(const char *s)
}
static inline const char *strerror(int errnum)
{
- return NULL;
+ return "unknown error";
}
#endif
--
2.39.5
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 11/13] stdio: stub out basprintf and friends when built for PBL
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 ` Ahmad Fatoum
1 sibling, 0 replies; 16+ messages in thread
From: Ahmad Fatoum @ 2024-10-16 9:40 UTC (permalink / raw)
To: barebox
On 16.10.24 11:01, Ahmad Fatoum wrote:
> 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.
This one patch could use some more love, so please drop it.
The other 12 (+ fixup) pass CI ok.
Thanks,
Ahmad
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> include/stdio.h | 24 ++++++++++++++++++++++--
> 1 file changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/include/stdio.h b/include/stdio.h
> index 1ed7e1d3e38b..64deec64e66c 100644
> --- a/include/stdio.h
> +++ b/include/stdio.h
> @@ -17,12 +17,32 @@ int sprintf(char *buf, const char *fmt, ...) __attribute__ ((format(__printf__,
> int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4)));
> int scnprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4)));
> int vsprintf(char *buf, const char *fmt, va_list args);
> +int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
> +int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
> +
> +#ifndef __PBL__
> char *basprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
> int asprintf(char **strp, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
> char *bvasprintf(const char *fmt, va_list ap);
> int vasprintf(char **strp, const char *fmt, va_list ap);
> -int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
> -int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
> +#else
> +static inline char *basprintf(const char *fmt, ...)
> +{
> + return NULL;
> +}
> +static inline int asprintf(char **strp, const char *fmt, ...)
> +{
> + return -ENOMEM;
> +}
> +static inline char *bvasprintf(const char *fmt, va_list ap)
> +{
> + return NULL;
> +}
> +static inline int vasprintf(char **strp, const char *fmt, va_list ap)
> +{
> + return -ENOMEM;
> +}
> +#endif
>
> #ifdef CONFIG_ARCH_HAS_CTRLC
> int arch_ctrlc(void);
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2024-10-16 9:47 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 06/13] libfile: stub out file descriptor API " Ahmad Fatoum
2024-10-16 9:01 ` [PATCH 07/13] environment: stub out environment " 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox