diff options
author | Jan Janssen <medhefgo@web.de> | 2022-09-10 16:56:48 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-09-20 12:43:48 +0200 |
commit | 55b5daf9b2b7e0c8b77de4f87986832447e72b84 (patch) | |
tree | 78d759b8ca808100b216ab83f58a8e20f089b53e /src/boot | |
parent | 2f9d231738b5ec6f979bb70674ef0c3ecc58c464 (diff) | |
download | systemd-55b5daf9b2b7e0c8b77de4f87986832447e72b84.tar.gz |
boot: Change the way we provide builtins
Relying on symbol aliasing seems to be rather unreliable. Instead just
use some light #ifdefery.
Fixes: #24630
Diffstat (limited to 'src/boot')
-rw-r--r-- | src/boot/efi/efi-string.c | 34 | ||||
-rw-r--r-- | src/boot/efi/efi-string.h | 6 | ||||
-rw-r--r-- | src/boot/efi/util.h | 4 |
3 files changed, 23 insertions, 21 deletions
diff --git a/src/boot/efi/efi-string.c b/src/boot/efi/efi-string.c index dfb2b06a75..6929e8667e 100644 --- a/src/boot/efi/efi-string.c +++ b/src/boot/efi/efi-string.c @@ -128,7 +128,8 @@ DEFINE_STRCHR(char16_t, strchr16); size_t size = len * sizeof(type); \ \ type *dup = xmalloc(size + sizeof(type)); \ - efi_memcpy(dup, s, size); \ + if (size > 0) \ + memcpy(dup, s, size); \ dup[len] = '\0'; \ \ return dup; \ @@ -271,7 +272,19 @@ bool efi_fnmatch(const char16_t *pattern, const char16_t *haystack) { DEFINE_PARSE_NUMBER(char, parse_number8); DEFINE_PARSE_NUMBER(char16_t, parse_number16); -int efi_memcmp(const void *p1, const void *p2, size_t n) { +#ifdef SD_BOOT +/* To provide the actual implementation for these we need to remove the redirection to the builtins. */ +# undef memcmp +# undef memcpy +# undef memset +#else +/* And for userpsace unit testing we need to give them an efi_ prefix. */ +# define memcmp efi_memcmp +# define memcpy efi_memcpy +# define memset efi_memset +#endif + +_used_ int memcmp(const void *p1, const void *p2, size_t n) { const uint8_t *up1 = p1, *up2 = p2; int r; @@ -291,7 +304,7 @@ int efi_memcmp(const void *p1, const void *p2, size_t n) { return 0; } -void *efi_memcpy(void * restrict dest, const void * restrict src, size_t n) { +_used_ _weak_ void *memcpy(void * restrict dest, const void * restrict src, size_t n) { if (!dest || !src || n == 0) return dest; @@ -318,7 +331,7 @@ void *efi_memcpy(void * restrict dest, const void * restrict src, size_t n) { return dest; } -void *efi_memset(void *p, int c, size_t n) { +_used_ _weak_ void *memset(void *p, int c, size_t n) { if (!p || n == 0) return p; @@ -339,16 +352,3 @@ void *efi_memset(void *p, int c, size_t n) { return p; } - -#ifdef SD_BOOT -# undef memcmp -# undef memcpy -# undef memset -/* Provide the actual implementation for the builtins by providing aliases. These need to be marked as used, - * as otherwise the compiler might remove them but still emit calls, which would break when linking. - * To prevent a different linker error, we mark memcpy/memset as weak, because gnu-efi is currently - * providing them. */ -__attribute__((used, alias("efi_memcmp"))) int memcmp(const void *p1, const void *p2, size_t n); -__attribute__((used, weak, alias("efi_memcpy"))) void *memcpy(void * restrict dest, const void * restrict src, size_t n); -__attribute__((used, weak, alias("efi_memset"))) void *memset(void *p, int c, size_t n); -#endif diff --git a/src/boot/efi/efi-string.h b/src/boot/efi/efi-string.h index 57899c978b..1ebd5fd6b7 100644 --- a/src/boot/efi/efi-string.h +++ b/src/boot/efi/efi-string.h @@ -119,9 +119,9 @@ static inline void *mempcpy(void * restrict dest, const void * restrict src, siz memcpy(dest, src, n); return (uint8_t *) dest + n; } -#endif - -/* The actual implementations of builtins with efi_ prefix so we can unit test them. */ +#else +/* For unit testing. */ int efi_memcmp(const void *p1, const void *p2, size_t n); void *efi_memcpy(void * restrict dest, const void * restrict src, size_t n); void *efi_memset(void *p, int c, size_t n); +#endif diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index afbc217d53..684930d5d6 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -60,7 +60,9 @@ static inline void *xmalloc_multiply(size_t size, size_t n) { _malloc_ _alloc_(3) _returns_nonnull_ _warn_unused_result_ static inline void *xrealloc(void *p, size_t old_size, size_t new_size) { void *r = xmalloc(new_size); - efi_memcpy(r, p, MIN(old_size, new_size)); + new_size = MIN(old_size, new_size); + if (new_size > 0) + memcpy(r, p, new_size); free(p); return r; } |