]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Mark memcmp/memcpy/memset aliases as used
authorJan Janssen <medhefgo@web.de>
Fri, 10 Jun 2022 13:20:01 +0000 (15:20 +0200)
committerJan Janssen <medhefgo@web.de>
Fri, 10 Jun 2022 13:54:02 +0000 (15:54 +0200)
The compiler may emit calls to these but also optimize the function away
somehow, breaking at link stage. Marking them as used prevents this.

src/boot/efi/efi-string.c

index b9ef1548ca24494fe21ab6b1c460905a60aebc97..f5b671c7be80c1b683922f562dbaa0e99b91886a 100644 (file)
@@ -294,9 +294,11 @@ void *efi_memset(void *p, int c, size_t n) {
 #  undef memcmp
 #  undef memcpy
 #  undef memset
-/* Provide the actual implementation for the builtins. To prevent a linker error, we mark memcpy/memset as
- * weak, because gnu-efi is currently providing them. */
-__attribute__((alias("efi_memcmp"))) int memcmp(const void *p1, const void *p2, size_t n);
-__attribute__((weak, alias("efi_memcpy"))) void *memcpy(void * restrict dest, const void * restrict src, size_t n);
-__attribute__((weak, alias("efi_memset"))) void *memset(void *p, int c, size_t n);
+/* 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