#ifndef NOLIBC_ARCH_HAS_MEMCPY /* must be exported, as it's used by libgcc on ARM */ void *memcpy(void *dst, constvoid *src, size_t len);
__attribute__((weak,unused,section(".text.nolibc_memcpy"))) void *memcpy(void *dst, constvoid *src, size_t len)
{
size_t pos = 0;
#ifndef NOLIBC_ARCH_HAS_MEMSET /* might be ignored by the compiler without -ffreestanding, then found as * missing.
*/ void *memset(void *dst, int b, size_t len);
__attribute__((weak,unused,section(".text.nolibc_memset"))) void *memset(void *dst, int b, size_t len)
{ char *p = dst;
while (len--) { /* prevent gcc from recognizing memset() here */
__asm__ volatile("");
*(p++) = b;
} return dst;
} #endif/* #ifndef NOLIBC_ARCH_HAS_MEMSET */
static __attribute__((unused)) char *strchr(constchar *s, int c)
{ while (*s) { if (*s == (char)c) return (char *)s;
s++;
} return NULL;
}
static __attribute__((unused)) int strcmp(constchar *a, constchar *b)
{ unsignedint c; int diff;
while (!(diff = (unsignedchar)*a++ - (c = (unsignedchar)*b++)) && c)
; return diff;
}
/* this function is only used with arguments that are not constants or when * it's not known because optimizations are disabled. Note that gcc 12 * recognizes an strlen() pattern and replaces it with a jump to strlen(), * thus itself, hence the asm() statement below that's meant to disable this * confusing practice.
*/
size_t strlen(constchar *str);
__attribute__((weak,unused,section(".text.nolibc_strlen")))
size_t strlen(constchar *str)
{
size_t len;
for (len = 0; str[len]; len++)
__asm__(""); return len;
}
/* do not trust __builtin_constant_p() at -O0, as clang will emit a test and * the two branches, then will rely on an external definition of strlen().
*/ #ifdefined(__OPTIMIZE__) #define nolibc_strlen(x) strlen(x) #define strlen(str) ({ \
__builtin_constant_p((str)) ? \
__builtin_strlen((str)) : \
nolibc_strlen((str)); \
}) #endif
/* * We want len < size-1. But as size is unsigned and can wrap * around, we use len + 1 instead.
*/ while (len + 1 < size) {
dst[len] = *src; if (*src == '\0') break;
len++;
src++;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.