forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 145
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # SPDX-License-Identifier: GPL-2.0 | ||
|
|
||
| obj-y += string.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // SPDX-License-Identifier: GPL-2.0 | ||
|
|
||
| #include <linux/string.h> | ||
| #include <linux/export.h> | ||
|
|
||
| #if !defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX) | ||
| /* | ||
| * If CONFIG_KASAN_GENERIC is on but CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX is | ||
| * off, mm/kasan/shadow.c will define the kasan version memcpy and its friends | ||
| * for us. We should not do anything, otherwise the symbols will conflict. | ||
| */ | ||
|
|
||
| #undef memcpy | ||
| #undef memset | ||
| #undef memmove | ||
|
|
||
| __visible void *memcpy(void *dest, const void *src, size_t count) | ||
| { | ||
| return __memcpy(dest, src, count); | ||
| } | ||
| EXPORT_SYMBOL(memcpy); | ||
|
|
||
| __visible void *memset(void *s, int c, size_t count) | ||
| { | ||
| return __memset(s, c, count); | ||
| } | ||
| EXPORT_SYMBOL(memset); | ||
|
|
||
| __visible void *memmove(void *dest, const void *src, size_t count) | ||
| { | ||
| return __memmove(dest, src, count); | ||
| } | ||
| EXPORT_SYMBOL(memmove); | ||
|
|
||
| #endif | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
#definesat https://github.com/lkl/linux/blob/master/arch/lkl/include/asm/string.h#L68 ? Are you building with or withoutCONFIG_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.
There is code that uses
__builtin_memcpydirectly. Our#define memcpywill have no effect on such usage. The compiler will generate direct calls tomemcpy, which is an undefined symbol because we never define it.linux/lib/string.c
Line 113 in 11f5b7e
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#defines?Uh oh!
There was an error while loading. Please reload this page.
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!
I think it's okay. The only difference is that if we use
static inline void *__memcpy(..)and#define memcpy __memcpythen most ofmemcpywill be inline, but if we haveextern void *memcpy(..)thenmemcpywon'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
__memcpyimplementation fromstring.htostring.cand then remove the#definealtogether, I think that's perfectly fine and will update the patch accordingly.