This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Make string.h strsignal prototype return const char *
- From: Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>
- To: newlib at sources dot redhat dot com
- Date: Thu, 20 Jan 2005 02:51:59 +0100
- Subject: Make string.h strsignal prototype return const char *
Without this patch, I get an error building the "elinux"
cris-axis-aout(!) libiberty multilib. It seems that a target
that defines __linux__ but doesn't use newlib/libc/sys/linux
(which seems very i386-specific) and doesn't provide a strsignal
function by some other means, can't build newlib and target
libiberty files currently, as in a combined newlib+binutils+gcc
build. It's arguable that such a target would be a bit out of
line, but the build does break for the wrong reasons
(cutnpasted):
/home/hp/cvs_areas/combined/cris-aout-obj/gcc/xgcc -B/home/hp/cvs_areas/combined/cris-aout-obj/gcc/ -nostdinc -B/home/hp/cvs_area\
s/combined/cris-aout-obj/cris-axis-aout/newlib/ -isystem /home/hp/cvs_areas/combined/cris-aout-obj/cris-axis-aout/newlib/targ-inc\
lude -isystem /home/hp/cvs_areas/combined/combined/newlib/libc/include -B/tmp/cris-aout/cris-axis-aout/bin/ -B/tmp/cris-aout/cris\
-axis-aout/lib/ -isystem /tmp/cris-aout/cris-axis-aout/include -isystem /tmp/cris-aout/cris-axis-aout/sys-include -L/home/hp/cvs_\
areas/combined/cris-aout-obj/ld -c -DHAVE_CONFIG_H -O2 -g -O2 -melinux -mbest-lib-options -I. -I/home/hp/cvs_areas/combined/comb\
ined/libiberty/../include -W -Wall -Wtraditional -pedantic /home/hp/cvs_areas/combined/combined/libiberty/strsignal.c -o strsign\
al.o
/home/hp/cvs_areas/combined/combined/libiberty/strsignal.c:413: error: conflicting types for 'strsignal'
/home/hp/cvs_areas/combined/combined/newlib/libc/include/string.h:79: error: previous declaration of 'strsignal' was here
/home/hp/cvs_areas/combined/combined/libiberty/strsignal.c: In function 'psignal':
/home/hp/cvs_areas/combined/combined/libiberty/strsignal.c:567: warning: comparison between signed and unsigned
make[4]: *** [strsignal.o] Error 1
make[4]: Leaving directory `/home/hp/cvs_areas/combined/cris-aout-obj/cris-axis-aout/elinux/libiberty'
The compilation error is due to a mismatch between the libiberty
and newlib prototypes, and it seems the libiberty prototype is
the correct one. I haven't actually compiled a target using
sys/linux to test the libc/sys/linux/strsignal.c patch, but I
modified it and test-compiled the core code with the host gcc
(3.2.2) -W -Wall to try and make sure no errors or warnings
would happen. It seems this change should actually get rid of a
warning when compiling strsignal.c; with the previous
definition, the "return sigstring[sig];" was stripping a const,
i.e. there should at least have been a cast to avoid warnings,
as in "return (char *) sigstring[sig];".
An alternative approach would be to change the "#elif
defined(__linux__)" seen below to "#elif defined(__linux__) &&
!defined (__i386__)", but that seems to just make an unnecessary
assumption that sys/linux will always be i386-specific.
BTW, the cris-elf target seems ok with no further changes to
core newlib+libgloss; gcc test-results look sane with the
recently submitted simulator. Soonish...
2005-01-20 Hans-Peter Nilsson <hp@axis.com>
* libc/include/string.h (strsignal): Make return type "const char *".
* libc/sys/linux/strsignal.c (strsignal): Ditto.
Index: libc/include/string.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/string.h,v
retrieving revision 1.14
diff -c -p -u -p -r1.14 string.h
cvs diff: conflicting specifications of output style
--- libc/include/string.h 23 Jul 2002 21:38:00 -0000 1.14
+++ libc/include/string.h 20 Jan 2005 00:55:56 -0000
@@ -76,7 +76,7 @@ const char *_EXFUN(strsignal, (int __si
#endif
int _EXFUN(strtosigno, (const char *__name));
#elif defined(__linux__)
-char *_EXFUN(strsignal, (int __signo));
+const char *_EXFUN(strsignal, (int __signo));
#endif
/* These function names are used on Windows and perhaps other systems. */
Index: libc/sys/linux/strsignal.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/linux/strsignal.c,v
retrieving revision 1.1
diff -c -p -u -p -r1.1 strsignal.c
cvs diff: conflicting specifications of output style
--- libc/sys/linux/strsignal.c 5 Jun 2002 20:58:58 -0000 1.1
+++ libc/sys/linux/strsignal.c 20 Jan 2005 00:55:56 -0000
@@ -39,7 +39,7 @@ static const char *sigstring[] =
"User defined signal 2"
};
-char *
+const char *
strsignal (int sig)
{
if (sig < 0 || sig >= __SIGRTMIN)
brgds, H-P