-
Notifications
You must be signed in to change notification settings - Fork 140
lkl: Define symbols for string utilities #587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If this PR can be somehow accepted, we'll leave only a few undefined symbols in
My use case is to use Thank you for taking the time to read and review this PR. I'd love to hear your feedback. |
{ | ||
return __memcpy(dest, src, count); | ||
} | ||
EXPORT_SYMBOL(memcpy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this redirect already happen via the preprocessor using the #defines
at https://github.com/lkl/linux/blob/master/arch/lkl/include/asm/string.h#L68 ? Are you building with or without CONFIG_KASAN
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this redirect already happen via the preprocessor using the #defines at https://github.com/lkl/linux/blob/master/arch/lkl/include/asm/string.h#L68 ?
There is code that uses __builtin_memcpy
directly. Our #define memcpy
will have no effect on such usage. The compiler will generate direct calls to memcpy
, which is an undefined symbol because we never define it.
Line 113 in 11f5b7e
__builtin_memcpy(dest, src, len); |
Are you building with or without CONFIG_KASAN?
I built without CONFIG_KASAN and found these undefined symbols.
My patch was tested with and without CONFIG_KASAN. It should work either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, I wasn't familiar with how the compiler handled __builtin_memcpy
. This change looks reasonable to me, although can't we now drop those #define
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review too!
can't we now drop those #defines?
I think it's okay. The only difference is that if we use static inline void *__memcpy(..)
and #define memcpy __memcpy
then most of memcpy
will be inline, but if we have extern void *memcpy(..)
then memcpy
won't be inline.
I don't think the difference really matters here. I chose an implementation that requires minimal changes (and preserves the original inline semantics). But if we prefer to move the __memcpy
implementation from string.h
to string.c
and then remove the #define
altogether, I think that's perfectly fine and will update the patch accordingly.
{ | ||
return __memcpy(dest, src, count); | ||
} | ||
EXPORT_SYMBOL(memcpy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, I wasn't familiar with how the compiler handled __builtin_memcpy
. This change looks reasonable to me, although can't we now drop those #define
s?
The generated lkl.o currently still directly references string utility symbols (e.g., memcpy and memset). This is because some kernel sources use things like __builtin_memcpy and the compiler generates a direct call to the memcpy method. $ ld -o lkl.bin lkl.o [ .. ] lkl.o: in function `virtblk_probe': drivers/block/virtio_blk.c:1367:(.text+0xa6c6be): undefined reference to `memset' lkl.o: in function `virtblk_name_format': drivers/block/virtio_blk.c:1125:(.text+0xa6c97a): undefined reference to `memmove' drivers/block/virtio_blk.c:1126:(.text+0xa6c99c): undefined reference to `memcpy' [ .. ] I suspect this isn't really expected, since LKL shouldn't reference the memcpy symbol directly, it should try to do so via host_ops first (i.e., make a call to lkl_ops->memcpy). The reason is that we claim __HAVE_ARCH_MEMCPY, but we don't actually provide the memcpy symbol. We should do that. This commit follows much the same approach as the x86 architecture, see arch/x86/lib/memcpy_32.c for the reference. Signed-off-by: Ruihan Li <[email protected]>
v2:
v3:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @lrh2000 !
Thanks for your review too @tavip ! |
The generated lkl.o currently still directly references string utility symbols (e.g., memcpy and memset). This is because some kernel sources use things like __builtin_memcpy and the compiler generates a direct call to the memcpy method.
I suspect this isn't really expected, since LKL shouldn't reference the memcpy symbol directly, it should try to do so via host_ops first (i.e., make a call to lkl_ops->memcpy).
The reason is that we claim __HAVE_ARCH_MEMCPY, but we don't actually provide the memcpy symbol. We should do that. This commit follows much the same approach as the x86 architecture, see arch/x86/lib/memcpy_32.c for the reference.