This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: _write, _read replacement
- From: Darin Johnson <chezdj at earthlink dot net>
- To: rekisum at web dot de, newlib at sources dot redhat dot com
- Date: Tue, 10 Jan 2006 14:05:37 -0500 (EST)
- Subject: Re: _write, _read replacement
- Reply-to: Darin Johnson <darin at usa dot net>
>From: rekisum@web.de
>
>Hi,
>searching this list, I found I have do replace _read and _write
>from syscalls.c with my own implementation to get printf to work on my chip.
>So do I have to rebuild the whole library or how to replace this functions?
Maybe this doesn't exactly answer your question, but some advice
anyway. If the linker command specifies an object file, it will be
linked in before examining any libraries (ie, .o files before .a).
So one solution if possible, is to link to your own object file
directly, instead of an object file that is within a library. Then
your version will always be used, and will override versions in libc
or libgloss.
Alternately, make sure that whatever object file your write() function
is in is referenced before anything in libc references write(). This
can require a bit more thought. Ie, if your object file has both
write() and my_system_init(), then make sure that one of your object
files listed on the link command line references my_system_init().
Finally, you could make sure that you've got write() included in
libnosys.a, not libc.a, which is a configuration time option. Then
in your command line, make sure that your library appears before
libgloss. As in:
gcc x.o y.o z.o libc.a myoverrides.a libnosys.a
Then if newlib references write(), it will find it first in your
own library before searching through libnosys.a.
My code looks something like this, since it overrides libnosys.a
instead of libc.a:
int write (int file, const char *ptr, int len)
{
if (file == 1 || file == 2) // stdout/stderr
{
// output string, converting /n to /r/n
// ...
return len;
}
else
{
errno = ENOSYS;
return -1;
}
}
--
Darin