From 41f204e3042b6f569a66615dc7558a15644e720d Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Thu, 23 Nov 2023 18:29:26 +0100 Subject: [PATCH] adds wrapping to all clib symbols --- bare-metal-bsp/libwrap/libwrap.mk | 3 ++- bare-metal-bsp/libwrap/sys/_exit.c | 4 +++- bare-metal-bsp/libwrap/sys/execve.c | 2 ++ bare-metal-bsp/libwrap/sys/getpid.c | 2 ++ bare-metal-bsp/libwrap/sys/isatty.c | 2 ++ bare-metal-bsp/libwrap/sys/kill.c | 2 ++ bare-metal-bsp/libwrap/sys/link.c | 2 ++ bare-metal-bsp/libwrap/sys/open.c | 2 ++ bare-metal-bsp/libwrap/sys/openat.c | 2 ++ bare-metal-bsp/libwrap/sys/stat.c | 2 ++ bare-metal-bsp/libwrap/sys/times.c | 2 ++ bare-metal-bsp/libwrap/sys/unlink.c | 2 ++ 12 files changed, 25 insertions(+), 2 deletions(-) diff --git a/bare-metal-bsp/libwrap/libwrap.mk b/bare-metal-bsp/libwrap/libwrap.mk index 345e993..8464a3c 100644 --- a/bare-metal-bsp/libwrap/libwrap.mk +++ b/bare-metal-bsp/libwrap/libwrap.mk @@ -50,7 +50,7 @@ LIBWRAP_SYMS := \ isatty \ times \ sbrk _sbrk\ - _exit \ + exit _exit \ puts _puts\ printf \ sprintf @@ -60,6 +60,7 @@ LIBWRAP := libwrap.a LINK_DEPS += $(LIBWRAP) LDFLAGS += $(foreach s,$(LIBWRAP_SYMS),-Wl,--wrap=$(s)) +#LDFLAGS += $(foreach s,$(LIBWRAP_SYMS),-Wl,--wrap=_$(s)) LDFLAGS += -L. -Wl,--start-group -lwrap -lc -Wl,--end-group CLEAN_OBJS += $(LIBWRAP_OBJS) diff --git a/bare-metal-bsp/libwrap/sys/_exit.c b/bare-metal-bsp/libwrap/sys/_exit.c index 7dab930..ed3caa0 100644 --- a/bare-metal-bsp/libwrap/sys/_exit.c +++ b/bare-metal-bsp/libwrap/sys/_exit.c @@ -2,12 +2,13 @@ #include #include "platform.h" +#include "weak_under_alias.h" extern volatile uint32_t tohost; extern volatile uint32_t fromhost; void write_hex(int fd, uint32_t hex); -void __wrap__exit(int code) +void __wrap_exit(int code) { //volatile uint32_t* leds = (uint32_t*) (GPIO_BASE_ADDR + GPIO_OUT_OFFSET); const char message[] = "\nProgam has exited with code:"; @@ -20,3 +21,4 @@ void __wrap__exit(int code) write(STDERR_FILENO, "\x04", 1); for (;;); } +weak_under_alias(exit); diff --git a/bare-metal-bsp/libwrap/sys/execve.c b/bare-metal-bsp/libwrap/sys/execve.c index 6178a01..f7be25a 100644 --- a/bare-metal-bsp/libwrap/sys/execve.c +++ b/bare-metal-bsp/libwrap/sys/execve.c @@ -2,8 +2,10 @@ #include #include "stub.h" +#include "weak_under_alias.h" int __wrap_execve(const char* name, char* const argv[], char* const env[]) { return _stub(ENOMEM); } +weak_under_alias(execve); diff --git a/bare-metal-bsp/libwrap/sys/getpid.c b/bare-metal-bsp/libwrap/sys/getpid.c index 5aa510b..195fbec 100644 --- a/bare-metal-bsp/libwrap/sys/getpid.c +++ b/bare-metal-bsp/libwrap/sys/getpid.c @@ -1,6 +1,8 @@ /* See LICENSE of license details. */ +#include "weak_under_alias.h" int __wrap_getpid(void) { return 1; } +weak_under_alias(getpid); diff --git a/bare-metal-bsp/libwrap/sys/isatty.c b/bare-metal-bsp/libwrap/sys/isatty.c index 55eab0a..7bb82ab 100644 --- a/bare-metal-bsp/libwrap/sys/isatty.c +++ b/bare-metal-bsp/libwrap/sys/isatty.c @@ -1,6 +1,7 @@ /* See LICENSE of license details. */ #include +#include "weak_under_alias.h" int __wrap_isatty(int fd) { @@ -9,3 +10,4 @@ int __wrap_isatty(int fd) return 0; } +weak_under_alias(isatty); diff --git a/bare-metal-bsp/libwrap/sys/kill.c b/bare-metal-bsp/libwrap/sys/kill.c index 9c56632..18b9bd4 100644 --- a/bare-metal-bsp/libwrap/sys/kill.c +++ b/bare-metal-bsp/libwrap/sys/kill.c @@ -2,8 +2,10 @@ #include #include "stub.h" +#include "weak_under_alias.h" int __wrap_kill(int pid, int sig) { return _stub(EINVAL); } +weak_under_alias(kill); diff --git a/bare-metal-bsp/libwrap/sys/link.c b/bare-metal-bsp/libwrap/sys/link.c index 9340cad..0cad551 100644 --- a/bare-metal-bsp/libwrap/sys/link.c +++ b/bare-metal-bsp/libwrap/sys/link.c @@ -2,8 +2,10 @@ #include #include "stub.h" +#include "weak_under_alias.h" int __wrap_link(const char *old_name, const char *new_name) { return _stub(EMLINK); } +weak_under_alias(link); diff --git a/bare-metal-bsp/libwrap/sys/open.c b/bare-metal-bsp/libwrap/sys/open.c index d1871f9..c61415a 100644 --- a/bare-metal-bsp/libwrap/sys/open.c +++ b/bare-metal-bsp/libwrap/sys/open.c @@ -2,8 +2,10 @@ #include #include "stub.h" +#include "weak_under_alias.h" int __wrap_open(const char* name, int flags, int mode) { return _stub(ENOENT); } +weak_under_alias(open); diff --git a/bare-metal-bsp/libwrap/sys/openat.c b/bare-metal-bsp/libwrap/sys/openat.c index 7f1c945..227c956 100644 --- a/bare-metal-bsp/libwrap/sys/openat.c +++ b/bare-metal-bsp/libwrap/sys/openat.c @@ -2,8 +2,10 @@ #include #include "stub.h" +#include "weak_under_alias.h" int __wrap_openat(int dirfd, const char* name, int flags, int mode) { return _stub(ENOENT); } +weak_under_alias(openat); diff --git a/bare-metal-bsp/libwrap/sys/stat.c b/bare-metal-bsp/libwrap/sys/stat.c index 1ccc2f4..1576ca1 100644 --- a/bare-metal-bsp/libwrap/sys/stat.c +++ b/bare-metal-bsp/libwrap/sys/stat.c @@ -3,8 +3,10 @@ #include #include #include "stub.h" +#include "weak_under_alias.h" int __wrap_stat(const char* file, struct stat* st) { return _stub(EACCES); } +weak_under_alias(stat); diff --git a/bare-metal-bsp/libwrap/sys/times.c b/bare-metal-bsp/libwrap/sys/times.c index 26a9566..55969a7 100644 --- a/bare-metal-bsp/libwrap/sys/times.c +++ b/bare-metal-bsp/libwrap/sys/times.c @@ -3,8 +3,10 @@ #include #include #include "stub.h" +#include "weak_under_alias.h" clock_t __wrap_times(struct tms* buf) { return _stub(EACCES); } +weak_under_alias(times); diff --git a/bare-metal-bsp/libwrap/sys/unlink.c b/bare-metal-bsp/libwrap/sys/unlink.c index b62b1ba..09f4da7 100644 --- a/bare-metal-bsp/libwrap/sys/unlink.c +++ b/bare-metal-bsp/libwrap/sys/unlink.c @@ -2,8 +2,10 @@ #include #include "stub.h" +#include "weak_under_alias.h" int __wrap_unlink(const char* name) { return _stub(ENOENT); } +weak_under_alias(unlink);