Possible bug at newlib/libc/rtems/sys/crt0.c sigfillset

Joel Sherrill joel.sherrill at OARcorp.com
Mon Apr 28 16:02:07 UTC 2014


Hi

I am not sure I got everything fixed but it should be a lot
better now. See the attached diffs.

+ libgcc - patterns were in the wrong order and or1k*-*-rtems*
   or1k*-*-* was before rtems stanza
+ config/or1k - moved elf.h to rtemself.h. There should be
  a target OS independent config/or1k/elf.h
  Also fixed or1k/rtemself.h so it defines CPP predefines
  including __rtems__ which explains your compilation problem.
+ newlib/.../rtems/crt0 had wrong prototypes for write() and
  read().

These are diffs against the sources with your patches applied.

Apply on top of yours.

It is still building here after clobbering the tree and starting
over so there may be more problems but this should be
a good start. :)

--joel


On 4/27/2014 7:26 PM, Joel Sherrill wrote:
> This is a bug in your gcc port. You need to ensure that __rtems__ is defined.
>
> See https://github.com/heshamelmatary/or1k-rtems/blob/master/patches/gcc-4.8.2-or1k-rtems.diff
> around 220 and compare it to 
> http://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/arm/rtems-eabi.h;h=4bdcf0d87ba68940f338f4de3b41b9bd7a47260f;hb=HEAD
>
> That defines __rtems__. Without that, the .h files in newlib don't get the right settings.
> ________________________________________
> From: rtems-devel-bounces at rtems.org [rtems-devel-bounces at rtems.org] On Behalf Of Joel Sherrill [Joel.Sherrill at oarcorp.com]
> Sent: Sunday, April 27, 2014 7:17 PM
> To: Hesham Moustafa
> Cc: rtems-devel at rtems.org
> Subject: Re: Possible bug at newlib/libc/rtems/sys/crt0.c sigfillset
>
> On Apr 27, 2014 6:40 PM, Joel Sherrill <Joel.Sherrill at oarcorp.com> wrote:
>>
>> On Apr 27, 2014 5:12 PM, Hesham Moustafa <heshamelmatary at gmail.com> wrote:
>>> Hi all,
>>>
>>> When I am trying to get newlib compiled while porting newlib to
>>> rtems/or1k, I met an error that confused me. The error happens for me
>>> with both: Ubuntu and Fedora. Also it arises when configuring and
>>> building a standalone newlib library (with configure
>>> --target=or1k-rtems4.11) or when building gcc with newlib (for the
>>> same target). By commenting that line, newlib and gcc building process
>>> works fine.
>>>
>>> The error is:
>>>
>>> "../../../../../../../gcc-4.8.2-or1k-rtems/newlib/libc/sys/rtems/crt0.c:74:37:
>>> error: expected ‘)’ before ‘*’ token
>>>  RTEMS_STUB(int, sigfillset(sigset_t *set), { return -1; })"
>>>
>>> By expanding the macros with -E option, I got the following expansion
>>> for the corresponding function:
>>>
>>> int rtems_stub_sigfillset(sigset_t *set) { return -1; }; int
>>> (*(sigset_t *set) = ~(0), 0) { return -1; }
>>>
>>> Does that make sense?
>>>
>>> I searched for anyone that happened to have the same problem and I
>>> found this link [1] related to compiling rtems/newlib for microblaze
>> This is a new architecture for RTEMS+newlib combination. I recall that there is a configure script near the top of newlib and it needs an entry for thus target. Or a pattern needs adjusting to distinguish or1k*-*-* from the RTEMS variant.
> This can also be because the path through signal.h is skipping something based on or1k.
>
> What source are you using as base to modify? I need to clone all your source and try it myself.
>
>>> [1] http://sourceware.org/ml/newlib/2012/msg00529.html
>>>
>>> Regards,
>>> Hesham
>>>
>>> _______________________________________________
>>> rtems-devel mailing list
>>> rtems-devel at rtems.org
>>> http://www.rtems.org/mailman/listinfo/rtems-devel

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985

-------------- next part --------------
diff -uNr --exclude '*newlib*' gcc-4.8.2-orig/gcc/config/or1k/elf.h gcc-4.8.2/gcc/config/or1k/elf.h
--- gcc-4.8.2-orig/gcc/config/or1k/elf.h	2014-04-28 10:45:18.320114849 -0500
+++ gcc-4.8.2/gcc/config/or1k/elf.h	1969-12-31 18:00:00.000000000 -0600
@@ -1,31 +0,0 @@
-/* Definitions for rtems targeting an OpenRisc OR1K using COFF
-   ??? this is for OR1K, but the rest of the above seems bogus.
-   Copyright (C) 1996, 1997, 2005 Free Software Foundation, Inc.
-   Contributed by Joel Sherrill (joel at OARcorp.com).
-
-This file is part of GNU CC.
-
-GNU CC is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU CC is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
-
-/* Use ELF */
-#undef  OBJECT_FORMAT_ELF
-#define OBJECT_FORMAT_ELF
-
-/* or1k debug info support is controlled by tm.h header files we include:
-   dbxelf.h enables optional stabs debug info.
-   elfos.h sets PREFERRED_DEBUGGING_TYPE to DWARF2_DEBUG .  */
-
-#define DRIVER_SELF_SPECS "%{!mno-newlib:-mnewlib}"
diff -uNr --exclude '*newlib*' gcc-4.8.2-orig/gcc/config/or1k/rtemself.h gcc-4.8.2/gcc/config/or1k/rtemself.h
--- gcc-4.8.2-orig/gcc/config/or1k/rtemself.h	1969-12-31 18:00:00.000000000 -0600
+++ gcc-4.8.2/gcc/config/or1k/rtemself.h	2014-04-28 09:18:15.271590730 -0500
@@ -0,0 +1,45 @@
+/* Definitions for rtems targeting an OpenRisc OR1K using ELF
+
+   Copyright (C) 1996, 1997, 2005 Free Software Foundation, Inc.
+   Contributed by Joel Sherrill (joel at OARcorp.com).
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/* Use ELF */
+#undef  OBJECT_FORMAT_ELF
+#define OBJECT_FORMAT_ELF
+
+/* what does this comment go to?
+/* or1k debug info support is controlled by tm.h header files we include:
+   dbxelf.h enables optional stabs debug info.
+   elfos.h sets PREFERRED_DEBUGGING_TYPE to DWARF2_DEBUG .  */
+
+/* RTEMS always uses newlib */
+#undef DRIVER_SELF_SPECS
+
+/* Target OS builtins.  */
+#undef TARGET_OS_CPP_BUILTINS
+#define TARGET_OS_CPP_BUILTINS()		\
+  do						\
+    {						\
+	builtin_define_std ("or1k");		\
+	builtin_define ("__USE_INIT_FINI__");	\
+	builtin_define ("__rtems__");		\
+	builtin_assert ("system=rtems");	\
+    }						\
+  while (0)
diff -uNr --exclude '*newlib*' gcc-4.8.2-orig/gcc/config.gcc gcc-4.8.2/gcc/config.gcc
--- gcc-4.8.2-orig/gcc/config.gcc	2014-04-28 10:45:18.325114875 -0500
+++ gcc-4.8.2/gcc/config.gcc	2014-04-28 09:19:03.849841647 -0500
@@ -1982,7 +1982,7 @@
        tm_defines="${tm_defines} OR1K_DELAY_DEFAULT=OR1K_DELAY_ON"
        ;;
 or1k-*-rtems*)
-       tm_file="${tm_file} dbxelf.h elfos.h newlib-stdint.h ${cpu_type}/elf.h"
+       tm_file="${tm_file} dbxelf.h elfos.h newlib-stdint.h ${cpu_type}/rtemself.h"
        extra_parts="crti.o crtbegin.o crtend.o crtn.o"
        tmake_file=or1k/t-or1k
        tm_defines="${tm_defines} OR1K_DELAY_DEFAULT=OR1K_DELAY_ON"
diff -uNr --exclude '*newlib*' gcc-4.8.2-orig/libgcc/config.host gcc-4.8.2/libgcc/config.host
--- gcc-4.8.2-orig/libgcc/config.host	2014-04-28 10:45:18.632116483 -0500
+++ gcc-4.8.2/libgcc/config.host	2014-04-28 10:59:09.375463746 -0500
@@ -807,11 +807,11 @@
 	tmake_file="$tmake_file or1k/t-or1k or1k/t-linux or1k/t-crtstuff t-softfp-sfdf t-softfp"
 	md_unwind_header=or1k/linux-unwind.h
 	;;
-or1k*-*-*)
+or1k*-*-rtems*)
 	tmake_file="$tmake_file or1k/t-or1k or1k/t-linux or1k/t-crtstuff t-softfp-sfdf t-softfp"
 	extra_parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o crti.o crtn.o"
 	;;
-or1k*-rtems*)
+or1k*-*-*)
 	tmake_file="$tmake_file or1k/t-or1k or1k/t-linux or1k/t-crtstuff t-softfp-sfdf t-softfp"
 	extra_parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o crti.o crtn.o"
 	;;
Binary files gcc-4.8.2-orig/libgcc/.config.host.swp and gcc-4.8.2/libgcc/.config.host.swp differ
-------------- next part --------------
diff -ur newlib-2.1.0-orig/newlib/libc/sys/rtems/crt0.c newlib-2.1.0/newlib/libc/sys/rtems/crt0.c
--- newlib-2.1.0-orig/newlib/libc/sys/rtems/crt0.c	2014-04-28 10:45:34.705200645 -0500
+++ newlib-2.1.0/newlib/libc/sys/rtems/crt0.c	2014-04-28 10:40:11.216495185 -0500
@@ -69,7 +69,7 @@
 RTEMS_STUB(int, lstat(const char *path, struct stat *buf), { return -1; })
 RTEMS_STUB(int, open(const char *pathname, int flags, int mode), { return -1; })
 RTEMS_STUB(int, pipe(int pipefd[2]), { return -1; })
-RTEMS_STUB(int, read(int fd, void *buf, size_t count), { return -1; })
+RTEMS_STUB(ssize_t, read(int fd, void *buf, size_t count), { return -1; })
 RTEMS_STUB(int, sched_yield(void), { return -1; })
 //RTEMS_STUB(int, sigfillset(sigset_t *set), { return -1; })
 RTEMS_STUB(int, sigprocmask(int how, const sigset_t *set, sigset_t *oldset), { return -1; })
@@ -80,7 +80,7 @@
 /* pulled in by libc/sys/posix/popen.c and libc/sys/posix/word*.c */
 RTEMS_STUB(int, waitpid (pid_t pid, int *status, int options), { return -1; })
 #endif
-RTEMS_STUB(int, write (int fd, const void *buf, size_t nbytes), { return -1; })
+RTEMS_STUB(ssize_t, write (int fd, const void *buf, size_t nbytes), { return -1; })
 
 /* stubs for functions from reent.h */
 RTEMS_STUB(int, _close_r (struct _reent *r, int fd), { return -1; })


More information about the devel mailing list