Before the build system used something like
echo "int main(){} void _exit(int n) {(void)n;while(1);}" | LC_ALL=C $(LINK) -xc - -o /dev/null -lc -Wall -Wextra -pedantic <FLAGS_TO_TEST>
to check for flags supported by the compiler (used as linker frontend).
This however no longer works with newlib 4.3.0, which requires the
symbols `_sbrk_r`, `_close_r`, `_lseek_r`, `_read_r`, and `_write_r` to
be present. Instead, now a new file `minimal_linkable.c` was added that
adds all the missing symbols and is used in the linker feature tests
instead.
GCC on some platforms does need an executable stack to generate
trampoline code, but use of nested functions is not allowed in
RIOT's code base anyway.
This allows including C headers from C++. It sadly reduced the
diagnostics on C++ code as well, were there warning may make sense as
unintended side effect. We may be able to drop that later on, when more
C APIs are properly wrapped in native C++ APIs, so that C headers do no
longer need to be compatible with C++ compilers.
The standard is 9 years old now, it is well supported in all mayor compilers.
In fact, features of the 'new' standard are already used in RIOT (std_atomic).
Let's make it the default and adapt the Makefiles accordingly.
This commit makes overflow of signed integers to behave as expected by at 90%
of the C developers, even though overflow of signed integers are strictly
undefined behavior.
Note: Please do not add code relying on a specific behavior for the overflow of
signed integers, even though `-fwrpav` will make that code work. This is
intended to mitigate the risk of bugs in overflow checks being exploited,
not to encourage adding new bugs.
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30475 for details and see
http://c-faq.com/misc/intovf.html on how to implement overflow checks properly.
Normal, or thick archives contain a copy of the object code. Thin
archives, on the contrary, are just an index to the .o files.
This patch does two things:
1. Change ARFLAGS to enable the "T" options.
2. Call AR with all relative paths.
The second step is necessary because the build system handles all
absolute paths. If the index in the thin archive contains absolute
paths, archives created in docker are no usable outside, and moving
the objects breaks the archive.
If all arguments to AR are relative, the resulting archive contains
filenames *relative to the .a file* and nothing should break as long
as the relative location of the .a and .o remains unchanged.
Compilation time is unchanged, but disc usage is reduced by approximately
50%. These are the result of a full RIOT build:
| Thin Archive | no | yes | Savings (%) |
| -------------- | ------: | ----: | ----------- |
| pkg (10e6 KiB) | 1 790 | 905 | 49% |
| Non pkg | 71 | 71 | 1% |
| Total | 1 812 | 976 | 46 % |
Use the -gz option to compress ELF sections containing DWARF information.
This saves around 50% of disk space, without any side effects.
See https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Debugging-Options.html#Debugging-Options
for more infomation on this option.
Some platforms have an outdated toolchain that does not support -gz so
the flag is blacklisted there. Even then, the results are quite impressive.
I used @cladmi's `buildtest` branch (https://github.com/cladmi/RIOT/tree/wip/du/buildtest)
with this change and compiled the `examples/default` application:
```
$ BUILD_IN_DOCKER=1 DOCKER="sudo docker" make -C examples/default buildtest-indocker
```
The size was obtained with:
```
$ find output -name "*.bin.bindirsize" -type f -exec tail -n1 '{}' \; | cut -f 1 | awk '{s+=$1} END {printf "%.0f", s}'
```
Results:
- Vanilla: 10328112 KB (~10GB).
- with -gz: 4982788 KB (~5GB).
This was inspired by #8496.
Update the optional flags to use 'OPTIONAL_CFLAGS' instead of evaluating
everytime.
They are now blacklisted by architecture/toolchain according to the
current docker reference image.
Handle declaring OPTIONAL_CFLAGS and blacklisting them with
OPTIONAL_CFLAGS_BLACKLIST.
This should replace checking everytime if options are supported.
The excluded patterns can always be defined as they only set `CFLAGS` that
should not be passed to `CXX`.
This prepares for replacing the cflags support detection by a function.