-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cpu/avr8_common/flash_utils: use C and linker for aliases
`flash_<funcname>()` is implemented by `<funcname>_P()` provided by the AVR libc on AVR targets. Previously, the preprocessor was used to do the aliasing, but this causes issues with LLVM: The signatures of e.g. `printf_P()` expects `const char *`, whereas flash utils expects `FLASH_ATTR const char *`. For GCC this will just implicitly drop the `FLASH_ATTR`, while it requires an explicit cast for LLVM. To implement the explicit cast, `static inline` function wrappers where used instead where possible. But for the variadic functions (e.g. `printf(fmt, ...)`) the linker is used to provide the aliases, as there is no way to pass the variadic functions throw in C. The alternative would be to implement `flash_printf()` by calling `vprintf_P()`, but that increased ROM size quite a bit. Finally, a work around for a bug in Ubuntu's toolchain has been added: An unused function that calls to `printf_P()`, `fprintf_P()` and `snprintf_P()`. Since this function is garbage collected anyway, it has no impact on the generated ELF file.
- Loading branch information
Showing
3 changed files
with
82 additions
and
15 deletions.
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,15 @@ | ||
#include <avr/pgmspace.h> | ||
#include <stdio.h> | ||
|
||
/* The outdated linker from Ubuntu's toolchain contains a bug in which it will | ||
* garbage collect symbols referenced only by --defsym= command line options, | ||
* and subsequently complain that the symbols are not defined. Adding other | ||
* references to those symbols from an unused function makes that buggy linker | ||
* happy. Since this function is never used, it will be garbage collected and | ||
* not impact the ROM size. */ | ||
void work_around_for_shitty_ubuntu_toolchain_and_not_expected_to_be_called(void) | ||
{ | ||
printf_P(NULL); | ||
fprintf_P(stdout, NULL); | ||
snprintf_P(NULL, 0, NULL); | ||
} |