Dear Maintainer,
newlib is supposed to be built with `-f{data,function}-sections`, and
newlib-nano is supposed to be built with also `-Os -fshort-wchar`:
=== cut debian/rules ===
CFLAGS := CFLAGS="-g -O2 -ffunction-sections -fdata-sections"
CFLAGS_NANO := CFLAGS="-g -Os -ffunction-sections -fdata-sections -fshort-wchar"
=== cut ===
Unfortunately, this is cross-compilation, and those flags are used to compile only
*build host* objects, and not for *target* objects. So, all target libraries are built
with wrong cflags.
This is especially bad for newlib-nano, as `-fshort-wchar` is alters ABI
(and lack of `-f*-sections` prevents removing unused data/functions on link
time, which is important for ram/flash limited targets).
(actually, I'm not sure if `-fshort-wchar` was that much good idea: you either don't
use `wchar_t` at all, or you want "proper" 32-bit one; and given that `-fshort-wchar`
is not automatically passed by `-specs=nano.specs`, this requires non-trivial and flaky
auto-configuration from library users, e.g. https://github.com/RIOT-OS/RIOT/pull/5627 ).
Fix:
CFLAGS += CFLAGS_FOR_TARGET="-g -O2 -ffunction-sections -fdata-sections"
CFLAGS_NANO += CFLAGS_FOR_TARGET="-g -Os -ffunction-sections -fdata-sections -fshort-wchar"
Disclaimer: noticed while building local backport; verified with buildd's logs
https://buildd.debian.org/status/fetch.php?pkg=newlib&arch=all&ver=3.3.0-1&stamp=1583408649&raw=1
and inspecting lib*.a from "official" packages from sid/bullseye, buster, stretch
(confirmed all was built without -f{funciton,data}-section). Bugreport metadata
altered to match sid version.