Skip to contentSkip to conversation

Experimental addition of the newlib library

PATCH New Chris Wardman 4 participants 23 messages Sep 13, 2015 – Sep 27, 2015 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Experimental addition of the newlib library

This patch add support for a newlib library build of the gcc toolchain.
This is designed to build arm-none-eabi- toolchain, and it was tested against an stm32f4discovery board.

Hopefully this will help people build bare metal code for arm processors

---
 package/Makefile.in                                | 10 ++++-
 package/gcc/gcc-final/gcc-final.mk                 |  4 ++
 package/gcc/gcc.mk                                 |  7 ++++
 package/newlib/Config.in                           |  4 ++
 .../newlib-0001-configure-tooldir-path.patch       | 25 +++++++++++
 package/newlib/newlib.mk                           | 48 ++++++++++++++++++++++
 toolchain/Config.in                                |  6 +++
 toolchain/toolchain-buildroot/Config.in            |  9 ++++
 8 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 package/newlib/Config.in
 create mode 100644 package/newlib/newlib-0001-configure-tooldir-path.patch
 create mode 100644 package/newlib/newlib.mk
package/Makefile.in +9 -1
index 545694f..7f4d74e 100644
@@ -37,10 +37,16 @@ $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \
 endif
 
 # Compute GNU_TARGET_NAME
+ifeq ($(BR2_TOOLCHAIN_NO_VENDOR),y)
+GNU_TARGET_NAME = $(ARCH)-$(TARGET_OS)-$(LIBC)$(ABI)
+else
 GNU_TARGET_NAME = $(ARCH)-$(TARGET_VENDOR)-$(TARGET_OS)-$(LIBC)$(ABI)
+endif
 
 # FLAT binary format needs uclinux
-ifeq ($(BR2_BINFMT_FLAT),y)
+ifeq ($(BR2_TOOLCHAIN_USES_NEWLIB),y)
+TARGET_OS = none
+else ifeq ($(BR2_BINFMT_FLAT),y)
 TARGET_OS = uclinux
 else
 TARGET_OS = linux
@@ -50,6 +56,8 @@ ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
 LIBC = uclibc
 else ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y)
 LIBC = musl
+else ifeq ($(BR2_TOOLCHAIN_USES_NEWLIB),y)
+LIBC = 
 else
 LIBC = gnu
 endif
package/gcc/gcc-final/gcc-final.mk +4 -0
index 86b3c78..ba8d644 100644
@@ -72,6 +72,10 @@ else
 HOST_GCC_FINAL_CONF_OPTS += --enable-shared
 endif
 
+ifeq ($(BR2_TOOLCHAIN_BUILDROOT_NEWLIB),y)
+HOST_GCC_FINAL_CONF_OPTS += --with-newlib
+endif
+
 ifeq ($(BR2_GCC_ENABLE_OPENMP),y)
 HOST_GCC_FINAL_CONF_OPTS += --enable-libgomp
 else
package/gcc/gcc.mk +7 -0
index 501fcea..62f6b80 100644
@@ -100,6 +100,13 @@ HOST_GCC_COMMON_CONF_OPTS = \
 HOST_GCC_COMMON_CONF_ENV = \
 	MAKEINFO=missing
 
+ifeq ($(BR2_TOOLCHAIN_BUILDROOT_NEWLIB),y)
+HOST_GCC_COMMON_CONF_OPTS += --with-gnu-as
+else
+HOST_GCC_COMMON_CONF_OPTS += --disable-__cxa_atexit
+endif
+
+
 GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
 GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
 
package/newlib/Config.in new file +4 -0
new file mode 100644
index 0000000..0f3e2d7
@@ -0,0 +1,4 @@
+config BR2_PACKAGE_NEWLIB
+       bool
+       depends on BR2_TOOLCHAIN_USES_NEWLIB
+       default y
package/newlib/newlib-0001-configure-tooldir-path.patch new file +25 -0
new file mode 100644
index 0000000..c162678
@@ -0,0 +1,25 @@
+This patch is required to fix how the newlib headers are installed. 
+
+The cross compiler expects headers to be in 
+.../host/usr/arm-none-eabi/sysroot/usr/include/newlib.h
+by default newlib installed the headers into 
+.../host/usr/arm-none-eabi/sysroot/arm-none-eabi/include/newlib.h
+
+${exec_prefix} provides the .../host/usr/arm-none-eabi/sysroot path
+${target_noncanonical} provides an extra arm-none-eabi/ that must be removed. 
+
+Signed-off-by: Chris Wardman <[email protected]>
+
+
+diff -uNr newlib-old/configure newlib-new/configure
+--- newlib-old/configure	2014-07-05 17:09:07.000000000 -0400
++++ newlib-new/configure	2014-12-25 00:59:01.727549186 -0500
+@@ -6985,7 +6985,7 @@
+ 
+ # Some systems (e.g., one of the i386-aix systems the gas testers are
+ # using) don't handle "\$" correctly, so don't use it here.
+-tooldir='${exec_prefix}'/${target_noncanonical}
++tooldir='${exec_prefix}'/usr
+ build_tooldir=${tooldir}
+ 
+ # Create a .gdbinit file which runs the one in srcdir
package/newlib/newlib.mk new file +48 -0

48 lines not on this page · raw message

toolchain/Config.in +6 -0
index a851ce4..88ebe8c 100644
@@ -28,6 +28,12 @@ config BR2_TOOLCHAIN_USES_MUSL
 	select BR2_TOOLCHAIN_HAS_THREADS_DEBUG
 	select BR2_TOOLCHAIN_HAS_THREADS_NPTL
 
+config BR2_TOOLCHAIN_USES_NEWLIB
+       bool
+
+config BR2_TOOLCHAIN_NO_VENDOR 
+       bool
+
 choice
 	prompt "Toolchain type"
 	help
toolchain/toolchain-buildroot/Config.in +9 -0
index 13e2b15..c11db73 100644
@@ -94,6 +94,14 @@ config BR2_TOOLCHAIN_BUILDROOT_MUSL
 	  This option selects musl as the C library for the
 	  cross-compilation toolchain.
 
+config BR2_TOOLCHAIN_BUILDROOT_NEWLIB
+       bool "newlib (experimental)"
+       depends on BR2_arm
+       select BR2_TOOLCHAIN_USES_NEWLIB
+       select BR2_TOOLCHAIN_NO_VENDOR
+       help
+         This will build the newlib library for a toolchain without an OS
+
 endchoice
 
 config BR2_TOOLCHAIN_BUILDROOT_LIBC
@@ -104,6 +112,7 @@ config BR2_TOOLCHAIN_BUILDROOT_LIBC
 	default "glibc"  if BR2_TOOLCHAIN_BUILDROOT_EGLIBC
 	default "glibc"  if BR2_TOOLCHAIN_BUILDROOT_GLIBC
 	default "musl"	 if BR2_TOOLCHAIN_BUILDROOT_MUSL
+	default "newlib" if BR2_TOOLCHAIN_BUILDROOT_NEWLIB
 
 source "package/uclibc/Config.in"
 source "package/glibc/Config.in"
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/3 New entry for the Cortex-M4 processor

I created a new entry for the Cortex-M4 processor in the processor list. Right now it is being tested against a STM32F4disovery board.
This is technically an M4F. I will add that entry with the floating point in the future

---
 arch/Config.in.arm | 6 ++++++
 1 file changed, 6 insertions(+)
arch/Config.in.arm +6 -0
index 4d10f4c..2692402 100644
@@ -156,6 +156,11 @@ config BR2_cortex_m3
 	bool "cortex-M3"
 	select BR2_ARM_CPU_HAS_THUMB
 	select BR2_ARM_CPU_HAS_THUMB2
+config BR2_cortex_m4
+       bool "cortex-M4"
+        select BR2_ARM_CPU_HAS_THUMB
+        select BR2_ARM_CPU_HAR_THUMB2
+        select BR2_ARM_CPU_ARMV7M
 config BR2_fa526
 	bool "fa526/626"
 	select BR2_ARM_CPU_HAS_ARM
@@ -419,6 +424,7 @@ config BR2_GCC_TARGET_CPU
 	default "cortex-a12"	if BR2_cortex_a12
 	default "cortex-a15"	if BR2_cortex_a15
 	default "cortex-m3"	if BR2_cortex_m3
+	default "cortex-m4"     if BR2_cortex_m4
 	default "fa526"		if BR2_fa526
 	default "marvell-pj4"	if BR2_pj4
 	default "strongarm"	if BR2_strongarm
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/3 New entry for the Cortex-M4 processor

Chris,

Quoted 1 line · Chris Wardman

I created a new entry for the Cortex-M4 processor in the processor list.

Don't use "personal" formulations in commit log. It should be something
like: "This commit adds a new entry..."

Quoted 2 lines

Right now it is being tested against a STM32F4disovery board.
This is technically an M4F. I will add that entry with the floating point in the future

Ditto here.

And the title of the commit log should be:

arch: add entry for the ARM Cortex-M4 processor

arch/Config.in.arm config BR2_cortex_m3 · line 163

Quoted 13 lines
arch/Config.in.arm +5 -0
index 4d10f4c..2692402 100644
@@ -156,6 +156,11 @@ config BR2_cortex_m3
 	bool "cortex-M3"
 	select BR2_ARM_CPU_HAS_THUMB
 	select BR2_ARM_CPU_HAS_THUMB2
+config BR2_cortex_m4
+       bool "cortex-M4"
+        select BR2_ARM_CPU_HAS_THUMB
+        select BR2_ARM_CPU_HAR_THUMB2
+        select BR2_ARM_CPU_ARMV7M

Please use tab for indentation. Also, while Cortex-M3 also does it, I think selecting both Thumb and Thumb-2 is not correct: Cortex-M3/M4 only support Thumb-2, no? Or at least, gcc only provides a -mthumb option that will generate Thumb-2 code, so there is no way to generate classic Thumb code on ARMv7-M platforms. Though since the problem already exists for Cortex-M3, we can keep it this way for Cortex-M4 as well for now.

Also, you're selecting the BR2_ARM_CPU_ARMV7M option, but this option does not exist. Since there is a BR2_ARM_CPU_ARMV7A, I believe it makes sense to create this option, so probably you should have three patches here:

* One option that adds BR2_ARM_CPU_ARMV7M
* One patch that makes Cortex-M3 select it
* One patch that adds Cortex-M4

Other than that, looks good to me.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#3 lore raw

PATCH 2/3 New entry for the Cortex-M4 processor

Thomas, All,

On 2015-09-13 10:21 +0200, Thomas Petazzoni spake thusly:

Quoted 1 line · Chris Wardman

[--SNIP--]

Quoted 14 lines

arch/Config.in.arm config BR2_cortex_m3 · line 163

Quoted 13 lines
arch/Config.in.arm +5 -0
index 4d10f4c..2692402 100644
@@ -156,6 +156,11 @@ config BR2_cortex_m3
 	bool "cortex-M3"
 	select BR2_ARM_CPU_HAS_THUMB
 	select BR2_ARM_CPU_HAS_THUMB2
+config BR2_cortex_m4
+       bool "cortex-M4"
+        select BR2_ARM_CPU_HAS_THUMB
+        select BR2_ARM_CPU_HAR_THUMB2
+        select BR2_ARM_CPU_ARMV7M
Quoted 7 lines

Please use tab for indentation. Also, while Cortex-M3 also does it, I think selecting both Thumb and Thumb-2 is not correct: Cortex-M3/M4 only support Thumb-2, no? Or at least, gcc only provides a -mthumb option that will generate Thumb-2 code, so there is no way to generate classic Thumb code on ARMv7-M platforms. Though since the problem already exists for Cortex-M3, we can keep it this way for Cortex-M4 as well for now.

It is my understanding that -mthumb will generate Thumb2 instructions on cores that have Thumb2 (e.g. Cortex), and Thumb (aka Thumb1) on cores that do not have Thumb2.

Also, since Thumb2 is a strict superset of Thumb, then having Thumb2 means having Thumb, at least from an instruction set point of view.

I believe Thumb2 should select Thumb.

What I meant is: if a package needs Thumb (e.g. to use assembly code that uses Thumb instructions) then that assembly code is still entirely valid when the core is Thumb2-capable.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#4 lore raw

PATCH 2/3 New entry for the Cortex-M4 processor

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Hi,

Quoted 8 lines

It is my understanding that -mthumb will generate Thumb2 instructions on cores that have Thumb2 (e.g. Cortex), and Thumb (aka Thumb1) on cores that do not have Thumb2.

Also, since Thumb2 is a strict superset of Thumb, then having Thumb2 means having Thumb, at least from an instruction set point of view.

I believe Thumb2 should select Thumb.

Yes, that sounds sensible.

Signature · 1 line
Bye, Peter Korsgaard
#5 lore raw

PATCH 3/3 Adding support for uclibcpp library

In reply to Chris Wardman

uclibcpp is built as an alternative to the standard libstdc++ library It provides the support for c++ with a smaller memory footprint. Right now it depends on newlib, because it has only been tested against newlib

---
 .../uclibcpp/0.2.4/uclibcpp-0001-minor-fixes.patch | 63 ++++++++++++++++++++++
 package/uclibcpp/Config.in                         |  9 ++++
 package/uclibcpp/uclibcpp.config                   | 54 +++++++++++++++++++
 package/uclibcpp/uclibcpp.mk                       | 28 ++++++++++
 toolchain/Config.in                                |  1 +
 5 files changed, 155 insertions(+)
 create mode 100644 package/uclibcpp/0.2.4/uclibcpp-0001-minor-fixes.patch
 create mode 100644 package/uclibcpp/Config.in
 create mode 100644 package/uclibcpp/uclibcpp.config
 create mode 100644 package/uclibcpp/uclibcpp.mk
package/uclibcpp/0.2.4/uclibcpp-0001-minor-fixes.patch new file +63 -0
new file mode 100644
index 0000000..851b87e
@@ -0,0 +1,63 @@
+Minor fixes so uclibcpp compiles. 
+
+I have no clude why they wrote the Unwind_Exception_Class variable that way, but that doesn't compile
+
+uclibcpp needs isspace which is not provided otherwise
+
+Signed-off-by: Chris Wardman <[email protected]>
+
+
+diff -uNr uClibc++-0.2.4/include/unwind-cxx.h uc_new/include/unwind-cxx.h
+--- uClibc++-0.2.4/include/unwind-cxx.h	2012-05-25 17:15:31.000000000 -0400
++++ uc_new/include/unwind-cxx.h	2015-01-15 16:29:05.358633886 -0500
+@@ -172,15 +172,7 @@
+ // These are explicitly GNU C++ specific.
+ 
+ // This is the exception class we report -- "GNUCC++\0".
+-const _Unwind_Exception_Class __gxx_exception_class
+-= ((((((((_Unwind_Exception_Class) 'G' 
+-	 << 8 | (_Unwind_Exception_Class) 'N')
+-	<< 8 | (_Unwind_Exception_Class) 'U')
+-       << 8 | (_Unwind_Exception_Class) 'C')
+-      << 8 | (_Unwind_Exception_Class) 'C')
+-     << 8 | (_Unwind_Exception_Class) '+')
+-    << 8 | (_Unwind_Exception_Class) '+')
+-   << 8 | (_Unwind_Exception_Class) '\0');
++  const _Unwind_Exception_Class __gxx_exception_class = "GNUCC++";
+ 
+ // GNU C++ personality routine, Version 0.
+ extern "C" _Unwind_Reason_Code __gxx_personality_v0
+diff -uNr uClibc++-0.2.4/Rules.mak uc_new/Rules.mak
+--- uClibc++-0.2.4/Rules.mak	2012-05-25 17:15:31.000000000 -0400
++++ uc_new/Rules.mak	2015-01-15 16:29:05.358633886 -0500
+@@ -107,7 +107,7 @@
+ 
+ # Some nice CFLAGS to work with
+ GEN_CFLAGS:=-fno-builtin
+-CFLAGS:=$(XWARNINGS) $(CPU_CFLAGS) -ansi
++CFLAGS:=$(XWARNINGS) $(CPU_CFLAGS)
+ 
+ LDFLAGS:=-Wl,--warn-common -Wl,--warn-once -Wl,-z,combreloc -Wl,-z,defs
+ 
+diff -uNr uClibc++-0.2.4/src/_ct_chr.cpp uc_new/src/_ct_chr.cpp
+--- uClibc++-0.2.4/src/_ct_chr.cpp	1969-12-31 19:00:00.000000000 -0500
++++ uc_new/src/_ct_chr.cpp	2015-01-15 16:29:21.478634145 -0500
+@@ -0,0 +1,18 @@
++#include <_ansi.h>
++#include <ctype.h>
++
++int _DEFUN(isspace, (c),int c){
++  switch(c){
++  case ' ': 
++  case '\r':
++  case '\n':
++  case '\b':
++  case '\t':
++    return true;
++  }
++  return false;
++}
++
++int _DEFUN(isdigit, (c), int c){
++  return ('0' <= c && c <= '9');
++}
package/uclibcpp/Config.in new file +9 -0
new file mode 100644
index 0000000..d0a962a
@@ -0,0 +1,9 @@
+config BR2_PACKAGE_UCLIBCPP
+       bool "uClibc++ C++ library"
+       depends on BR2_TOOLCHAIN_BUILDROOT_NEWLIB
+       depends on BR2_TOOLCHAIN_BUILDROOT_CXX
+       help
+	Uclibc++ library support. Smaller than libvstdc++
+
+
+
package/uclibcpp/uclibcpp.config new file +54 -0

54 lines not on this page · raw message

package/uclibcpp/uclibcpp.mk new file +28 -0
new file mode 100644
index 0000000..dfe8ede
@@ -0,0 +1,28 @@
+UCLIBCPP_VERSION = 0.2.4
+UCLIBCPP_SOURCE = uClibc++-$(UCLIBCPP_VERSION).tar.bz2
+UCLIBCPP_LICENSE = LGPLv3
+UCLIBCPP_SITE = http://cxx.uclibc.org/src/
+
+UCLIBCPP_INSTALL_STAGING = YES
+
+UCLIBCPP_DEPENDENCIES = host-gcc-final
+
+UCLIBCPP_KCONFIG_FILE = $(TOPDIR)/package/uclibcpp/uclibcpp.config
+
+UCLIBCPP_MAKE_FLAGS = CROSS=$(TARGET_CROSS)
+
+define UCLIBCPP_BUILD_CMDS
+	$(MAKE) -C $(@D) $(UCLIBCPP_MAKE_FLAGS)
+endef
+
+define UCLIBCPP_INSTALL_STAGING_CMDS
+	$(MAKE) -C $(@D) PREFIX=$(STAGING_DIR) install
+endef
+
+define UCLIBCPP_INSTALL_TARGET_CMDS
+	$(MAKE) -C $(@D) PREFIX=$(TARGET_DIR) install
+endef
+
+$(eval $(kconfig-package))
+
+
toolchain/Config.in +1 -0
index 88ebe8c..3904f44 100644
@@ -60,5 +60,6 @@ endchoice
 source "toolchain/toolchain-buildroot/Config.in"
 source "toolchain/toolchain-external/Config.in"
 source "toolchain/toolchain-common.in"
+source "package/uclibcpp/Config.in"
 
 endmenu
Signature · 1 line
1.9.1
#6 lore raw

PATCH 3/3 Adding support for uclibcpp library

Chris,

The commit title should probably be:

toolchain: add support for the uclibcpp library

Quoted 1 line · Chris Wardman

uclibcpp is built as an alternative to the standard libstdc++ library

The question is how does it replace the libstdc++ provided by gcc? Does it simply overwrite it? So you're building C++ support in gcc normally and then overwrite the libstdc++ from gcc with uclibcpp ?

Also, how compatible is it with the C++ standard? I.e will people be able to build arbitrary C++ libraries/applications with this smaller C++ library, or is it limited to a certain subset of the C++ standard?

package/uclibcpp/0.2.4/uclibcpp-0001-minor-fixes.patch

Quoted 5 lines
package/uclibcpp/0.2.4/uclibcpp-0001-minor-fixes.patch new file +0 -0
new file mode 100644
index 0000000..851b87e

The patches shouldn't start with the package name, so a proper name is:

	0001-minor-fixes.patch

However, I believe this patch is really mixing too many things. Can you split this uclibcpp patch into smaller piece, each fixing one particular problem?

Also, since we're supporting only one version of uclibcpp at a time, there is no need to put the patch in a 0.2.4/ subdirectory of package/uclibcpp/. Just put them directly in package/uclibcpp.

Quoted 1 line

+I have no clude why they wrote the Unwind_Exception_Class variable that way, but that doesn't compile

Please wrap the patch description to 80 columns, and don't use first person wording.

Quoted 14 lines

+diff -uNr uClibc++-0.2.4/src/_ct_chr.cpp uc_new/src/_ct_chr.cpp
+--- uClibc++-0.2.4/src/_ct_chr.cpp 1969-12-31 19:00:00.000000000 -0500
++++ uc_new/src/_ct_chr.cpp 2015-01-15 16:29:21.478634145 -0500
+@@ -0,0 +1,18 @@
++#include <_ansi.h>
++#include <ctype.h>
++
++int _DEFUN(isspace, (c),int c){

++  switch(c){
++  case ' ': 
++  case '\r':
++  case '\n':
++  case '\b':
++  case '\t':
Quoted 8 lines

++ return true;
++ }
++ return false;
++}
++
++int _DEFUN(isdigit, (c), int c){
++ return ('0' <= c && c <= '9');
++}

newlib is not providing isspace() and isdigit() ?

package/uclibcpp/Config.in line 5

Quoted 11 lines
package/uclibcpp/Config.in new file +5 -0
new file mode 100644
index 0000000..d0a962a
@@ -0,0 +1,9 @@
+config BR2_PACKAGE_UCLIBCPP
+       bool "uClibc++ C++ library"
+       depends on BR2_TOOLCHAIN_BUILDROOT_NEWLIB
+       depends on BR2_TOOLCHAIN_BUILDROOT_CXX
+       help

Please use tab for indentation.

package/uclibcpp/Config.in line 6

Quoted 1 line
package/uclibcpp/Config.in new file +1 -0
+	Uclibc++ library support. Smaller than libvstdc++

And one tab + two spaces for the help text. Also, fix the typo in the description (libvstdc++ -> libstdc++) and maybe extend the description with more details (difference between the original libstdc++ and uclibcpp one).

package/uclibcpp/Config.in line 9

Quoted 3 lines
package/uclibcpp/Config.in new file +3 -0
+
+
+

Unneeded empty lines.

package/uclibcpp/uclibcpp.mk

Quoted 66 lines
package/uclibcpp/uclibcpp.config new file +54 -0
new file mode 100644
index 0000000..4e2d0ec
@@ -0,0 +1,54 @@
+#
+# Automatically generated make config: don't edit
+#
+
+#
+# Target Features and Options
+#
+UCLIBCXX_HAS_FLOATS=y
+UCLIBCXX_HAS_LONG_DOUBLE=y
+UCLIBCXX_HAS_TLS=y
+WARNINGS="-Wall"
+BUILD_EXTRA_LIBRARIES=""
+HAVE_DOT_CONFIG=y
+
+#
+# String and I/O Stream Support
+#
+# UCLIBCXX_HAS_WCHAR is not set
+UCLIBCXX_IOSTREAM_BUFSIZE=32
+UCLIBCXX_HAS_LFS=y
+UCLIBCXX_SUPPORT_CDIR=y
+UCLIBCXX_SUPPORT_CIN=y
+UCLIBCXX_SUPPORT_COUT=y
+UCLIBCXX_SUPPORT_CERR=y
+# UCLIBCXX_SUPPORT_CLOG is not set
+
+#
+# STL and Code Expansion
+#
+UCLIBCXX_STL_BUFFER_SIZE=32
+UCLIBCXX_CODE_EXPANSION=y
+UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS=y
+UCLIBCXX_EXPAND_STRING_CHAR=y
+UCLIBCXX_EXPAND_VECTOR_BASIC=y
+UCLIBCXX_EXPAND_IOS_CHAR=y
+UCLIBCXX_EXPAND_STREAMBUF_CHAR=y
+UCLIBCXX_EXPAND_ISTREAM_CHAR=y
+UCLIBCXX_EXPAND_OSTREAM_CHAR=y
+UCLIBCXX_EXPAND_FSTREAM_CHAR=y
+UCLIBCXX_EXPAND_SSTREAM_CHAR=y
+
+#
+# Library Installation Options
+#
+UCLIBCXX_RUNTIME_PREFIX="/usr"
+UCLIBCXX_RUNTIME_INCLUDE_SUBDIR="/include"
+UCLIBCXX_RUNTIME_LIB_SUBDIR="/lib"
+UCLIBCXX_RUNTIME_BIN_SUBDIR="/bin"
+UCLIBCXX_EXCEPTION_SUPPORT=y
+IMPORT_LIBSUP=y
+# IMPORT_LIBGCC_EH is not set
+BUILD_STATIC_LIB=y
+BUILD_ONLY_STATIC_LIB=y
+# DODEBUG is not set
package/uclibcpp/uclibcpp.mk new file +0 -0
new file mode 100644
index 0000000..dfe8ede
@@ -0,0 +1,28 @@

Missing comment header. Also please add a hash file (see
http://buildroot.uclibc.org/downloads/manual/manual.html#adding-packages-hash).
Maybe I forgot to say that in my review of your newlib package, but please do it there as well.

package/uclibcpp/uclibcpp.mk line 2

Quoted 2 lines
package/uclibcpp/uclibcpp.mk new file +2 -0
+UCLIBCPP_VERSION = 0.2.4
+UCLIBCPP_SOURCE = uClibc++-$(UCLIBCPP_VERSION).tar.bz2

The last version is from May 2012, like uClibc itself. Is it a dead project like uClibc ? If so, then I'm a bit worried in packaging something so fundamental as the standard C++ library if it isn't maintained.

There has been a few commits since the last release, see
http://git.uclibc.org/uClibc++/log/. But it still doesn't seem to be very active. According to the website, there is not even a mailing list for it.

You could use the .tar.xz tarball instead of .tar.bz2.

package/uclibcpp/uclibcpp.mk line 3

Quoted 1 line
package/uclibcpp/uclibcpp.mk new file +1 -0
+UCLIBCPP_LICENSE = LGPLv3

Some quick inspection indicates LGPLv2.1+

package/uclibcpp/uclibcpp.mk line 8

Quoted 5 lines
package/uclibcpp/uclibcpp.mk new file +5 -0
+UCLIBCPP_SITE = http://cxx.uclibc.org/src/
+
+UCLIBCPP_INSTALL_STAGING = YES
+
+UCLIBCPP_DEPENDENCIES = host-gcc-final

All target packages depend on "toolchain", which has host-gcc-final as part of its dependencies. However maybe, what you need is to have this uclibcpp package built *before* any other target package that uses C++, no? If so, then toolchain/toolchain/toolchain.mk needs to be modified to add uclibcpp as a dependency when it is enabled. And of course, uclibcpp.mk should specify UCLIBCPP_ADD_TOOLCHAIN_DEPENDENCY = NO.

package/uclibcpp/uclibcpp.mk line 10

Quoted 2 lines
package/uclibcpp/uclibcpp.mk new file +2 -0
+
+UCLIBCPP_KCONFIG_FILE = $(TOPDIR)/package/uclibcpp/uclibcpp.config

$(TOPDIR)/ not needed.

Quoted 8 lines
package/uclibcpp/uclibcpp.mk new file +8 -0
+
+UCLIBCPP_MAKE_FLAGS = CROSS=$(TARGET_CROSS)
+
+define UCLIBCPP_BUILD_CMDS
+	$(MAKE) -C $(@D) $(UCLIBCPP_MAKE_FLAGS)
+endef
+
+define UCLIBCPP_INSTALL_STAGING_CMDS

package/uclibcpp/uclibcpp.mk line 28

Quoted 10 lines
package/uclibcpp/uclibcpp.mk new file +10 -0
+	$(MAKE) -C $(@D) PREFIX=$(STAGING_DIR) install
+endef
+
+define UCLIBCPP_INSTALL_TARGET_CMDS
+	$(MAKE) -C $(@D) PREFIX=$(TARGET_DIR) install
+endef
+
+$(eval $(kconfig-package))
+
+

Unneeded empty lines at the end of the file.

toolchain/Config.in endchoice · line 63

Quoted 9 lines
toolchain/Config.in +1 -0
index 88ebe8c..3904f44 100644
@@ -60,5 +60,6 @@ endchoice
 source "toolchain/toolchain-buildroot/Config.in"
 source "toolchain/toolchain-external/Config.in"
 source "toolchain/toolchain-common.in"
+source "package/uclibcpp/Config.in"

This should go in toolchain/toolchain-buildroot/Config.in.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
author
#7 lore raw

PATCH 3/3 Adding support for uclibcpp library

Hi Thomas, all,

(Sorry for the second email Thomas, didn't send the list)

You have some very valid concerns. For extremely small footprint devices that want to use C++ I think this package will be useful, but for now I'm not even using C++ in my embedded projects, so it is not critical.

I don't think it is being maintained and it has some other issues, so, I am going to leave this patch out for now.

Thanks!
-Chris

Quoted 241 lines · Thomas Petazzoni

Chris,

The commit title should probably be:

toolchain: add support for the uclibcpp library

Quoted 1 line · Chris Wardman

uclibcpp is built as an alternative to the standard libstdc++ library

The question is how does it replace the libstdc++ provided by gcc? Does it simply overwrite it? So you're building C++ support in gcc normally and then overwrite the libstdc++ from gcc with uclibcpp ?

Also, how compatible is it with the C++ standard? I.e will people be able to build arbitrary C++ libraries/applications with this smaller C++ library, or is it limited to a certain subset of the C++ standard?

package/uclibcpp/0.2.4/uclibcpp-0001-minor-fixes.patch

Quoted 5 lines
package/uclibcpp/0.2.4/uclibcpp-0001-minor-fixes.patch new file +0 -0
new file mode 100644
index 0000000..851b87e

The patches shouldn't start with the package name, so a proper name is:

        0001-minor-fixes.patch

However, I believe this patch is really mixing too many things. Can you split this uclibcpp patch into smaller piece, each fixing one particular problem?

Also, since we're supporting only one version of uclibcpp at a time, there is no need to put the patch in a 0.2.4/ subdirectory of package/uclibcpp/. Just put them directly in package/uclibcpp.

Quoted 1 line

+I have no clude why they wrote the Unwind_Exception_Class variable that way, but that doesn't compile

Please wrap the patch description to 80 columns, and don't use first person wording.

Quoted 14 lines

+diff -uNr uClibc++-0.2.4/src/_ct_chr.cpp uc_new/src/_ct_chr.cpp

+--- uClibc++-0.2.4/src/_ct_chr.cpp   1969-12-31 19:00:00.000000000 -0500
++++ uc_new/src/_ct_chr.cpp   2015-01-15 16:29:21.478634145 -0500

+@@ -0,0 +1,18 @@
++#include <_ansi.h>
++#include <ctype.h>
++
++int _DEFUN(isspace, (c),int c){

++  switch(c){
++  case ' ':
++  case '\r':
++  case '\n':
++  case '\b':
++  case '\t':
Quoted 8 lines

++ return true;
++ }
++ return false;
++}
++
++int _DEFUN(isdigit, (c), int c){
++ return ('0' <= c && c <= '9');
++}

newlib is not providing isspace() and isdigit() ?

package/uclibcpp/Config.in line 5

Quoted 11 lines
package/uclibcpp/Config.in new file +5 -0
new file mode 100644
index 0000000..d0a962a
@@ -0,0 +1,9 @@
+config BR2_PACKAGE_UCLIBCPP
+       bool "uClibc++ C++ library"
+       depends on BR2_TOOLCHAIN_BUILDROOT_NEWLIB
+       depends on BR2_TOOLCHAIN_BUILDROOT_CXX
+       help

Please use tab for indentation.

package/uclibcpp/Config.in line 6

Quoted 1 line
package/uclibcpp/Config.in new file +1 -0
+     Uclibc++ library support. Smaller than libvstdc++

And one tab + two spaces for the help text. Also, fix the typo in the description (libvstdc++ -> libstdc++) and maybe extend the description with more details (difference between the original libstdc++ and uclibcpp one).

package/uclibcpp/Config.in line 9

Quoted 3 lines
package/uclibcpp/Config.in new file +3 -0
+
+
+

Unneeded empty lines.

package/uclibcpp/uclibcpp.mk

Quoted 66 lines
package/uclibcpp/uclibcpp.config new file +54 -0
new file mode 100644
index 0000000..4e2d0ec
@@ -0,0 +1,54 @@
+#
+# Automatically generated make config: don't edit
+#
+
+#
+# Target Features and Options
+#
+UCLIBCXX_HAS_FLOATS=y
+UCLIBCXX_HAS_LONG_DOUBLE=y
+UCLIBCXX_HAS_TLS=y
+WARNINGS="-Wall"
+BUILD_EXTRA_LIBRARIES=""
+HAVE_DOT_CONFIG=y
+
+#
+# String and I/O Stream Support
+#
+# UCLIBCXX_HAS_WCHAR is not set
+UCLIBCXX_IOSTREAM_BUFSIZE=32
+UCLIBCXX_HAS_LFS=y
+UCLIBCXX_SUPPORT_CDIR=y
+UCLIBCXX_SUPPORT_CIN=y
+UCLIBCXX_SUPPORT_COUT=y
+UCLIBCXX_SUPPORT_CERR=y
+# UCLIBCXX_SUPPORT_CLOG is not set
+
+#
+# STL and Code Expansion
+#
+UCLIBCXX_STL_BUFFER_SIZE=32
+UCLIBCXX_CODE_EXPANSION=y
+UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS=y
+UCLIBCXX_EXPAND_STRING_CHAR=y
+UCLIBCXX_EXPAND_VECTOR_BASIC=y
+UCLIBCXX_EXPAND_IOS_CHAR=y
+UCLIBCXX_EXPAND_STREAMBUF_CHAR=y
+UCLIBCXX_EXPAND_ISTREAM_CHAR=y
+UCLIBCXX_EXPAND_OSTREAM_CHAR=y
+UCLIBCXX_EXPAND_FSTREAM_CHAR=y
+UCLIBCXX_EXPAND_SSTREAM_CHAR=y
+
+#
+# Library Installation Options
+#
+UCLIBCXX_RUNTIME_PREFIX="/usr"
+UCLIBCXX_RUNTIME_INCLUDE_SUBDIR="/include"
+UCLIBCXX_RUNTIME_LIB_SUBDIR="/lib"
+UCLIBCXX_RUNTIME_BIN_SUBDIR="/bin"
+UCLIBCXX_EXCEPTION_SUPPORT=y
+IMPORT_LIBSUP=y
+# IMPORT_LIBGCC_EH is not set
+BUILD_STATIC_LIB=y
+BUILD_ONLY_STATIC_LIB=y
+# DODEBUG is not set
package/uclibcpp/uclibcpp.mk new file +0 -0
new file mode 100644
index 0000000..dfe8ede
@@ -0,0 +1,28 @@

Missing comment header. Also please add a hash file (see
http://buildroot.uclibc.org/downloads/manual/manual.html#adding-packages-hash).
Maybe I forgot to say that in my review of your newlib package, but please do it there as well.

package/uclibcpp/uclibcpp.mk line 2

Quoted 2 lines
package/uclibcpp/uclibcpp.mk new file +2 -0
+UCLIBCPP_VERSION = 0.2.4
+UCLIBCPP_SOURCE = uClibc++-$(UCLIBCPP_VERSION).tar.bz2

The last version is from May 2012, like uClibc itself. Is it a dead project like uClibc ? If so, then I'm a bit worried in packaging something so fundamental as the standard C++ library if it isn't maintained.

There has been a few commits since the last release, see
http://git.uclibc.org/uClibc++/log/. But it still doesn't seem to be very active. According to the website, there is not even a mailing list for it.

You could use the .tar.xz tarball instead of .tar.bz2.

package/uclibcpp/uclibcpp.mk line 3

Quoted 1 line
package/uclibcpp/uclibcpp.mk new file +1 -0
+UCLIBCPP_LICENSE = LGPLv3

Some quick inspection indicates LGPLv2.1+

package/uclibcpp/uclibcpp.mk line 8

Quoted 5 lines
package/uclibcpp/uclibcpp.mk new file +5 -0
+UCLIBCPP_SITE = http://cxx.uclibc.org/src/
+
+UCLIBCPP_INSTALL_STAGING = YES
+
+UCLIBCPP_DEPENDENCIES = host-gcc-final

All target packages depend on "toolchain", which has host-gcc-final as part of its dependencies. However maybe, what you need is to have this uclibcpp package built *before* any other target package that uses C++, no? If so, then toolchain/toolchain/toolchain.mk needs to be modified to add uclibcpp as a dependency when it is enabled. And of course, uclibcpp.mk should specify UCLIBCPP_ADD_TOOLCHAIN_DEPENDENCY = NO.

package/uclibcpp/uclibcpp.mk line 10

Quoted 2 lines
package/uclibcpp/uclibcpp.mk new file +2 -0
+
+UCLIBCPP_KCONFIG_FILE = $(TOPDIR)/package/uclibcpp/uclibcpp.config

$(TOPDIR)/ not needed.

Quoted 8 lines
package/uclibcpp/uclibcpp.mk new file +8 -0
+
+UCLIBCPP_MAKE_FLAGS = CROSS=$(TARGET_CROSS)
+
+define UCLIBCPP_BUILD_CMDS
+     $(MAKE) -C $(@D) $(UCLIBCPP_MAKE_FLAGS)
+endef
+
+define UCLIBCPP_INSTALL_STAGING_CMDS

package/uclibcpp/uclibcpp.mk line 28

Quoted 10 lines
package/uclibcpp/uclibcpp.mk new file +10 -0
+     $(MAKE) -C $(@D) PREFIX=$(STAGING_DIR) install
+endef
+
+define UCLIBCPP_INSTALL_TARGET_CMDS
+     $(MAKE) -C $(@D) PREFIX=$(TARGET_DIR) install
+endef
+
+$(eval $(kconfig-package))
+
+

Unneeded empty lines at the end of the file.

toolchain/Config.in endchoice · line 63

Quoted 9 lines
toolchain/Config.in +1 -0
index 88ebe8c..3904f44 100644
@@ -60,5 +60,6 @@ endchoice
 source "toolchain/toolchain-buildroot/Config.in"
 source "toolchain/toolchain-external/Config.in"
 source "toolchain/toolchain-common.in"
+source "package/uclibcpp/Config.in"

This should go in toolchain/toolchain-buildroot/Config.in.

Best regards,

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

#8 lore raw

PATCH 3/3 Adding support for uclibcpp library

Hello,

Quoted 7 lines · Cjw X

You have some very valid concerns. For extremely small footprint devices that want to use C++ I think this package will be useful, but for now I'm not even using C++ in my embedded projects, so it is not critical.

I don't think it is being maintained and it has some other issues, so, I am going to leave this patch out for now.

Ok, thanks for the explanation. It's indeed better if we can leave this on the side, at least for now.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#9 lore raw

PATCH 1/3 Experimental addition of the newlib library

In reply to Chris Wardman

Chris,

Thanks a lot! This patch looks pretty good. I have a couple of comments below, but overall it looks nice.

Quoted 4 lines · Chris Wardman

This patch add support for a newlib library build of the gcc toolchain.
This is designed to build arm-none-eabi- toolchain, and it was tested against an stm32f4discovery board.

Hopefully this will help people build bare metal code for arm processors

A few comments on the commit log:

* The title should be something like:

toolchain: add support for the newlib library

* The commit log text should be line wrapped at ~80 columns.

* I believe the last sentence "Hopefully this will help people build bare metal code for arm processors" is not really useful as part of the commit log.

package/Makefile.in $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \ · line 41

Quoted 10 lines
package/Makefile.in +2 -0
index 545694f..7f4d74e 100644
@@ -37,10 +37,16 @@ $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \
 endif
 
 # Compute GNU_TARGET_NAME
+ifeq ($(BR2_TOOLCHAIN_NO_VENDOR),y)
+GNU_TARGET_NAME = $(ARCH)-$(TARGET_OS)-$(LIBC)$(ABI)

Is it really mandatory to *not* have a vendor part of the tuple?

package/gcc/gcc.mk HOST_GCC_COMMON_CONF_OPTS = \ · line 107

Quoted 13 lines
package/gcc/gcc.mk +5 -0
index 501fcea..62f6b80 100644
@@ -100,6 +100,13 @@ HOST_GCC_COMMON_CONF_OPTS = \
 HOST_GCC_COMMON_CONF_ENV = \
 	MAKEINFO=missing
 
+ifeq ($(BR2_TOOLCHAIN_BUILDROOT_NEWLIB),y)
+HOST_GCC_COMMON_CONF_OPTS += --with-gnu-as
+else
+HOST_GCC_COMMON_CONF_OPTS += --disable-__cxa_atexit
+endif

While I may understand that you're adding some specific options when BR2_TOOLCHAIN_BUILDROOT_NEWLIB=y, could you explain why you're doing something new in the "else" case, which should already be working today?

package/gcc/gcc.mk HOST_GCC_COMMON_CONF_OPTS = \ · line 109

Quoted 2 lines
package/gcc/gcc.mk +2 -0
+
+

Only one empty new line is necessary here.

package/newlib/Config.in line 4

Quoted 13 lines
package/gcc/gcc.mk +0 -0
 GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
 GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
 
package/newlib/Config.in new file +4 -0
new file mode 100644
index 0000000..0f3e2d7
@@ -0,0 +1,4 @@
+config BR2_PACKAGE_NEWLIB
+       bool
+       depends on BR2_TOOLCHAIN_USES_NEWLIB
+       default y

Use tab for the indentation of bool / depends on / default.

Quoted 19 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +13 -0
new file mode 100644
index 0000000..c162678
@@ -0,0 +1,25 @@
+This patch is required to fix how the newlib headers are installed. 
+
+The cross compiler expects headers to be in 
+.../host/usr/arm-none-eabi/sysroot/usr/include/newlib.h
+by default newlib installed the headers into 
+.../host/usr/arm-none-eabi/sysroot/arm-none-eabi/include/newlib.h
+
+${exec_prefix} provides the .../host/usr/arm-none-eabi/sysroot path
+${target_noncanonical} provides an extra arm-none-eabi/ that must be removed. 
+
+Signed-off-by: Chris Wardman <[email protected]>
+
+

package/newlib/newlib-0001-configure-tooldir-path.patch line 23

Quoted 10 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +10 -0
+diff -uNr newlib-old/configure newlib-new/configure
+--- newlib-old/configure	2014-07-05 17:09:07.000000000 -0400
++++ newlib-new/configure	2014-12-25 00:59:01.727549186 -0500
+@@ -6985,7 +6985,7 @@
+ 
+ # Some systems (e.g., one of the i386-aix systems the gas testers are
+ # using) don't handle "\$" correctly, so don't use it here.
+-tooldir='${exec_prefix}'/${target_noncanonical}
++tooldir='${exec_prefix}'/usr
+ build_tooldir=${tooldir}

You're patching the configure script, which we generally don't like, since it's generated from configure.ac. So you should either patch configure.ac and use NEWLIB_AUTORECONF = YES, or alternatively don't patch the code, and instead use a post install hook to move around the headers.

package/newlib/newlib.mk line 7

Quoted 13 lines
package/newlib/newlib.mk new file +7 -0
new file mode 100644
index 0000000..02008e5
@@ -0,0 +1,48 @@
+################################################################################
+#
+# newlib
+#
+################################################################################
+
+NEWLIB_VERSION = 2.2.0

There's a 2.2.0-1 version, that was released after 2.2.0, so presumably we may want to use this newer version?

Quoted 13 lines
package/newlib/newlib.mk new file +13 -0
+NEWLIB_SITE = ftp://sourceware.org/pub/newlib
+NEWLIB_LICENSE = MIT
+NEWLIB_LICENSE_FILES = COPYRIGHT
+
+NEWLIB_DEPENDENCIES = host-gcc-initial
+NEWLIB_ADD_TOOLCHAIN_DEPENDENCY = NO
+NEWLIB_INSTALL_STAGING = YES
+
+define NEWLIB_CONFIGURE_CMDS
+	(cd $(@D); \
+		$(TARGET_MAKE_ENV) \
+		./configure \
+			--target=$(GNU_TARGET_NAME) \

package/newlib/newlib.mk line 30

Quoted 10 lines
package/newlib/newlib.mk new file +10 -0
+			--host=$(GNU_HOST_NAME) \
+			--build=$(GNU_HOST_NAME) \
+			--prefix=$(STAGING_DIR) \
+			--includedir=$(STAGING_DIR)/usr/include \
+			--oldincludedir=$(STAGING_DIR)/usr/include \
+			--with-build-sysroot=$(STAGING_DIR) \
+			--enable-newlib-io-long-long \
+			--enable-newlib-register-fini \
+			--disable-newlib-supplied-syscalls \
+			--disable-nls)

Why don't you use the autotools-package infrastructure? newlib is using autoconf, so I believe it does make sense to use the autotools-package infrastructure.

package/newlib/newlib.mk line 36

Quoted 3 lines
package/newlib/newlib.mk new file +3 -0
+define NEWLIB_APPLY_PATCHES
+	$(APPLY_PATCHES) $(@D) package/newlib \*.patch
+endef

This does not have any effect, and is not necessary: patches in package/<pkg>/ are automatically applied.

package/newlib/newlib.mk line 40

Quoted 3 lines
package/newlib/newlib.mk new file +3 -0
+define NEWLIB_BUILD_CMDS
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)
+endef

Not needed if you use the autotools-package infrastructure.

package/newlib/newlib.mk line 44

Quoted 3 lines
package/newlib/newlib.mk new file +3 -0
+define NEWLIB_INSTALL_STAGING_CMDS
+	mkdir -p $(HOST_DIR)/usr/$(GNU_TARGET_NAME)/lib
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) install

Except the mkdir, the install command is not needed if you use the autotools-package infrastructure.

Thanks a lot!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
author
#10 lore raw

PATCH 1/3 Experimental addition of the newlib library

So, I'm going through comments and investigating. Everything seems pretty reasonable.
I'll have more comments and an updated patch soon. First though, for the vendor in the toolchain...

Quoted 30 lines · Thomas Petazzoni

Chris,

Thanks a lot! This patch looks pretty good. I have a couple of comments below, but overall it looks nice.

Quoted 4 lines · Chris Wardman

This patch add support for a newlib library build of the gcc toolchain.
This is designed to build arm-none-eabi- toolchain, and it was tested against an stm32f4discovery board.

Hopefully this will help people build bare metal code for arm processors

A few comments on the commit log:

* The title should be something like:

toolchain: add support for the newlib library

* The commit log text should be line wrapped at ~80 columns.

* I believe the last sentence "Hopefully this will help people build bare metal code for arm processors" is not really useful as part of the commit log.

Quoted 7 lines
package/Makefile.in +0 -0
index 545694f..7f4d74e 100644
@@ -37,10 +37,16 @@ $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \
 endif
 
Quoted 5 lines

package/Makefile.in $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \ · line 41

Quoted 3 lines
package/Makefile.in +2 -0
 # Compute GNU_TARGET_NAME
+ifeq ($(BR2_TOOLCHAIN_NO_VENDOR),y)
+GNU_TARGET_NAME = $(ARCH)-$(TARGET_OS)-$(LIBC)$(ABI)

Is it really mandatory to *not* have a vendor part of the tuple?

I've tried building arm-buildroot-none-eabi and arm-buildroot-none-newlibeabi, both of which, based on my understanding, should compile, but none of the tools build with that target. Binutils doesn't compile, nor does gcc. I spent some time looking at this, but never found an elegant solution.

If anyone has some suggestions about what I'm doing wrong there, I'd love to know.

Thanks,
-Chris

Quoted 148 lines
Quoted 6 lines
package/gcc/gcc.mk +0 -0
index 501fcea..62f6b80 100644

package/gcc/gcc.mk HOST_GCC_COMMON_CONF_OPTS = \ · line 107

Quoted 8 lines
package/gcc/gcc.mk +5 -0
@@ -100,6 +100,13 @@ HOST_GCC_COMMON_CONF_OPTS = \
 HOST_GCC_COMMON_CONF_ENV = \
      MAKEINFO=missing
 
+ifeq ($(BR2_TOOLCHAIN_BUILDROOT_NEWLIB),y)
+HOST_GCC_COMMON_CONF_OPTS += --with-gnu-as
+else
+HOST_GCC_COMMON_CONF_OPTS += --disable-__cxa_atexit
+endif

While I may understand that you're adding some specific options when BR2_TOOLCHAIN_BUILDROOT_NEWLIB=y, could you explain why you're doing something new in the "else" case, which should already be working today?

package/gcc/gcc.mk HOST_GCC_COMMON_CONF_OPTS = \ · line 109

Quoted 2 lines
package/gcc/gcc.mk +2 -0
+
+

Only one empty new line is necessary here.

package/newlib/Config.in line 4

Quoted 13 lines
package/gcc/gcc.mk +0 -0
 GCC_COMMON_TARGET_CFLAGS = $(TARGET_CFLAGS)
 GCC_COMMON_TARGET_CXXFLAGS = $(TARGET_CXXFLAGS)
 
package/newlib/Config.in new file +4 -0
new file mode 100644
index 0000000..0f3e2d7
@@ -0,0 +1,4 @@
+config BR2_PACKAGE_NEWLIB
+       bool
+       depends on BR2_TOOLCHAIN_USES_NEWLIB
+       default y

Use tab for the indentation of bool / depends on / default.

Quoted 19 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +13 -0
new file mode 100644
index 0000000..c162678
@@ -0,0 +1,25 @@
+This patch is required to fix how the newlib headers are installed.
+
+The cross compiler expects headers to be in
+.../host/usr/arm-none-eabi/sysroot/usr/include/newlib.h
+by default newlib installed the headers into
+.../host/usr/arm-none-eabi/sysroot/arm-none-eabi/include/newlib.h
+
+${exec_prefix} provides the .../host/usr/arm-none-eabi/sysroot path
+${target_noncanonical} provides an extra arm-none-eabi/ that must be removed.
+
+Signed-off-by: Chris Wardman <[email protected]>
+
+

package/newlib/newlib-0001-configure-tooldir-path.patch line 23

Quoted 10 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +10 -0
+diff -uNr newlib-old/configure newlib-new/configure
+--- newlib-old/configure     2014-07-05 17:09:07.000000000 -0400
++++ newlib-new/configure     2014-12-25 00:59:01.727549186 -0500
+@@ -6985,7 +6985,7 @@
+
+ # Some systems (e.g., one of the i386-aix systems the gas testers are
+ # using) don't handle "\$" correctly, so don't use it here.
+-tooldir='${exec_prefix}'/${target_noncanonical}
++tooldir='${exec_prefix}'/usr
+ build_tooldir=${tooldir}

You're patching the configure script, which we generally don't like, since it's generated from configure.ac. So you should either patch configure.ac and use NEWLIB_AUTORECONF = YES, or alternatively don't patch the code, and instead use a post install hook to move around the headers.

package/newlib/newlib.mk line 7

Quoted 13 lines
package/newlib/newlib.mk new file +7 -0
new file mode 100644
index 0000000..02008e5
@@ -0,0 +1,48 @@
+################################################################################
+#
+# newlib
+#
+################################################################################
+
+NEWLIB_VERSION = 2.2.0

There's a 2.2.0-1 version, that was released after 2.2.0, so presumably we may want to use this newer version?

Quoted 13 lines
package/newlib/newlib.mk new file +13 -0
+NEWLIB_SITE = ftp://sourceware.org/pub/newlib
+NEWLIB_LICENSE = MIT
+NEWLIB_LICENSE_FILES = COPYRIGHT
+
+NEWLIB_DEPENDENCIES = host-gcc-initial
+NEWLIB_ADD_TOOLCHAIN_DEPENDENCY = NO
+NEWLIB_INSTALL_STAGING = YES
+
+define NEWLIB_CONFIGURE_CMDS
+     (cd $(@D); \
+             $(TARGET_MAKE_ENV) \
+             ./configure \
+                     --target=$(GNU_TARGET_NAME) \

package/newlib/newlib.mk line 30

Quoted 10 lines
package/newlib/newlib.mk new file +10 -0
+                     --host=$(GNU_HOST_NAME) \
+                     --build=$(GNU_HOST_NAME) \
+                     --prefix=$(STAGING_DIR) \
+                     --includedir=$(STAGING_DIR)/usr/include \
+                     --oldincludedir=$(STAGING_DIR)/usr/include \
+                     --with-build-sysroot=$(STAGING_DIR) \
+                     --enable-newlib-io-long-long \
+                     --enable-newlib-register-fini \
+                     --disable-newlib-supplied-syscalls \
+                     --disable-nls)

Why don't you use the autotools-package infrastructure? newlib is using autoconf, so I believe it does make sense to use the autotools-package infrastructure.

package/newlib/newlib.mk line 36

Quoted 3 lines
package/newlib/newlib.mk new file +3 -0
+define NEWLIB_APPLY_PATCHES
+     $(APPLY_PATCHES) $(@D) package/newlib \*.patch
+endef

This does not have any effect, and is not necessary: patches in package/<pkg>/ are automatically applied.

package/newlib/newlib.mk line 40

Quoted 3 lines
package/newlib/newlib.mk new file +3 -0
+define NEWLIB_BUILD_CMDS
+     $(TARGET_MAKE_ENV) $(MAKE) -C $(@D)
+endef

Not needed if you use the autotools-package infrastructure.

package/newlib/newlib.mk line 44

Quoted 3 lines
package/newlib/newlib.mk new file +3 -0
+define NEWLIB_INSTALL_STAGING_CMDS
+     mkdir -p $(HOST_DIR)/usr/$(GNU_TARGET_NAME)/lib
+     $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) install

Except the mkdir, the install command is not needed if you use the autotools-package infrastructure.

Thanks a lot!

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

#11 lore raw

PATCH 1/3 Experimental addition of the newlib library

Hello,

Quoted 2 lines · Cjw X

So, I'm going through comments and investigating. Everything seems pretty reasonable.

Great, thanks.

Quoted 11 lines
Quoted 5 lines

package/Makefile.in $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \ · line 41

Quoted 3 lines

# Compute GNU_TARGET_NAME

package/Makefile.in +2 -0
+ifeq ($(BR2_TOOLCHAIN_NO_VENDOR),y)
+GNU_TARGET_NAME = $(ARCH)-$(TARGET_OS)-$(LIBC)$(ABI)

Is it really mandatory to *not* have a vendor part of the tuple?

I've tried building arm-buildroot-none-eabi and arm-buildroot-none-newlibeabi, both of which, based on my understanding, should compile, but none of the tools build with that target. Binutils doesn't compile, nor does gcc. I spent some time looking at this, but never found an elegant solution.

Interesting. I guess we'll have to experiment a bit with this.

I'm adding Yann in Cc. Yann, have you experienced such thing when adding bare-metal/newlib support in Crosstool-NG? I've quickly looked at the Crosstool-NG code, and I don't see the vendor part of the tuple being skipped specifically for bare metal/newlib toolchains, but maybe I missed it.

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#12 lore raw

PATCH 1/3 Experimental addition of the newlib library

Thomas, Cjw, All,

On 2015-09-15 09:35 +0200, Thomas Petazzoni spake thusly:

Quoted 13 lines · Cjw X
Quoted 11 lines
Quoted 5 lines

package/Makefile.in $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \ · line 41

Quoted 3 lines

# Compute GNU_TARGET_NAME

package/Makefile.in +2 -0
+ifeq ($(BR2_TOOLCHAIN_NO_VENDOR),y)
+GNU_TARGET_NAME = $(ARCH)-$(TARGET_OS)-$(LIBC)$(ABI)

Is it really mandatory to *not* have a vendor part of the tuple?

I've tried building arm-buildroot-none-eabi and arm-buildroot-none-newlibeabi, both of which, based on my understanding, should compile, but none of the tools build with that target. Binutils doesn't compile, nor does gcc. I spent some time looking at this, but never found an elegant solution.

Quoted 7 lines

Interesting. I guess we'll have to experiment a bit with this.

I'm adding Yann in Cc. Yann, have you experienced such thing when adding bare-metal/newlib support in Crosstool-NG? I've quickly looked at the Crosstool-NG code, and I don't see the vendor part of the tuple being skipped specifically for bare metal/newlib toolchains, but maybe I missed it.

In fact, that's not the 'vendor' part that is to be removed; it's the 'kernel' part.

A canonical tuple is usually a three-part tuple: arch-vendor-os. But in the case of linux, the 'os' field is split in two: the 'kernel' and 'userland', like so: arch-vendor-kernel-userland.

But really, the 'os' or 'userland' fields mostly denote the ABI being used.

So we end up with things like:

- targets for running Linux:
- i386-blabla-linux-gnu
- powerpc-unknown-linux-gnuspe
- arm-none-linux-gnueabihf
- and so on...

- targets running bare-metal:
- i386-blabla-elf
- powerpc-unknown-spe
- arm-none-eabihf
- and so on...

So, for bare-metal:

- tuples are made of only three-part (in fact the historical canonical

    form),

- the part that is "omitted" from the four-part variant is not the vendor string; rather the 'kernel' and 'userland' fields are merged into one.

However, I'm not sure it is possible to run newlib as the C library under Linux (i.e. as a replacement for glibc/uClibc/musl). IIRC, newlib really targets kernel-less systems. It seems there are linux support files in the newlib source, but I doubt tht is often tested or even compeltely supported; a cursory look at the interwebs does not return promissing results...

And in nay case, I'm afraid a lot of packages would not build against newlib.

All that to say that I need to look at the patch, and I otherwise do not see the point for having newlib in Buildroot...

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#13 lore raw

PATCH 1/3 Experimental addition of the newlib library

Yann, Peter, Chris,

Quoted 30 lines · Yann E. MORIN
Quoted 5 lines

I'm adding Yann in Cc. Yann, have you experienced such thing when adding bare-metal/newlib support in Crosstool-NG? I've quickly looked at the Crosstool-NG code, and I don't see the vendor part of the tuple being skipped specifically for bare metal/newlib toolchains, but maybe I missed it.

In fact, that's not the 'vendor' part that is to be removed; it's the 'kernel' part.

A canonical tuple is usually a three-part tuple: arch-vendor-os. But in the case of linux, the 'os' field is split in two: the 'kernel' and 'userland', like so: arch-vendor-kernel-userland.

But really, the 'os' or 'userland' fields mostly denote the ABI being used.

So we end up with things like:

- targets for running Linux:
- i386-blabla-linux-gnu
- powerpc-unknown-linux-gnuspe
- arm-none-linux-gnueabihf
- and so on...

- targets running bare-metal:
- i386-blabla-elf
- powerpc-unknown-spe
- arm-none-eabihf
- and so on...

Quoted 8 lines

So, for bare-metal:

- tuples are made of only three-part (in fact the historical canonical

    form),

- the part that is "omitted" from the four-part variant is not the vendor string; rather the 'kernel' and 'userland' fields are merged into one.

Thanks a lot for this explanation! It makes a lot more sense now. So, Chris, I guess you have to rework your patch set in this direction:
it's not the vendor part of the tuple that is omitted.

Quoted 7 lines

However, I'm not sure it is possible to run newlib as the C library under Linux (i.e. as a replacement for glibc/uClibc/musl). IIRC, newlib really targets kernel-less systems. It seems there are linux support files in the newlib source, but I doubt tht is often tested or even compeltely supported; a cursory look at the interwebs does not return promissing results...

Quoted 5 lines

And in nay case, I'm afraid a lot of packages would not build against newlib.

All that to say that I need to look at the patch, and I otherwise do not see the point for having newlib in Buildroot...

Chris is the person who submitted the support for the NuttX operating system, which is another operating system kernel than Linux. In this context, newlib is the C library of choice.

Now, there is indeed the question of how to handle all the existing packages that would anyway only build with a normal Linux C library. It's an open debate.

Maybe we first need to get an agreement on whether we want to merge something such a newlib toolchain support and NuttX support. On my side, I believe I am quite favorable to that, but I was also favorable to Luca's patch series on the mdev stuff without devtmpfs, which is why Luca started working on this, but in the end, it got turned down. So this time around, it would be better if Peter could have a look at the original patch from Chris (which definitely wasn't mergeable as is, but was giving an idea of what was needed), and give his opinion on whether we want something like this in Buildroot or not.

My view is that Buildroot is probably easier to use than Crosstool-NG, even to build a simple bare-metal toolchain. Crosstool-NG has too many options, and too many combinations that fail to build. There is a discussion on-going on the crossgcc@ mailing list about that, but I can see the interest in having a simpler to use tool to build bare-metal toolchains.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#14 lore raw

PATCH 1/3 Experimental addition of the newlib library

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thomas" == Thomas Petazzoni <[email protected]> writes:

Hi,

Sorry for the slow response, I've been away and busy with deadlines at $WORK.

Quoted 21 lines
Quoted 7 lines

However, I'm not sure it is possible to run newlib as the C library under Linux (i.e. as a replacement for glibc/uClibc/musl). IIRC, newlib really targets kernel-less systems. It seems there are linux support files in the newlib source, but I doubt tht is often tested or even compeltely supported; a cursory look at the interwebs does not return promissing results...

Quoted 5 lines

And in nay case, I'm afraid a lot of packages would not build against newlib.

All that to say that I need to look at the patch, and I otherwise do not see the point for having newlib in Buildroot...

Chris is the person who submitted the support for the NuttX operating system, which is another operating system kernel than Linux. In this context, newlib is the C library of choice.

Now, there is indeed the question of how to handle all the existing packages that would anyway only build with a normal Linux C library. It's an open debate.

Quoted 5 lines

Maybe we first need to get an agreement on whether we want to merge something such a newlib toolchain support and NuttX support. On my side, I believe I am quite favorable to that, but I was also favorable to Luca's patch series on the mdev stuff without devtmpfs, which is why Luca started working on this, but in the end, it got turned down.

I wouldn't call it "getting turned down", I simply wanted to make it clear that just working around old kernels in mdev wouldn't fix the various other packages that haven't ever been tested on such ancient kernels, and for the mdev issue a simpler fix would just be to backport devtmpfs support to the kernel.

I must say that my initial thought when seeing the newlib patches was that this was really outside the scope of Buildroot, but the patches ARE quite small and self contained, so if there is interest it might make sense after all.

I does require that we basically stick the entire package/ under an ifndef NEWLIB (and system / fs / linux as well), and it will stay a lower priority than the normal Linux stuff, but if that can be done at a high enough level then that is probably ok.

I recently bought one of those cheap arduino clones with a stm32f103 (m3) for tinkering, so I might even use it myself! ;)

Signature · 2 lines
Venlig hilsen,
Peter Korsgaard 
#15 lore raw

PATCH 1/3 Experimental addition of the newlib library

Hello,

Quoted 17 lines · Peter Korsgaard
Quoted 5 lines

Maybe we first need to get an agreement on whether we want to merge something such a newlib toolchain support and NuttX support. On my side, I believe I am quite favorable to that, but I was also favorable to Luca's patch series on the mdev stuff without devtmpfs, which is why Luca started working on this, but in the end, it got turned down.

I wouldn't call it "getting turned down", I simply wanted to make it clear that just working around old kernels in mdev wouldn't fix the various other packages that haven't ever been tested on such ancient kernels, and for the mdev issue a simpler fix would just be to backport devtmpfs support to the kernel.

I must say that my initial thought when seeing the newlib patches was that this was really outside the scope of Buildroot, but the patches ARE quite small and self contained, so if there is interest it might make sense after all.

Quoted 7 lines

I does require that we basically stick the entire package/ under an ifndef NEWLIB (and system / fs / linux as well), and it will stay a lower priority than the normal Linux stuff, but if that can be done at a high enough level then that is probably ok.

I recently bought one of those cheap arduino clones with a stm32f103 (m3) for tinkering, so I might even use it myself! ;)

Great, thanks for the feedback. Then we'll continue to work with Chris to provide a proper solution.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
author
#16 lore raw

PATCH 1/3 Experimental addition of the newlib library

Hi All, Thomas,

Quoted 26 lines · Thomas Petazzoni

Hello,

Quoted 22 lines · Peter Korsgaard
Quoted 5 lines

Maybe we first need to get an agreement on whether we want to merge something such a newlib toolchain support and NuttX support. On my side, I believe I am quite favorable to that, but I was also favorable to Luca's patch series on the mdev stuff without devtmpfs, which is why Luca started working on this, but in the end, it got turned down.

I wouldn't call it "getting turned down", I simply wanted to make it clear that just working around old kernels in mdev wouldn't fix the various other packages that haven't ever been tested on such ancient kernels, and for the mdev issue a simpler fix would just be to backport devtmpfs support to the kernel.

I must say that my initial thought when seeing the newlib patches was that this was really outside the scope of Buildroot, but the patches ARE quite small and self contained, so if there is interest it might make sense after all.

I does require that we basically stick the entire package/ under an ifndef NEWLIB (and system / fs / linux as well), and it will stay a lower priority than the normal Linux stuff, but if that can be done at a high enough level then that is probably ok.

Quoted 6 lines
Quoted 2 lines

I recently bought one of those cheap arduino clones with a stm32f103 (m3) for tinkering, so I might even use it myself! ;)

Great, thanks for the feedback. Then we'll continue to work with Chris to provide a proper solution.

That is great news!

I submitted a few patches a few days ago. How do those look? I'm guessing that is much closer to what you want.

Thanks,
-Chris

Quoted 7 lines

Thanks!

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

#17 lore raw

PATCH 1/3 Experimental addition of the newlib library

In reply to Thomas Petazzoni

Thomas, Cris, All,

On 2015-09-13 10:17 +0200, Thomas Petazzoni spake thusly:

Quoted 6 lines · Chris Wardman
Quoted 4 lines

This patch add support for a newlib library build of the gcc toolchain.
This is designed to build arm-none-eabi- toolchain, and it was tested against an stm32f4discovery board.

Hopefully this will help people build bare metal code for arm processors

[--SNIP--]

Quoted 32 lines
Quoted 32 lines
package/newlib/newlib.mk new file +26 -0
new file mode 100644
index 0000000..02008e5
@@ -0,0 +1,48 @@
+################################################################################
+#
+# newlib
+#
+################################################################################
+
+NEWLIB_VERSION = 2.2.0
+NEWLIB_SITE = ftp://sourceware.org/pub/newlib
+NEWLIB_LICENSE = MIT
+NEWLIB_LICENSE_FILES = COPYRIGHT
+
+NEWLIB_DEPENDENCIES = host-gcc-initial
+NEWLIB_ADD_TOOLCHAIN_DEPENDENCY = NO
+NEWLIB_INSTALL_STAGING = YES
+
+define NEWLIB_CONFIGURE_CMDS
+	(cd $(@D); \
+		$(TARGET_MAKE_ENV) \
+		./configure \
+			--target=$(GNU_TARGET_NAME) \
+			--host=$(GNU_HOST_NAME) \
+			--build=$(GNU_HOST_NAME) \
+			--prefix=$(STAGING_DIR) \
+			--includedir=$(STAGING_DIR)/usr/include \
+			--oldincludedir=$(STAGING_DIR)/usr/include \
+			--with-build-sysroot=$(STAGING_DIR) \
Quoted 8 lines

package/newlib/newlib.mk line 30

Quoted 4 lines
package/newlib/newlib.mk new file +4 -0
+			--enable-newlib-io-long-long \
+			--enable-newlib-register-fini \
+			--disable-newlib-supplied-syscalls \
+			--disable-nls)

Why don't you use the autotools-package infrastructure? newlib is using autoconf, so I believe it does make sense to use the autotools-package infrastructure.

Because newlib does not interpret --build, --host and --target like the other autotools-based packages do. newlib basically ignores --build, considers --host as the buld machine, and --target as the host. :-/

[--SNIP--]

Quoted 6 lines

package/newlib/newlib.mk line 44

Quoted 3 lines
package/newlib/newlib.mk new file +3 -0
+define NEWLIB_INSTALL_STAGING_CMDS
+	mkdir -p $(HOST_DIR)/usr/$(GNU_TARGET_NAME)/lib
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) install

Except the mkdir, the install command is not needed if you use the autotools-package infrastructure.

In which case a pre-install hook can be used to do the mkdir.

But it would probably not be needed if $(GNU_TARGET_NAME) is a symlink to "." .

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

A message that is not in the archive (sent off-list or not yet received): CAOudHSVLKiTwrkv0xBNVW=ry3w1yOv4TJqP8+JMFSJRzw3dASQ@mail.gmail.com

#19 lore raw

PATCH 1/3 Experimental addition of the newlib library

Chris, All,

On 2015-09-15 18:42 -0400, Cjw X spake thusly:
[--SNIP--]

Quoted 10 lines

I'm working on switching it over to be an autotools-package now. Newlib has a fun issue though. Newlib wants to install it's headers in the wrong place with respect to how buildroot builds its tools. When I modified newlib's configure.ac to fix the problem, I selected AUTORECONF for newlib to rebuild the automake tools. However, I get an error that it is the wrong autoreconf version. Apparently, it only works with version 2.64, and we are using version 2.69.

I can comment out the check, which appears to work, but that seems like a poor solution.

In this case, I thing the easiest is just o patch both configure.in and configure, since the change is trivial, and comment in the patch that newlib does not autoreconf, hence the two changes.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
author
#20 lore raw

PATCH 1/3 Experimental addition of the newlib library

In reply to Thomas Petazzoni

Hi Thomas,

I've gotten newlib moved over to the autotools infrastructure. I should be able to post updated patches tonight.

Quoted 7 lines

package/newlib/newlib.mk line 44

Quoted 4 lines
package/newlib/newlib.mk new file +3 -0
+define NEWLIB_INSTALL_STAGING_CMDS
+     mkdir -p $(HOST_DIR)/usr/$(GNU_TARGET_NAME)/lib
+     $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) install

Except the mkdir, the install command is not needed if you use the autotools-package infrastructure.

So, that mkdir command needs to be run, and the it is most closely associated with the staging install.
Is there some way to run mkdir then without overriding the install_staging define? I haven't found anything in the docs.

Thanks,
-Chris

Quoted 8 lines

Thanks a lot!

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

#21 lore raw

PATCH 1/3 Experimental addition of the newlib library

Hello Chris,

Quoted 2 lines · Cjw X

I've gotten newlib moved over to the autotools infrastructure. I should be able to post updated patches tonight.

Good. However, don't hold your breath. While I think adding newlib support is interesting in Buildroot, it may not be the opinion of others.

Quoted 7 lines
Quoted 2 lines

Except the mkdir, the install command is not needed if you use the autotools-package infrastructure.

So, that mkdir command needs to be run, and the it is most closely associated with the staging install.
Is there some way to run mkdir then without overriding the install_staging define? I haven't found anything in the docs.

Search for <pkg>_PRE_INSTALL_STAGING_HOOKS in the documentation, and generally the concept of hooks. See
http://buildroot.org/downloads/manual/manual.html#hooks.

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#22 lore raw

PATCH 1/3 Experimental addition of the newlib library

In reply to Chris Wardman

Chris, All,

On 2015-09-13 03:02 -0400, Chris Wardman spake thusly:

Quoted 4 lines

This patch add support for a newlib library build of the gcc toolchain.
This is designed to build arm-none-eabi- toolchain, and it was tested against an stm32f4discovery board.

Hopefully this will help people build bare metal code for arm processors

OK, I eventually had a bit of time to gave a cusory glance at the patch...

Quoted 1 line

[--SNIP--]

Quoted 8 lines
package/Makefile.in +0 -0
index 545694f..7f4d74e 100644
@@ -37,10 +37,16 @@ $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \
 endif
 
 # Compute GNU_TARGET_NAME

package/Makefile.in $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \ · line 48

Quoted 10 lines
package/Makefile.in +6 -1
+ifeq ($(BR2_TOOLCHAIN_NO_VENDOR),y)
+GNU_TARGET_NAME = $(ARCH)-$(TARGET_OS)-$(LIBC)$(ABI)
+else
 GNU_TARGET_NAME = $(ARCH)-$(TARGET_VENDOR)-$(TARGET_OS)-$(LIBC)$(ABI)
+endif
 
 # FLAT binary format needs uclinux
-ifeq ($(BR2_BINFMT_FLAT),y)
+ifeq ($(BR2_TOOLCHAIN_USES_NEWLIB),y)
+TARGET_OS = none

See how you have to set TARGET_OS=none here? With the change above we've been discussing previously, this would construct a three-part tuple as (because LIBC is empty, too, below):

    $(ARCH)-none-$(ABI)

which is directly in line with what I previosuly explained. Yeah me! :-)

package/Makefile.in ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y) · line 60

Quoted 10 lines
package/Makefile.in +3 -0
+else ifeq ($(BR2_BINFMT_FLAT),y)
 TARGET_OS = uclinux
 else
 TARGET_OS = linux
@@ -50,6 +56,8 @@ ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
 LIBC = uclibc
 else ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y)
 LIBC = musl
+else ifeq ($(BR2_TOOLCHAIN_USES_NEWLIB),y)
+LIBC = 

... here.

package/gcc/gcc-final/gcc-final.mk

Quoted 4 lines
package/Makefile.in +0 -0
 else
 LIBC = gnu
 endif
package/gcc/gcc-final/gcc-final.mk +0 -0

I haven't had a look at the gcc part yet...

[--SNIP--]

package/newlib/newlib-0001-configure-tooldir-path.patch line 6

Quoted 12 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +6 -0
new file mode 100644
index 0000000..c162678
@@ -0,0 +1,25 @@
+This patch is required to fix how the newlib headers are installed. 
+
+The cross compiler expects headers to be in 
+.../host/usr/arm-none-eabi/sysroot/usr/include/newlib.h
+by default newlib installed the headers into 
+.../host/usr/arm-none-eabi/sysroot/arm-none-eabi/include/newlib.h

Wouldn't that be the case for creating the symlink arm-none-eabi -> . as we're doing for some external toolchains?

Quoted 6 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +6 -0
+${exec_prefix} provides the .../host/usr/arm-none-eabi/sysroot path
+${target_noncanonical} provides an extra arm-none-eabi/ that must be removed. 
+
+Signed-off-by: Chris Wardman <[email protected]>
+
+

package/newlib/newlib-0001-configure-tooldir-path.patch line 23

Quoted 10 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +10 -0
+diff -uNr newlib-old/configure newlib-new/configure
+--- newlib-old/configure	2014-07-05 17:09:07.000000000 -0400
++++ newlib-new/configure	2014-12-25 00:59:01.727549186 -0500
+@@ -6985,7 +6985,7 @@
+ 
+ # Some systems (e.g., one of the i386-aix systems the gas testers are
+ # using) don't handle "\$" correctly, so don't use it here.
+-tooldir='${exec_prefix}'/${target_noncanonical}
++tooldir='${exec_prefix}'/usr
+ build_tooldir=${tooldir}

But the patch looks pretty clean...

Quoted 19 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +1 -0
+ # Create a .gdbinit file which runs the one in srcdir
package/newlib/newlib.mk new file +12 -0
new file mode 100644
index 0000000..02008e5
@@ -0,0 +1,48 @@
+################################################################################
+#
+# newlib
+#
+################################################################################
+
+NEWLIB_VERSION = 2.2.0
+NEWLIB_SITE = ftp://sourceware.org/pub/newlib
+NEWLIB_LICENSE = MIT
+NEWLIB_LICENSE_FILES = COPYRIGHT
+
+NEWLIB_DEPENDENCIES = host-gcc-initial

package/newlib/newlib.mk line 22

Quoted 10 lines
package/newlib/newlib.mk new file +10 -0
+NEWLIB_ADD_TOOLCHAIN_DEPENDENCY = NO
+NEWLIB_INSTALL_STAGING = YES
+
+define NEWLIB_CONFIGURE_CMDS
+	(cd $(@D); \
+		$(TARGET_MAKE_ENV) \
+		./configure \
+			--target=$(GNU_TARGET_NAME) \
+			--host=$(GNU_HOST_NAME) \
+			--build=$(GNU_HOST_NAME) \

From what I recall, newlib does not use --build. So you should not have to specify it. At l;east, it was still the case in newlib-2.2.0, released 2014-12-18.

package/newlib/newlib.mk line 26

Quoted 4 lines
package/newlib/newlib.mk new file +4 -0
+			--prefix=$(STAGING_DIR) \
+			--includedir=$(STAGING_DIR)/usr/include \
+			--oldincludedir=$(STAGING_DIR)/usr/include \
+			--with-build-sysroot=$(STAGING_DIR) \

I don't think --includedir, --oldincludedir or --with-build-sysroot are needed.

package/newlib/newlib.mk line 29

Quoted 3 lines
package/newlib/newlib.mk new file +3 -0
+			--enable-newlib-io-long-long \
+			--enable-newlib-register-fini \
+			--disable-newlib-supplied-syscalls \

What about --enable-newlib-io-float or --enable-newlib-io-long-double or --enable-newlib-io-c99-formats?

(I don't really care they be enabled or disabled, just I would not use the defaults; we prefer to force these kind of things explcitly, rather than have nasty surprises, especially when a new version changes the defaults, and especially since a toolchain component is pretty much critical.)

Quoted 8 lines
package/newlib/newlib.mk new file +8 -0
+			--disable-nls)
+
+endef
+
+define NEWLIB_APPLY_PATCHES
+	$(APPLY_PATCHES) $(@D) package/newlib \*.patch
+endef
+

package/newlib/newlib.mk line 47

Quoted 10 lines
package/newlib/newlib.mk new file +10 -0
+define NEWLIB_BUILD_CMDS
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)
+endef
+
+define NEWLIB_INSTALL_STAGING_CMDS
+	mkdir -p $(HOST_DIR)/usr/$(GNU_TARGET_NAME)/lib
+	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) install
+endef
+
+$(eval $(generic-package))

Maybe you can make that an autootols package, since it *is* an autotools package. It's just that we're redefining the configure command.

But you're also not providing target-install commands, so you may also want to add:

NEWLIB_INSTALL_TARGET = NO

And then you can indeed make it an autootls-package. :-)

toolchain/toolchain-buildroot/Config.in config BR2_TOOLCHAIN_BUILDROOT_MUSL · line 99

Quoted 11 lines
toolchain/toolchain-buildroot/Config.in +3 -0
index 13e2b15..c11db73 100644
@@ -94,6 +94,14 @@ config BR2_TOOLCHAIN_BUILDROOT_MUSL
 	  This option selects musl as the C library for the
 	  cross-compilation toolchain.
 
+config BR2_TOOLCHAIN_BUILDROOT_NEWLIB
+       bool "newlib (experimental)"
+       depends on BR2_arm

Why only arm? newlib has support for other architectures. In fact, I would gues that all architectures that Buildroot supports are also supported in newlib.

Note: for glibc and uClibc, we have a choice to select the version. Do we also want to add such a version selection (especially a custom version) for newlib, too?

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
author
#23 lore raw

PATCH 1/3 Experimental addition of the newlib library

Hi Yann, all,

I just sent out a patch that I think addresses the reviews given.

Some minor comments below.

Quoted 141 lines · Yann E. MORIN

Chris, All,

On 2015-09-13 03:02 -0400, Chris Wardman spake thusly:

Quoted 4 lines

This patch add support for a newlib library build of the gcc toolchain.
This is designed to build arm-none-eabi- toolchain, and it was tested against an stm32f4discovery board.

Hopefully this will help people build bare metal code for arm processors

OK, I eventually had a bit of time to gave a cusory glance at the patch...

Quoted 1 line

[--SNIP--]

Quoted 8 lines
package/Makefile.in +0 -0
index 545694f..7f4d74e 100644
@@ -37,10 +37,16 @@ $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \
 endif
 
 # Compute GNU_TARGET_NAME

package/Makefile.in $(error BR2_TOOLCHAIN_BUILDROOT_VENDOR cannot be 'unknown'. \ · line 48

Quoted 10 lines
package/Makefile.in +6 -1
+ifeq ($(BR2_TOOLCHAIN_NO_VENDOR),y)
+GNU_TARGET_NAME = $(ARCH)-$(TARGET_OS)-$(LIBC)$(ABI)
+else
 GNU_TARGET_NAME = $(ARCH)-$(TARGET_VENDOR)-$(TARGET_OS)-$(LIBC)$(ABI)
+endif
 
 # FLAT binary format needs uclinux
-ifeq ($(BR2_BINFMT_FLAT),y)
+ifeq ($(BR2_TOOLCHAIN_USES_NEWLIB),y)
+TARGET_OS = none

See how you have to set TARGET_OS=none here? With the change above we've been discussing previously, this would construct a three-part tuple as (because LIBC is empty, too, below):

    $(ARCH)-none-$(ABI)

which is directly in line with what I previosuly explained. Yeah me! :-)

package/Makefile.in ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y) · line 60

Quoted 10 lines
package/Makefile.in +3 -0
+else ifeq ($(BR2_BINFMT_FLAT),y)
 TARGET_OS = uclinux
 else
 TARGET_OS = linux
@@ -50,6 +56,8 @@ ifeq ($(BR2_TOOLCHAIN_USES_UCLIBC),y)
 LIBC = uclibc
 else ifeq ($(BR2_TOOLCHAIN_USES_MUSL),y)
 LIBC = musl
+else ifeq ($(BR2_TOOLCHAIN_USES_NEWLIB),y)
+LIBC =

... here.

package/gcc/gcc-final/gcc-final.mk

Quoted 4 lines
package/Makefile.in +0 -0
 else
 LIBC = gnu
 endif
package/gcc/gcc-final/gcc-final.mk +0 -0

I haven't had a look at the gcc part yet...

[--SNIP--]

package/newlib/newlib-0001-configure-tooldir-path.patch line 6

Quoted 12 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +6 -0
new file mode 100644
index 0000000..c162678
@@ -0,0 +1,25 @@
+This patch is required to fix how the newlib headers are installed.
+
+The cross compiler expects headers to be in
+.../host/usr/arm-none-eabi/sysroot/usr/include/newlib.h
+by default newlib installed the headers into
+.../host/usr/arm-none-eabi/sysroot/arm-none-eabi/include/newlib.h

Wouldn't that be the case for creating the symlink arm-none-eabi -> . as we're doing for some external toolchains?

Quoted 6 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +6 -0
+${exec_prefix} provides the .../host/usr/arm-none-eabi/sysroot path
+${target_noncanonical} provides an extra arm-none-eabi/ that must be removed.
+
+Signed-off-by: Chris Wardman <[email protected]>
+
+

package/newlib/newlib-0001-configure-tooldir-path.patch line 23

Quoted 10 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +10 -0
+diff -uNr newlib-old/configure newlib-new/configure
+--- newlib-old/configure     2014-07-05 17:09:07.000000000 -0400
++++ newlib-new/configure     2014-12-25 00:59:01.727549186 -0500
+@@ -6985,7 +6985,7 @@
+
+ # Some systems (e.g., one of the i386-aix systems the gas testers are
+ # using) don't handle "\$" correctly, so don't use it here.
+-tooldir='${exec_prefix}'/${target_noncanonical}
++tooldir='${exec_prefix}'/usr
+ build_tooldir=${tooldir}

But the patch looks pretty clean...

Quoted 19 lines
package/newlib/newlib-0001-configure-tooldir-path.patch new file +1 -0
+ # Create a .gdbinit file which runs the one in srcdir
package/newlib/newlib.mk new file +12 -0
new file mode 100644
index 0000000..02008e5
@@ -0,0 +1,48 @@
+################################################################################
+#
+# newlib
+#
+################################################################################
+
+NEWLIB_VERSION = 2.2.0
+NEWLIB_SITE = ftp://sourceware.org/pub/newlib
+NEWLIB_LICENSE = MIT
+NEWLIB_LICENSE_FILES = COPYRIGHT
+
+NEWLIB_DEPENDENCIES = host-gcc-initial

package/newlib/newlib.mk line 22

Quoted 10 lines
package/newlib/newlib.mk new file +10 -0
+NEWLIB_ADD_TOOLCHAIN_DEPENDENCY = NO
+NEWLIB_INSTALL_STAGING = YES
+
+define NEWLIB_CONFIGURE_CMDS
+     (cd $(@D); \
+             $(TARGET_MAKE_ENV) \
+             ./configure \
+                     --target=$(GNU_TARGET_NAME) \
+                     --host=$(GNU_HOST_NAME) \
+                     --build=$(GNU_HOST_NAME) \

From what I recall, newlib does not use --build. So you should not have to specify it. At l;east, it was still the case in newlib-2.2.0, released 2014-12-18.

package/newlib/newlib.mk line 26

Quoted 4 lines
package/newlib/newlib.mk new file +4 -0
+                     --prefix=$(STAGING_DIR) \
+                     --includedir=$(STAGING_DIR)/usr/include \
+                     --oldincludedir=$(STAGING_DIR)/usr/include \
+                     --with-build-sysroot=$(STAGING_DIR) \

I don't think --includedir, --oldincludedir or --with-build-sysroot are needed.

package/newlib/newlib.mk line 29

Quoted 3 lines
package/newlib/newlib.mk new file +3 -0
+                     --enable-newlib-io-long-long \
+                     --enable-newlib-register-fini \
+                     --disable-newlib-supplied-syscalls \
Quoted 9 lines

What about --enable-newlib-io-float or --enable-newlib-io-long-double or --enable-newlib-io-c99-formats?

(I don't really care they be enabled or disabled, just I would not use the defaults; we prefer to force these kind of things explcitly, rather than have nasty surprises, especially when a new version changes the defaults, and especially since a toolchain component is pretty much critical.)

I never went through the flag options in detail. I took the options from a 'known good' build of the toolchain which was designed to run with this target.

At one point I did try to go through the options in detail, but found that I did not get the results I expected.

If we decide to include newlib in the buildroot, I think it would be very valuable to figure out the different options and potentially add config options to select them (or make them dependent on other selections).

I think it would also be valuable to provide the option to use specific versions newlib.

Thanks!
-Chris

Quoted 59 lines
Quoted 8 lines
package/newlib/newlib.mk new file +8 -0
+                     --disable-nls)
+
+endef
+
+define NEWLIB_APPLY_PATCHES
+     $(APPLY_PATCHES) $(@D) package/newlib \*.patch
+endef
+

package/newlib/newlib.mk line 47

Quoted 10 lines
package/newlib/newlib.mk new file +10 -0
+define NEWLIB_BUILD_CMDS
+     $(TARGET_MAKE_ENV) $(MAKE) -C $(@D)
+endef
+
+define NEWLIB_INSTALL_STAGING_CMDS
+     mkdir -p $(HOST_DIR)/usr/$(GNU_TARGET_NAME)/lib
+     $(TARGET_MAKE_ENV) $(MAKE) -C $(@D) install
+endef
+
+$(eval $(generic-package))

Maybe you can make that an autootols package, since it *is* an autotools package. It's just that we're redefining the configure command.

But you're also not providing target-install commands, so you may also want to add:

NEWLIB_INSTALL_TARGET = NO

And then you can indeed make it an autootls-package. :-)

toolchain/toolchain-buildroot/Config.in config BR2_TOOLCHAIN_BUILDROOT_MUSL · line 99

Quoted 11 lines
toolchain/toolchain-buildroot/Config.in +3 -0
index 13e2b15..c11db73 100644
@@ -94,6 +94,14 @@ config BR2_TOOLCHAIN_BUILDROOT_MUSL
        This option selects musl as the C library for the
        cross-compilation toolchain.
 
+config BR2_TOOLCHAIN_BUILDROOT_NEWLIB
+       bool "newlib (experimental)"
+       depends on BR2_arm

Why only arm? newlib has support for other architectures. In fact, I would gues that all architectures that Buildroot supports are also supported in newlib.

Note: for glibc and uClibc, we have a choice to select the version. Do we also want to add such a version selection (especially a custom version) for newlib, too?

Regards,
Yann E. MORIN.

--
.-----------------.--------------------.------------------.--------------------.

|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |

'------------------------------^-------^------------------^--------------------'