Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 532390 - sys-libs/newlib - add support for building newlib-nano
Summary: sys-libs/newlib - add support for building newlib-nano
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Luca Barbato
URL:
Whiteboard:
Keywords: EBUILD
Depends on:
Blocks:
 
Reported: 2014-12-12 21:36 UTC by Joakim Gebart Nohlgård
Modified: 2018-03-14 16:08 UTC (History)
6 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
newlib-9999.ebuild (newlib-9999.ebuild,3.09 KB, text/plain)
2014-12-12 21:37 UTC, Joakim Gebart Nohlgård
Details
newlib-nano.patch (newlib-nano.patch,2.69 KB, patch)
2016-01-19 12:36 UTC, Joakim Gebart Nohlgård
Details | Diff
newlib-nano-r1.patch (newlib-nano-r1.patch,3.33 KB, patch)
2016-01-23 07:37 UTC, Joakim Gebart Nohlgård
Details | Diff
newlib-nano-9999-r1.patch (newlib-nano.patch,3.37 KB, patch)
2016-02-22 09:11 UTC, Joakim Gebart Nohlgård
Details | Diff
newlib-nano-9999-r1.patch (newlib-nano-9999-r1.patch,3.49 KB, patch)
2016-06-20 11:42 UTC, Joakim Gebart Nohlgård
Details | Diff
newlib-nano-9999-r1.patch (newlib-nano-9999-r1.patch,3.52 KB, patch)
2016-07-26 21:02 UTC, Joakim Gebart Nohlgård
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joakim Gebart Nohlgård 2014-12-12 21:36:11 UTC
There is a variation of Newlib called newlib-nano which is optimized for smaller systems. The ARM-supported gcc-arm-embedded toolchain in Ubuntu distributes two versions of the library, newlib as regular libc.a, libg.a etc. and newlib-nano as libc_nano.a, libg_nano.a etc.

Some embedded projects use these *_nano.a libs for linking and it would be useful to be able to provide the same kind of libraries in Gentoo.

I have attached an ebuild with an added USE flag 'newlib-nano' which enables the Debian/Ubuntu behaviour of building newlib twice, first normally, then as "nano". The files for the nano version are installed to the same names as in the deb packages, (that is, with the suffix _nano)

I have tested the ebuild on the live newlib-9999, did not try 2.1.0 or any earlier version. According to some posts around the Ubuntu gcc-arm-embedded project the nano functions were only recently upstreamed, before this it was living as a separate fork.

For more information:
http://community.arm.com/groups/embedded/blog/2013/01/21/shrink-your-mcu-code-size-with-gcc-arm-embedded-47
https://answers.launchpad.net/gcc-arm-embedded/+question/244125

Reproducible: Always
Comment 1 Joakim Gebart Nohlgård 2014-12-12 21:37:56 UTC
Created attachment 391522 [details]
newlib-9999.ebuild

The behaviour of the ebuild is based on the Debian script at https://tracker.debian.org/media/packages/n/newlib/rules-2.1.0%2Bgit20140818.1a8323b-2
Comment 2 SpanKY gentoo-dev 2015-05-26 00:06:28 UTC
Comment on attachment 391522 [details]
newlib-9999.ebuild

please post diffs, not full files
Comment 3 Joakim Gebart Nohlgård 2016-01-19 12:36:21 UTC
Created attachment 423336 [details, diff]
newlib-nano.patch

Patch against recent ebuild to add newlib-nano support.
Comment 4 Joakim Gebart Nohlgård 2016-01-23 07:37:15 UTC
Created attachment 423652 [details, diff]
newlib-nano-r1.patch

Added CFLAGS and CCASFLAGS handling to add -Os to the nano build and -ffunction-sections -fdata-sections to all builds.

The CCASFLAGS -Os flag (set/not set) must match CFLAGS -Os, else the finished library may be missing implementations to standard functions, e.g. strlen. (I found out this the hard way...)
Comment 5 Martin Gysel (bearsh) 2016-01-23 14:12:20 UTC
thanks for the patch

now I'm wondering how I get the nano version of stdc++ (stdc++_nano, supc++_nano)

also when I compile a mbed example project which build fine with "ARM GCC embedded compiler", I get linker errors:
/usr/libexec/gcc/arm-none-eabi/ld: cannot find -lstdc++_nano
/usr/libexec/gcc/arm-none-eabi/ld: cannot find -lsupc++_nano
/usr/lib/gcc/arm-none-eabi/5.3.0/../../../../arm-none-eabi/lib/thumb/libc_nano.a(lib_a-syscalls.o): In function `_lseek':
/var/tmp/portage/cross-arm-none-eabi/newlib-2.3.0.20160104/work/newlib-2.3.0.20160104/newlib/libc/sys/arm/syscalls.c:282: multiple definition of `_lseek'
ym/mbed-drivers/source/mbed-drivers.a(retarget.cpp.o):/home/bearsh/tmp/ble-examples/BLE_HeartRate/yotta_modules/mbed-drivers/source/retarget.cpp:324: first defined here
/usr/lib/gcc/arm-none-eabi/5.3.0/../../../../arm-none-eabi/lib/thumb/libc_nano.a(lib_a-syscalls.o): In function `findslot':
/var/tmp/portage/cross-arm-none-eabi/newlib-2.3.0.20160104/work/newlib-2.3.0.20160104/newlib/libc/sys/arm/syscalls.c:90: multiple definition of `_open'
ym/mbed-drivers/source/mbed-drivers.a(retarget.cpp.o):/home/bearsh/tmp/ble-examples/BLE_HeartRate/yotta_modules/mbed-drivers/mbed-drivers/FileHandle.h:105: first defined here
...
Comment 6 Joakim Gebart Nohlgård 2016-01-23 14:48:17 UTC
(In reply to Martin Gysel (bearsh) from comment #5)
> thanks for the patch
> 
> now I'm wondering how I get the nano version of stdc++ (stdc++_nano,
> supc++_nano)
> 
> also when I compile a mbed example project which build fine with "ARM GCC
> embedded compiler", I get linker errors:
> /usr/libexec/gcc/arm-none-eabi/ld: cannot find -lstdc++_nano
> /usr/libexec/gcc/arm-none-eabi/ld: cannot find -lsupc++_nano
> /usr/lib/gcc/arm-none-eabi/5.3.0/../../../../arm-none-eabi/lib/thumb/
> libc_nano.a(lib_a-syscalls.o): In function `_lseek':
> /var/tmp/portage/cross-arm-none-eabi/newlib-2.3.0.20160104/work/newlib-2.3.0.
> 20160104/newlib/libc/sys/arm/syscalls.c:282: multiple definition of `_lseek'
> ym/mbed-drivers/source/mbed-drivers.a(retarget.cpp.o):/home/bearsh/tmp/ble-
> examples/BLE_HeartRate/yotta_modules/mbed-drivers/source/retarget.cpp:324:
> first defined here
> /usr/lib/gcc/arm-none-eabi/5.3.0/../../../../arm-none-eabi/lib/thumb/
> libc_nano.a(lib_a-syscalls.o): In function `findslot':
> /var/tmp/portage/cross-arm-none-eabi/newlib-2.3.0.20160104/work/newlib-2.3.0.
> 20160104/newlib/libc/sys/arm/syscalls.c:90: multiple definition of `_open'
> ym/mbed-drivers/source/mbed-drivers.a(retarget.cpp.o):/home/bearsh/tmp/ble-
> examples/BLE_HeartRate/yotta_modules/mbed-drivers/mbed-drivers/FileHandle.h:
> 105: first defined here
> ...

I'm having the same problem. I worked around it for now by symlinking libstdc++.a as libstdc++_nano.a, but it's ugly and it's not "nano". There's a similar bug filed at Red Hat:

https://bugzilla.redhat.com/show_bug.cgi?id=1260439

The solution in theory would be to build libstdc++,libsupc++ twice when building cross GCC: once normal and once with -Os and whatever else makes up a nano libstdc++, perhaps -fno-exception -fno-rtti, but I am not very comfortable/confident messing around with the core toolchain eclasses and ebuilds..
Comment 7 Joakim Gebart Nohlgård 2016-01-24 11:39:54 UTC
(In reply to Martin Gysel (bearsh) from comment #5)
> thanks for the patch
> 
> now I'm wondering how I get the nano version of stdc++ (stdc++_nano,
> supc++_nano)
> 
> also when I compile a mbed example project which build fine with "ARM GCC
> embedded compiler", I get linker errors:
> /usr/libexec/gcc/arm-none-eabi/ld: cannot find -lstdc++_nano
> /usr/libexec/gcc/arm-none-eabi/ld: cannot find -lsupc++_nano
> /usr/lib/gcc/arm-none-eabi/5.3.0/../../../../arm-none-eabi/lib/thumb/
> libc_nano.a(lib_a-syscalls.o): In function `_lseek':
> /var/tmp/portage/cross-arm-none-eabi/newlib-2.3.0.20160104/work/newlib-2.3.0.
> 20160104/newlib/libc/sys/arm/syscalls.c:282: multiple definition of `_lseek'
> ym/mbed-drivers/source/mbed-drivers.a(retarget.cpp.o):/home/bearsh/tmp/ble-
> examples/BLE_HeartRate/yotta_modules/mbed-drivers/source/retarget.cpp:324:
> first defined here
> /usr/lib/gcc/arm-none-eabi/5.3.0/../../../../arm-none-eabi/lib/thumb/
> libc_nano.a(lib_a-syscalls.o): In function `findslot':
> /var/tmp/portage/cross-arm-none-eabi/newlib-2.3.0.20160104/work/newlib-2.3.0.
> 20160104/newlib/libc/sys/arm/syscalls.c:90: multiple definition of `_open'
> ym/mbed-drivers/source/mbed-drivers.a(retarget.cpp.o):/home/bearsh/tmp/ble-
> examples/BLE_HeartRate/yotta_modules/mbed-drivers/mbed-drivers/FileHandle.h:
> 105: first defined here
> ...

The problems with multiple definition of syscalls are easiest to get rid of by adding
EXTRA_ECONF="--disable-newlib-supplied-syscalls"
to /etc/portage/env/cross-arm-none-eabi/newlib.conf
in order to get rid of newlib's syscall implementation stubs, which you likely need to implement in any RTOS anyway. The problem is that when both the RTOS and newlib's implementations are placed in static libraries it becomes quite difficult to pick which implementation is the one that you want..

See for example 
http://comments.gmane.org/gmane.comp.gnu.binutils/71187
https://sourceware.org/ml/newlib/2015/msg00669.html
Comment 8 Vadim A. Misbakh-Soloviov (mva) gentoo-dev 2016-02-22 08:21:18 UTC
Btw, I just logged in to bugzilla right now, exactly to ask adding "--enable-newlib-io-long-long --enable-newlib-register-fini --disable-newlib-supplied-syscalls" options from ARM's official toolchain ;)
Not sure, about first two (at least "
io-long-long" can be usefull everywhere), but third one can be added in something like "if [ ${CHOST} = "arm-none-eabi" ]" block (or how do it named there).

It'd be very good.
Comment 9 Joakim Gebart Nohlgård 2016-02-22 09:11:27 UTC
Created attachment 426172 [details, diff]
newlib-nano-9999-r1.patch

This is the version that I am currently using to build my toolchain. Apply it against the current newlib-9999.ebuild

Added a USE flag for newlib-supplied-syscalls
Comment 10 Vadim A. Misbakh-Soloviov (mva) gentoo-dev 2016-02-22 13:19:13 UTC
yeah. It looks fine now (although, it'd be nice to port changes to stable and ~arch).

But, there is also that (or related) problem: https://bugs.gentoo.org/show_bug.cgi?id=549512

// It seems, it is impossible to compile gcc[cxx] (libstdc++) on stage4 when newlib is built without supplied syscalls. Although, it is quite strange: ARM's toolchain is built without syscalls and WITH stdc++, gmp and so on...
Comment 11 Vadim A. Misbakh-Soloviov (mva) gentoo-dev 2016-02-22 13:21:34 UTC
Sorry, I forgot to add quote of stage4 build failure:

> checking for gettimeofday... checking sys/time.h usability... yes
> checking sys/time.h presence... yes
> checking for sys/time.h... yes
> checking for gettimeofday... yes
> checking for library containing clock_gettime... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
Comment 12 Joakim Gebart Nohlgård 2016-02-22 13:30:37 UTC
I don't know the proper fix for the problem, but a quick workaround is to add

EXTRA_ECONF="--enable-libstdcxx-time=no"

to /etc/portage/env/cross-arm-none-eabi-elf/gcc.conf

I don't know what the implications of changing this flag are, but from some quick googling it seems like it could possibly affect std::thread and std::chrono (C++11)
Comment 13 Joakim Gebart Nohlgård 2016-06-20 11:42:51 UTC
Created attachment 438094 [details, diff]
newlib-nano-9999-r1.patch

Updated patch to fix some issues with CFLAGS not being set correctly on the nano build. Now uses CFLAGS_FOR_TARGET to set -Os on the nano build.
Comment 14 Joakim Gebart Nohlgård 2016-07-26 21:02:31 UTC
Created attachment 441658 [details, diff]
newlib-nano-9999-r1.patch

Updated ebuild to place newlib-nano's newlib.h in include/newlib-nano/ instead of include/nano, since nano.specs in the current newlib git also points to include/newlib-nano/
Comment 15 Larry the Git Cow gentoo-dev 2018-03-14 16:08:52 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=791f828192341cfdbe896cd266b9e786ecb84e2e

commit 791f828192341cfdbe896cd266b9e786ecb84e2e
Author:     Jason Zaman <perfinion@gentoo.org>
AuthorDate: 2018-03-14 15:33:11 +0000
Commit:     Jason Zaman <perfinion@gentoo.org>
CommitDate: 2018-03-14 16:06:18 +0000

    sys-libs/newlib: Add support for newlib-nano
    
    Closes: https://bugs.gentoo.org/532390
    Package-Manager: Portage-2.3.24, Repoman-2.3.6

 sys-libs/newlib/metadata.xml        |  9 +++--
 sys-libs/newlib/newlib-2.5.0.ebuild | 66 ++++++++++++++++++++++++++++++++++---
 sys-libs/newlib/newlib-9999.ebuild  | 66 ++++++++++++++++++++++++++++++++++---
 3 files changed, 130 insertions(+), 11 deletions(-)