Hi Finn,
On Thu, Mar 7, 2019 at 10:42 PM Finn Thain <fthain@xxxxxxxxxxxxxxxxxxx> wrote:
On Thu, 7 Mar 2019, Geert Uytterhoeven wrote:
On Thu, Mar 7, 2019 at 3:59 AM Finn Thain <fthain@xxxxxxxxxxxxxxxxxxx> wrote:
On Tue, 5 Mar 2019, Andreas Schwab wrote:
On Mar 05 2019, Finn Thain <fthain@xxxxxxxxxxxxxxxxxxx> wrote:
interesting that the kernel's strlen implementation in
include/linux/string.h can't achieve this.
This implementation is only available if ARCH_HAS_FORTIFY_SOURCE.
I see. Perhaps we could add another definition to that file:
#if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE)
...
#else
__FORTIFY_INLINE __kernel_size_t strlen(const char *p)
{
return __builtin_strlen(p);
}
#endif
I didn't test that.
I've tested it now, it works too. This may be a better solution than
defining a strlen macro.
diff --git a/include/linux/string.h b/include/linux/string.h
index 7927b875f80c..ec9c0a206bd3 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -436,6 +436,13 @@ __FORTIFY_INLINE char *strcpy(char *p, const char *q)
return p;
}
+#else
+
+__FORTIFY_INLINE __kernel_size_t strlen(const char *p)
+{
+ return __builtin_strlen(p);
+}
+
#endif
/**
But the following patch seems to work...
diff --git a/arch/m68k/include/asm/string.h b/arch/m68k/include/asm/string.h
index f759d944c449..3cff6b128ed3 100644
--- a/arch/m68k/include/asm/string.h
+++ b/arch/m68k/include/asm/string.h
@@ -71,4 +71,6 @@ extern void *memset(void *, int, __kernel_size_t);
extern void *memcpy(void *, const void *, __kernel_size_t);
#define memcpy(d, s, n) __builtin_memcpy(d, s, n)
+#define strlen(s) __builtin_strlen(s)
Shouldn't you add
#define __HAVE_ARCH_STRLEN
here...
No, the link fails because the compiler still emits some references to
strlen().
Despite -ffreestanding?!?
--- a/lib/string.c
+++ b/lib/string.c
@@ -472,6 +472,7 @@ char *strim(char *s)
EXPORT_SYMBOL(strim);
#ifndef __HAVE_ARCH_STRLEN
+#undef strlen
... so you can drop this change?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds