-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
libc/picolibc: Split hooks into separate files #81105
Merged
+317
−260
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 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 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 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,28 @@ | ||
/* | ||
* Copyright © 2021, Keith Packard <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "picolibc-hooks.h" | ||
|
||
#ifdef CONFIG_PICOLIBC_ASSERT_VERBOSE | ||
|
||
FUNC_NORETURN void __assert_func(const char *file, int line, | ||
const char *function, const char *expression) | ||
{ | ||
__ASSERT(0, "assertion \"%s\" failed: file \"%s\", line %d%s%s\n", | ||
expression, file, line, | ||
function ? ", function: " : "", function ? function : ""); | ||
Check notice on line 16 in lib/libc/picolibc/assert.c GitHub Actions / Run compliance checks on patch series (PR)You may want to run clang-format on this change
|
||
CODE_UNREACHABLE; | ||
} | ||
|
||
#else | ||
|
||
FUNC_NORETURN void __assert_no_args(void) | ||
{ | ||
__ASSERT_NO_MSG(0); | ||
CODE_UNREACHABLE; | ||
} | ||
|
||
#endif |
This file contains 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,31 @@ | ||
/* | ||
* Copyright © 2021, Keith Packard <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "picolibc-hooks.h" | ||
|
||
struct cb_bits { | ||
FILE f; | ||
cbprintf_cb out; | ||
void *ctx; | ||
}; | ||
|
||
static int cbputc(char c, FILE *_s) | ||
{ | ||
struct cb_bits *s = (struct cb_bits *) _s; | ||
|
||
(*s->out) (c, s->ctx); | ||
return 0; | ||
} | ||
|
||
int cbvprintf(cbprintf_cb out, void *ctx, const char *fp, va_list ap) | ||
{ | ||
struct cb_bits s = { | ||
.f = FDEV_SETUP_STREAM(cbputc, NULL, NULL, _FDEV_SETUP_WRITE), | ||
Check notice on line 26 in lib/libc/picolibc/cbprintf.c GitHub Actions / Run compliance checks on patch series (PR)You may want to run clang-format on this change
|
||
.out = out, | ||
.ctx = ctx, | ||
}; | ||
return vfprintf(&s.f, fp, ap); | ||
} |
This file contains 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,18 @@ | ||
/* | ||
* Copyright © 2021, Keith Packard <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "picolibc-hooks.h" | ||
|
||
/* This function gets called if static buffer overflow detection is enabled on | ||
* stdlib side (Picolibc here), in case such an overflow is detected. Picolibc | ||
* provides an implementation not suitable for us, so we override it here. | ||
*/ | ||
__weak FUNC_NORETURN void __chk_fail(void) | ||
{ | ||
printk("* buffer overflow detected *\n"); | ||
z_except_reason(K_ERR_STACK_CHK_FAIL); | ||
CODE_UNREACHABLE; | ||
} |
This file contains 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,21 @@ | ||
/* | ||
* Copyright © 2021, Keith Packard <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "picolibc-hooks.h" | ||
|
||
#ifndef CONFIG_LIBC_ERRNO | ||
|
||
/* | ||
* Picolibc needs to be able to declare this itself so that the library | ||
* doesn't end up needing zephyr header files. That means using a regular | ||
* function instead of an inline. | ||
*/ | ||
int *z_errno_wrap(void) | ||
{ | ||
return z_errno(); | ||
} | ||
|
||
#endif |
This file contains 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,15 @@ | ||
/* | ||
* Copyright © 2021, Keith Packard <[email protected]> | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "picolibc-hooks.h" | ||
|
||
__weak void _exit(int status) | ||
{ | ||
printf("exit\n"); | ||
while (1) { | ||
Z_SPIN_DELAY(100); | ||
} | ||
} |
Oops, something went wrong.
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.
This is not needed anymore?
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.
I inherited this piece from newlib/CMakeLists.txt and I have no idea what it is supposed to do. There's certainly no code in this library which needs to be protected from LTO; usually that's used to avoid letting the compiler elide calls to things like memset when storage is freed or other similar operations.
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.
Fair enough. From the commit message it kind of seemed like it may have been an oversight to remove this :)
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.
yeah, I hadn't remembered that part of the change as I did this a long time ago. Good to review and make sure nothing got missed.