Changing Configuration for a Newlib build

Stan Katz
Tue Aug 16 19:11:00 GMT 2005

Hi all,

I have a couple of questions on configuring newlib. The short version of
the question is how do I add macros and flags to a variation of a build.
The rest of this post is some additional details on what I'm trying to

I am trying to get a version of newlib that will handle task switching
(uCos) on an ARM without adding too much overhead to the task switch. I
have only a few threads that really need to handle system calls (mostly
I/O related) and having a reent structure for each thread, and needing
the OS task switch to change the impure pointer on all context switches
will add more overhead than I want. It will also need changes at the OS
level, which I would prefer to avoid.

Looking at the sources, I decided to try using the __getreent function,
that allowed me to have any thread that needed to use syscalls register
with the module (that I have added) and provide a reentrant structure.
If the thread that is active when the reentrant syscall is made has
registered then the __getreent function call will return a pointer to
the correct structure for that thread, otherwise it returns a pointer to
the default structure.

It seems that I can get the options I need if I build newlib with the
macro __DYNAMIC_REENT__ defined and __SINGLE_THREAD__ not defined. In
addition, since I am providing the reentrant versions of the syscalls I
also defined the REENTRANT_SYSCALLS_PROVIDED macro.

Based on Bill Gatliff's article on porting newlib, I ran the standard
configure script for newlib (--target-arm-elf
--prefix=/home/stan/newlib-re). I then changed the top level makefile
generated by the configure script by changing the value of the
CFLAGS_FOR_TARGET variable, however I found that this did not build
correctly and looking at the commands executed, it seems that the
CFLAGS_FOR_TARGET is not passed through to the lower level make in the
libgloss directory. I found that I could get it working if I made the
changes to the FLAGS_FOR_TARGET variable instead.

The library now seems to be working, but I have found that I need to add
the same flags (or at least define the __DYNAMIC_REENT__ macro) when I
build my application that will use the new library.

The first question is whether modifying FLAGS_FOR_TARGET is an
acceptable way to generate a variation on the basic configuration? Is
there any potential problem doing this instead of CFLAGS_FOR_TARGET
(aside from the issue that CFLAGS_FOR_TARGET doesn't work for me)? Is
there any specific reason for there to be the 2 different variables?

The second question is about changing the library header files so that
the macros are automatically defined when the correct library header
path is defined. It seems that the sys and machine subdirectories of the
library include directory do contain system specific macros. I was
simply going to add the necessary macros to sys/param.h but I see that
this isn't automatically included by reent.h. 

Looking at reent.h (which is where the macros need to be defined to get
the build to work with the revised library) seems to indicate that the
changes need to either go there or in sys/_types.h, neither of which
seem to be a clean configuration point.

I also have a concern about the multilib aspect, do I need to duplicate
the changes to the header file throughout the library tree, since there
are multiple incarnations of the directories and files.

I am looking for a way to (in order of preference)
Add some parameters/options when running the configuration script that
will add the necessary macros where they will be used in the build.
Change the makefile generated by the configure to add the necessary
macros to the generated header files. Add a new configuration option for
newlib - and if this is the way to go, some pointers on where the
changes should go. From the FAQ it seems that I may only need to change
newlib/libc/include/sys/config.h but it would be nice if someone could
confirm that.

Thanks for taking the time to read this ramble, any help would be
greatly appreciated.

Stan Katz

More information about the Newlib mailing list