* [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL
@ 2024-11-25 15:12 Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 01/16] scripts: include: add definitions for printk and BUG() Ahmad Fatoum
` (15 more replies)
0 siblings, 16 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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.
v1 -> v2:
- squash fixes noticed by CI (strerror, PBL_CONSOLE)
- define printk/BUG for host tools to fix compile error
- replace IS_PROPER macro with new global IN_PROPER macro
- use IN_PROPER where appropriate
Ahmad Fatoum (16):
scripts: include: add definitions for printk and BUG()
xfuncs: include <malloc.h> for free definition
pbl: define IN_PBL & IN_PROPER macros globally
treewide: replace inverted check for PBL with new IN_PROPER macro
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
arch/arm/mach-imx/romapi.c | 2 +-
arch/arm/mach-omap/omap3_generic.c | 2 +-
arch/riscv/include/asm/unwind.h | 2 +-
common/bootsource.c | 2 +-
crypto/Makefile | 2 +-
drivers/pinctrl/imx-iomux-v1.c | 2 +-
fs/fat/ff.h | 2 +-
include/abort.h | 2 +-
include/dma.h | 2 +-
include/driver.h | 24 +++++++++-
include/environment.h | 2 +-
include/errno.h | 10 +++++
include/fcntl.h | 8 ++++
include/libfile.h | 7 +++
include/linux/iopoll.h | 4 +-
include/linux/kasan.h | 2 +-
include/linux/kconfig.h | 8 ++++
include/linux/list.h | 2 +-
include/linux/printk.h | 4 +-
include/linux/string.h | 7 +++
include/malloc.h | 37 +++++++++++++++
include/memory.h | 10 +++++
include/of.h | 2 +-
include/pbl.h | 6 ---
include/printk.h | 4 +-
include/stdio.h | 28 ++++++++++--
include/stdlib.h | 19 +++++++-
include/unistd.h | 72 ++++++++++++++++++++++++++++++
include/xfuncs.h | 20 +++++++++
include/zero_page.h | 2 +-
lib/vsprintf.c | 4 +-
scripts/include/asm-generic/bug.h | 14 ++++++
scripts/include/linux/bug.h | 1 +
scripts/include/printk.h | 9 ++++
34 files changed, 289 insertions(+), 35 deletions(-)
create mode 100644 scripts/include/asm-generic/bug.h
create mode 100644 scripts/include/linux/bug.h
create mode 100644 scripts/include/printk.h
--
2.39.5
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2 01/16] scripts: include: add definitions for printk and BUG()
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 02/16] xfuncs: include <malloc.h> for free definition Ahmad Fatoum
` (14 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
This is required for building files that are built for both host and
target systems and use these headers.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
scripts/include/asm-generic/bug.h | 14 ++++++++++++++
scripts/include/linux/bug.h | 1 +
scripts/include/printk.h | 9 +++++++++
3 files changed, 24 insertions(+)
create mode 100644 scripts/include/asm-generic/bug.h
create mode 100644 scripts/include/linux/bug.h
create mode 100644 scripts/include/printk.h
diff --git a/scripts/include/asm-generic/bug.h b/scripts/include/asm-generic/bug.h
new file mode 100644
index 000000000000..c53ced628fcc
--- /dev/null
+++ b/scripts/include/asm-generic/bug.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef _ASM_GENERIC_BUG_H
+#define _ASM_GENERIC_BUG_H
+
+#include <printk.h>
+#include <stdlib.h>
+
+#define BUG() do { \
+ printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
+ exit(41); \
+} while (0)
+
+#endif
diff --git a/scripts/include/linux/bug.h b/scripts/include/linux/bug.h
new file mode 100644
index 000000000000..b12fd89e42e9
--- /dev/null
+++ b/scripts/include/linux/bug.h
@@ -0,0 +1 @@
+#include <asm-generic/bug.h>
diff --git a/scripts/include/printk.h b/scripts/include/printk.h
new file mode 100644
index 000000000000..363d32f2e5cb
--- /dev/null
+++ b/scripts/include/printk.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __PRINTK_H
+#define __PRINTK_H
+
+#include <stdio.h>
+
+#define printk printf
+
+#endif
--
2.39.5
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2 02/16] xfuncs: include <malloc.h> for free definition
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 01/16] scripts: include: add definitions for printk and BUG() Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 03/16] pbl: define IN_PBL & IN_PROPER macros globally Ahmad Fatoum
` (13 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
xfuncs.h defines all the functions that panic on out-of-memory
condition, but doesn't actually define free, so let's fix that by
importing <malloc.h> inside.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/xfuncs.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/xfuncs.h b/include/xfuncs.h
index 60ec220bd9b8..9e09b88141a1 100644
--- a/include/xfuncs.h
+++ b/include/xfuncs.h
@@ -6,6 +6,7 @@
#include <linux/compiler.h>
#include <stdarg.h>
#include <wchar.h>
+#include <malloc.h>
void *xmalloc(size_t size) __xalloc_size(1);
void *xrealloc(void *ptr, size_t size) __xrealloc_size(2);
--
2.39.5
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2 03/16] pbl: define IN_PBL & IN_PROPER macros globally
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 01/16] scripts: include: add definitions for printk and BUG() Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 02/16] xfuncs: include <malloc.h> for free definition Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 04/16] treewide: replace inverted check for PBL with new IN_PROPER macro Ahmad Fatoum
` (12 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
While we define the macro __PBL__ globally for all PBL files, files that
want to avoid use of #ifdef must explicitly include <pbl.h> to get the
IN_PBL macro definition. Let's add an IN_PROPER macro that's the inverse
of IN_PBL and in preparation for adding IN_PBL to a lot more places,
let's move this definition into <linux/kconfig.h>, which is always
included and thus the macro becomes available globally everywhere.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/kconfig.h | 8 ++++++++
include/pbl.h | 6 ------
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index 58f68adbbadf..4e9c77b964a7 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -33,4 +33,12 @@
*/
#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
+#ifdef __PBL__
+#define IN_PBL 1
+#define IN_PROPER 0
+#else
+#define IN_PBL 0
+#define IN_PROPER 1
+#endif
+
#endif /* __LINUX_KCONFIG_H */
diff --git a/include/pbl.h b/include/pbl.h
index 0633e340bef3..abac3458593a 100644
--- a/include/pbl.h
+++ b/include/pbl.h
@@ -6,12 +6,6 @@
#ifndef __PBL_H__
#define __PBL_H__
-#ifdef __PBL__
-#define IN_PBL 1
-#else
-#define IN_PBL 0
-#endif
-
#ifndef __ASSEMBLY__
#include <linux/types.h>
--
2.39.5
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2 04/16] treewide: replace inverted check for PBL with new IN_PROPER macro
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (2 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 03/16] pbl: define IN_PBL & IN_PROPER macros globally Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 05/16] lib: random: add stubs for PBL Ahmad Fatoum
` (11 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Guarding code behind an #if IN_PROPER is easier to read than #ifndef __PBL__,
so let's use it where appropriate.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
arch/arm/mach-imx/romapi.c | 2 +-
arch/arm/mach-omap/omap3_generic.c | 2 +-
arch/riscv/include/asm/unwind.h | 2 +-
drivers/pinctrl/imx-iomux-v1.c | 2 +-
fs/fat/ff.h | 2 +-
include/abort.h | 2 +-
include/dma.h | 2 +-
include/linux/iopoll.h | 4 ++--
include/linux/kasan.h | 2 +-
include/linux/list.h | 2 +-
include/linux/printk.h | 4 ++--
include/printk.h | 4 ++--
include/stdio.h | 4 ++--
include/zero_page.h | 2 +-
lib/vsprintf.c | 4 ++--
15 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/arch/arm/mach-imx/romapi.c b/arch/arm/mach-imx/romapi.c
index 155e706437f7..10af42f28a76 100644
--- a/arch/arm/mach-imx/romapi.c
+++ b/arch/arm/mach-imx/romapi.c
@@ -256,7 +256,7 @@ const u32 *imx8m_get_bootrom_log(void)
return (u32 *)rom_log_addr;
}
- if (!IN_PBL)
+ if (IN_PROPER)
return imx8m_scratch_get_bootrom_log();
return NULL;
diff --git a/arch/arm/mach-omap/omap3_generic.c b/arch/arm/mach-omap/omap3_generic.c
index 8230b37619dc..d1b57dffd0cf 100644
--- a/arch/arm/mach-omap/omap3_generic.c
+++ b/arch/arm/mach-omap/omap3_generic.c
@@ -553,7 +553,7 @@ const struct gpmc_config omap3_nand_cfg = {
.size = GPMC_SIZE_16M,
};
-#ifndef __PBL__
+#if IN_PROPER
static int omap3_gpio_init(void)
{
add_generic_device("omap-gpio", 0, NULL, OMAP3_GPIO1_BASE,
diff --git a/arch/riscv/include/asm/unwind.h b/arch/riscv/include/asm/unwind.h
index 00f7845147b1..4e8beb988070 100644
--- a/arch/riscv/include/asm/unwind.h
+++ b/arch/riscv/include/asm/unwind.h
@@ -4,7 +4,7 @@
struct pt_regs;
-#if defined CONFIG_RISCV_UNWIND && !defined __PBL__
+#if defined CONFIG_RISCV_UNWIND && IN_PROPER
void unwind_backtrace(const struct pt_regs *regs);
#else
static inline void unwind_backtrace(const struct pt_regs *regs)
diff --git a/drivers/pinctrl/imx-iomux-v1.c b/drivers/pinctrl/imx-iomux-v1.c
index a0878fa9eb85..ac98f4dcb763 100644
--- a/drivers/pinctrl/imx-iomux-v1.c
+++ b/drivers/pinctrl/imx-iomux-v1.c
@@ -115,7 +115,7 @@ void imx_gpio_mode(void __iomem *base, int gpio_mode)
}
}
-#ifndef __PBL__
+#if IN_PROPER
/*
* MUX_ID format defines
diff --git a/fs/fat/ff.h b/fs/fat/ff.h
index c961de46e1f4..e1a7d029efe8 100644
--- a/fs/fat/ff.h
+++ b/fs/fat/ff.h
@@ -17,7 +17,7 @@
#ifndef _FATFS
#define _FATFS 8237 /* Revision ID */
-#ifndef __PBL__
+#if IN_PROPER
#ifdef CONFIG_FS_FAT_LFN
#define FS_FAT_LFN 1
diff --git a/include/abort.h b/include/abort.h
index 039500b04d0b..95db1b54d6d9 100644
--- a/include/abort.h
+++ b/include/abort.h
@@ -2,7 +2,7 @@
#ifndef __ABORT_H
#define __ABORT_H
-#if defined CONFIG_ARCH_HAS_DATA_ABORT_MASK && !defined __PBL__
+#if defined CONFIG_ARCH_HAS_DATA_ABORT_MASK && IN_PROPER
/*
* data_abort_mask - ignore data aborts
diff --git a/include/dma.h b/include/dma.h
index 5a82637e24ac..53cb50b707f4 100644
--- a/include/dma.h
+++ b/include/dma.h
@@ -90,7 +90,7 @@ void arch_sync_dma_for_device(void *vaddr, size_t size,
enum dma_data_direction dir);
#endif
-#ifndef __PBL__
+#if IN_PROPER
void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
size_t size, enum dma_data_direction dir);
diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h
index c7dcaec38237..9350a3d05007 100644
--- a/include/linux/iopoll.h
+++ b/include/linux/iopoll.h
@@ -32,13 +32,13 @@
#define read_poll_timeout(op, val, cond, timeout_us, args...) \
({ \
uint64_t start = 0; \
- if (!IN_PBL && (timeout_us) != 0) \
+ if (IN_PROPER && (timeout_us) != 0) \
start = get_time_ns(); \
for (;;) { \
(val) = op(args); \
if (cond) \
break; \
- if (!IN_PBL && (timeout_us) != 0 && \
+ if (IN_PROPER && (timeout_us) != 0 && \
is_timeout(start, ((timeout_us) * USECOND))) { \
(val) = op(args); \
break; \
diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index 2dea347c40ae..8afdab7c9d4b 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -45,7 +45,7 @@
extern unsigned long kasan_shadow_start;
extern unsigned long kasan_shadow_base;
-#if defined(CONFIG_KASAN) && !defined(__PBL__)
+#if defined(CONFIG_KASAN) && IN_PROPER
static inline void *kasan_mem_to_shadow(const void *addr)
{
diff --git a/include/linux/list.h b/include/linux/list.h
index e28f54a0d413..35b3f573806a 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -36,7 +36,7 @@ static inline void INIT_LIST_HEAD(struct list_head *list)
list->prev = list;
}
-#if defined(CONFIG_DEBUG_LIST) && !defined(__PBL__)
+#if defined(CONFIG_DEBUG_LIST) && IN_PROPER
extern bool __list_add_valid_or_report(struct list_head *new,
struct list_head *prev,
struct list_head *next);
diff --git a/include/linux/printk.h b/include/linux/printk.h
index 07403ea60cb7..9fdf97507483 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -39,8 +39,8 @@ static inline int dev_printf(int level, const struct device *dev,
}
#endif
-#if (!defined(__PBL__) && !defined(CONFIG_CONSOLE_NONE)) || \
- (defined(__PBL__) && defined(CONFIG_PBL_CONSOLE))
+#if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
+ (IN_PBL && defined(CONFIG_PBL_CONSOLE))
int pr_print(int level, const char *format, ...)
__attribute__ ((format(__printf__, 2, 3)));
#else
diff --git a/include/printk.h b/include/printk.h
index bf9645249dae..d0e56e1994a2 100644
--- a/include/printk.h
+++ b/include/printk.h
@@ -16,8 +16,8 @@ struct device;
#define KERN_DEBUG "" /* debug-level messages */
#define KERN_CONT ""
-#if (!defined(__PBL__) && !defined(CONFIG_CONSOLE_NONE)) || \
- (defined(__PBL__) && defined(CONFIG_PBL_CONSOLE))
+#if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
+ (IN_PBL && defined(CONFIG_PBL_CONSOLE))
int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
#else
static int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
diff --git a/include/stdio.h b/include/stdio.h
index 1ed7e1d3e38b..4edadf5c16be 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -82,8 +82,8 @@ static inline void ctrlc_handled(void)
char *size_human_readable(unsigned long long size);
int readline(const char *prompt, char *buf, int len);
-#if (!defined(__PBL__) && !defined(CONFIG_CONSOLE_NONE)) || \
- (defined(__PBL__) && defined(CONFIG_PBL_CONSOLE))
+#if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
+ (IN_PBL && defined(CONFIG_PBL_CONSOLE))
static inline int puts(const char *s)
{
return console_puts(CONSOLE_STDOUT, s);
diff --git a/include/zero_page.h b/include/zero_page.h
index 79e0f22c7b5b..067f39a7ee96 100644
--- a/include/zero_page.h
+++ b/include/zero_page.h
@@ -4,7 +4,7 @@
#include <common.h>
-#if defined CONFIG_ARCH_HAS_ZERO_PAGE && defined CONFIG_MMU && !defined __PBL__
+#if defined CONFIG_ARCH_HAS_ZERO_PAGE && defined CONFIG_MMU && IN_PROPER
/*
* zero_page_faulting - fault when accessing the zero page
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 1b7d568e8f0c..e421a4352a12 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -251,7 +251,7 @@ static char *raw_pointer(char *buf, const char *end, const void *ptr, int field_
return number(buf, end, (unsigned long) ptr, 16, field_width, precision, flags);
}
-#ifndef __PBL__
+#if IN_PROPER
static char *symbol_string(char *buf, const char *end, const void *ptr, int field_width,
int precision, int flags)
{
@@ -727,7 +727,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
continue;
case 's':
- if (IS_ENABLED(CONFIG_PRINTF_WCHAR) && !IN_PBL && qualifier == 'l')
+ if (IS_ENABLED(CONFIG_PRINTF_WCHAR) && IN_PROPER && qualifier == 'l')
str = wstring(str, end, va_arg(args, wchar_t *),
field_width, precision, flags);
else
--
2.39.5
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2 05/16] lib: random: add stubs for PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (3 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 04/16] treewide: replace inverted check for PBL with new IN_PROPER macro Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 06/16] bootsource: stub out when in PBL Ahmad Fatoum
` (10 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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 we want to fail the build in barebox
proper as before, when HWRNG support is missing.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/stdlib.h | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/include/stdlib.h b/include/stdlib.h
index c427cbc87f6e..20bdc0491e3c 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 */
+#if IN_PROPER
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] 17+ messages in thread
* [PATCH v2 06/16] bootsource: stub out when in PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (4 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 05/16] lib: random: add stubs for PBL Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 07/16] crypto: provide crypto_memneq for PBL Ahmad Fatoum
` (9 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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..d82bb5f18c52 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_ENABLED(CONFIG_OFDEVICE) || IN_PBL)
return BOOTSOURCE_INSTANCE_UNKNOWN;
if (src == BOOTSOURCE_UNKNOWN ||
--
2.39.5
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2 07/16] crypto: provide crypto_memneq for PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (5 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 06/16] bootsource: stub out when in PBL Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 08/16] cdev: stub out cdev_read/write " Ahmad Fatoum
` (8 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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] 17+ messages in thread
* [PATCH v2 08/16] cdev: stub out cdev_read/write for PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (6 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 07/16] crypto: provide crypto_memneq for PBL Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 09/16] libfile: stub out file descriptor API " Ahmad Fatoum
` (7 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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..3aef385bc837 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);
+#if IN_PROPER
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] 17+ messages in thread
* [PATCH v2 09/16] libfile: stub out file descriptor API for PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (7 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 08/16] cdev: stub out cdev_read/write " Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 10/16] environment: stub out environment " Ahmad Fatoum
` (6 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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..f3694c2bba5f 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)
+#if IN_PROPER
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..bf775b022dc4 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);
+#if IN_PROPER
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..aad67ad30f84 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;
+#if IN_PROPER
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] 17+ messages in thread
* [PATCH v2 10/16] environment: stub out environment API for PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (8 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 09/16] libfile: stub out file descriptor API " Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 11/16] of: stub out live tree API when using PBL Ahmad Fatoum
` (5 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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..bd863ad3f425 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_ENABLED(CONFIG_ENVIRONMENT_VARIABLES) && IN_PROPER
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] 17+ messages in thread
* [PATCH v2 11/16] of: stub out live tree API when using PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (9 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 10/16] environment: stub out environment " Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 12/16] errno: stub out perror/strerror API when built for PBL Ahmad Fatoum
` (4 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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..3d24e17e43a0 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_ENABLED(CONFIG_OFTREE) && IN_PROPER
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] 17+ messages in thread
* [PATCH v2 12/16] errno: stub out perror/strerror API when built for PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (10 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 11/16] of: stub out live tree API when using PBL Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 13/16] xfuncs: stub out " Ahmad Fatoum
` (3 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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..fd358e1c1103 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -7,8 +7,18 @@
extern int errno;
+#if IN_PROPER
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 "unknown error";
+}
+#endif
static inline int errno_set(int err)
{
--
2.39.5
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2 13/16] xfuncs: stub out API when built for PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (11 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 12/16] errno: stub out perror/strerror API when built for PBL Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 14/16] stdio: stub out basprintf and friends " Ahmad Fatoum
` (2 subsequent siblings)
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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..f0aca6de76b3 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>
+#if IN_PROPER || !defined(__BAREBOX__)
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] 17+ messages in thread
* [PATCH v2 14/16] stdio: stub out basprintf and friends when built for PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (12 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 13/16] xfuncs: stub out " Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 15/16] memory: stub out request_barebox_region " Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 16/16] malloc: add PBL stubs Ahmad Fatoum
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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 4edadf5c16be..03cd3d281890 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);
+
+#if IN_PROPER || defined(CONFIG_PBL_CONSOLE)
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] 17+ messages in thread
* [PATCH v2 15/16] memory: stub out request_barebox_region for PBL
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (13 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 14/16] stdio: stub out basprintf and friends " Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 16/16] malloc: add PBL stubs Ahmad Fatoum
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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..8c330e65c012 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);
+#if IN_PROPER
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] 17+ messages in thread
* [PATCH v2 16/16] malloc: add PBL stubs
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
` (14 preceding siblings ...)
2024-11-25 15:12 ` [PATCH v2 15/16] memory: stub out request_barebox_region " Ahmad Fatoum
@ 2024-11-25 15:12 ` Ahmad Fatoum
15 siblings, 0 replies; 17+ messages in thread
From: Ahmad Fatoum @ 2024-11-25 15:12 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..5d5824b61bf0 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -161,7 +161,14 @@ static inline const char *kbasename(const char *path)
}
#endif
+#if IN_PROPER
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..a823ce8c8462 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,6 +5,7 @@
#include <linux/compiler.h>
#include <types.h>
+#if IN_PROPER
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] 17+ messages in thread
end of thread, other threads:[~2024-11-25 15:17 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-25 15:12 [PATCH v2 00/16] Remove dependency on ld --gc-section in PBL Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 01/16] scripts: include: add definitions for printk and BUG() Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 02/16] xfuncs: include <malloc.h> for free definition Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 03/16] pbl: define IN_PBL & IN_PROPER macros globally Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 04/16] treewide: replace inverted check for PBL with new IN_PROPER macro Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 05/16] lib: random: add stubs for PBL Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 06/16] bootsource: stub out when in PBL Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 07/16] crypto: provide crypto_memneq for PBL Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 08/16] cdev: stub out cdev_read/write " Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 09/16] libfile: stub out file descriptor API " Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 10/16] environment: stub out environment " Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 11/16] of: stub out live tree API when using PBL Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 12/16] errno: stub out perror/strerror API when built for PBL Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 13/16] xfuncs: stub out " Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 14/16] stdio: stub out basprintf and friends " Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 15/16] memory: stub out request_barebox_region " Ahmad Fatoum
2024-11-25 15:12 ` [PATCH v2 16/16] 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