Re: Failure to build GPC under Linux

Waldek Hebisch <[email protected]> Sat, 16 May 2020 15:34:13 +0200
Newsgroups gmane.comp.compilers.gpc
Message-ID <[email protected]>
--45Z9DzgjV8m4Oswq
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sun, May 10, 2020 at 07:18:01PM -0700, John Ries wrote:
> The error messages are:
> 
> ../../gcc-4.3.5/gcc/toplev.c:545:1: error: redefinition of ???floor_log2???
>   545 | floor_log2 (unsigned HOST_WIDE_INT x)
>       | ^~~~~~~~~~
> In file included from ../../gcc-4.3.5/gcc/toplev.c:58:
> ../../gcc-4.3.5/gcc/toplev.h:177:1: note: previous definition of
> ???floor_log2??? wa
> s here
>   177 | floor_log2 (unsigned HOST_WIDE_INT x)
>       | ^~~~~~~~~~
> ../../gcc-4.3.5/gcc/toplev.c:580:1: error: redefinition of ???exact_log2???
>   580 | exact_log2 (unsigned HOST_WIDE_INT x)
>       | ^~~~~~~~~~
> In file included from ../../gcc-4.3.5/gcc/toplev.c:58:
> ../../gcc-4.3.5/gcc/toplev.h:183:1: note: previous definition of
> ???exact_log2??? wa
> s here
>   183 | exact_log2 (unsigned HOST_WIDE_INT x)
>       | ^~~~~~~~~~
> 
> There is probably a GCC flag to allow such duplicate definitions, but I
> haven't found it yet (apparently, it isn't -Wnoduplicate-decl-specifier).
> I'm using the GCC 4.3.5 codebase and building with GCC 9.3.1 under Fedora
> 31 (x86_64).
> 
> I'm running configure as follows:
> 
> SRCDIR=../gcc-4.3.5
> export CFLAGS ="-fkeep-inline-functions -W -Wall -Wwrite-strings \
>                 -Wstrict-prototypes -Wmissing-prototypes \
>                 -Wold-style-definition -Wmissing-format-attribute \
>                 -pedantic -Wno-long-long -Wno-variadic-macros \
>                 -Wno-overlength-strings -fno-common \
>                 -Wnoduplicate-decl-specifier"
> 
> $SRCDIR/configure --program-suffix=-4.3.5 --disable-shared \
>                   --enable-languages=pascal
> 
> The definition of CFLAGS was my attempt to allow the code to compile.  It
> made no difference.
> 
> Any ideas as to how to proceed would be greatly appreciated.

To compile with gcc-4.3.6 on Debian 10 I need two attached patches.
First one fixes to problem above and a few other problems.

The second patch is a gross hack, to work around major breakage
due to changes in Debian.  Namely, Debian moved several critical
files to archtecture specific subdirectories.  For example,
instead of

/usr/lib/crti.o

there is

/usr/lib/x86_64-linux-gnu/crti.o

(or analogous thing for different architecture).  Notably,
compilation of GPC is affected by location of C include files.
If most C include files are in

/usr/include/x86_64-linux-gnu

then your system is affected.  ATM I do not know which distributions
use this scheme and which switched to Debian way.  The
second patch somewhat handles this issue.  It is unstatisfactory,
as it hardcodes 'x86_64-linux-gnu' and there is some (small ???)
breakage when compiling C files (this affects mixed Pascal and C
projects).  Anyway, with both patches applied I can compile
GPC on top of gcc-4.3.6 in Debian 10 using configure line:

../gcc-4.3.6.nn2/configure --enable-languages=c,pascal --disable-multilib --disable-mapped-location

Note that I always compile in directory separate from sources,
that is reason for '../' at the start. '.nn2' suffix is to
indicate that this is patched gcc (with two attached patches and
gcc-4.3.5 patch).


-- 
                              Waldek Hebisch

--45Z9DzgjV8m4Oswq
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="sum1.diff"

diff -ru gcc-4.3.6/gcc/config/i386/linux-unwind.h gcc-4.3.6.nn2/gcc/config/i386/linux-unwind.h
--- gcc-4.3.6/gcc/config/i386/linux-unwind.h	2006-10-26 21:31:09.000000000 +0200
+++ gcc-4.3.6.nn2/gcc/config/i386/linux-unwind.h	2020-05-16 02:46:26.499025550 +0200
@@ -51,7 +51,7 @@
   if (*(unsigned char *)(pc+0) == 0x48
       && *(unsigned long *)(pc+1) == 0x050f0000000fc0c7)
     {
-      struct ucontext *uc_ = context->cfa;
+      ucontext_t *uc_ = context->cfa;
       /* The void * cast is necessary to avoid an aliasing warning.
          The aliasing warning is correct, but should not be a problem
          because it does not alias anything.  */
@@ -140,7 +140,7 @@
 	struct siginfo *pinfo;
 	void *puc;
 	struct siginfo info;
-	struct ucontext uc;
+	ucontext_t uc;
       } *rt_ = context->cfa;
       /* The void * cast is necessary to avoid an aliasing warning.
          The aliasing warning is correct, but should not be a problem
diff -ru gcc-4.3.6/gcc/doc/c-tree.texi gcc-4.3.6.nn2/gcc/doc/c-tree.texi
--- gcc-4.3.6/gcc/doc/c-tree.texi	2008-02-17 19:52:04.000000000 +0100
+++ gcc-4.3.6.nn2/gcc/doc/c-tree.texi	2020-05-16 02:46:26.563025552 +0200
@@ -2325,13 +2325,13 @@
 not matter.  The type of the operands and that of the result are
 always of @code{BOOLEAN_TYPE} or @code{INTEGER_TYPE}.
 
-@itemx POINTER_PLUS_EXPR
+@item POINTER_PLUS_EXPR
 This node represents pointer arithmetic.  The first operand is always
 a pointer/reference type.  The second operand is always an unsigned
 integer type compatible with sizetype.  This is the only binary
 arithmetic operand that can operate on pointer types.
 
-@itemx PLUS_EXPR
+@item PLUS_EXPR
 @itemx MINUS_EXPR
 @itemx MULT_EXPR
 These nodes represent various binary arithmetic operations.
diff -ru gcc-4.3.6/gcc/doc/cppopts.texi gcc-4.3.6.nn2/gcc/doc/cppopts.texi
--- gcc-4.3.6/gcc/doc/cppopts.texi	2007-07-30 20:29:20.000000000 +0200
+++ gcc-4.3.6.nn2/gcc/doc/cppopts.texi	2020-05-16 02:46:26.563025552 +0200
@@ -754,7 +754,7 @@
 Enable special code to work around file systems which only permit very
 short file names, such as MS-DOS@.
 
-@itemx --help
+@item --help
 @itemx --target-help
 @opindex help
 @opindex target-help
diff -ru gcc-4.3.6/gcc/doc/extend.texi gcc-4.3.6.nn2/gcc/doc/extend.texi
--- gcc-4.3.6/gcc/doc/extend.texi	2009-03-17 14:11:58.000000000 +0100
+++ gcc-4.3.6.nn2/gcc/doc/extend.texi	2020-05-16 02:46:26.567025552 +0200
@@ -4231,6 +4231,8 @@
 Otherwise the two shared objects will be unable to use the same
 typeinfo node and exception handling will break.
 
+@end table
+
 @subsection ARM Type Attributes
 
 On those ARM targets that support @code{dllimport} (such as Symbian
@@ -4260,6 +4262,8 @@
 Two attributes are currently defined for i386 configurations:
 @code{ms_struct} and @code{gcc_struct}
 
+@table @code
+
 @item ms_struct
 @itemx gcc_struct
 @cindex @code{ms_struct}
diff -ru gcc-4.3.6/gcc/doc/gcc.texi gcc-4.3.6.nn2/gcc/doc/gcc.texi
--- gcc-4.3.6/gcc/doc/gcc.texi	2008-04-01 20:49:36.000000000 +0200
+++ gcc-4.3.6.nn2/gcc/doc/gcc.texi	2020-05-16 03:29:18.783089058 +0200
@@ -86,9 +86,9 @@
 @item GNU Press
 @tab Website: www.gnupress.org
 @item a division of the
-@tab General: @tex press@@gnu.org @end tex
+@tab General: @email{press@@gnu.org}
 @item Free Software Foundation
-@tab Orders:  @tex sales@@gnu.org @end tex
+@tab Orders:  @email{sales@@gnu.org}
 @item 51 Franklin Street, Fifth Floor
 @tab Tel 617-542-5942
 @item Boston, MA 02110-1301 USA
diff -ru gcc-4.3.6/gcc/doc/invoke.texi gcc-4.3.6.nn2/gcc/doc/invoke.texi
--- gcc-4.3.6/gcc/doc/invoke.texi	2009-01-27 19:45:49.000000000 +0100
+++ gcc-4.3.6.nn2/gcc/doc/invoke.texi	2020-05-16 02:46:26.571025552 +0200
@@ -958,7 +958,7 @@
 generic, or subprogram renaming declaration).  Such files are also
 called @dfn{specs}.
 
-@itemx @var{file}.adb
+@item @var{file}.adb
 Ada source code file containing a library unit body (a subprogram or
 package body).  Such files are also called @dfn{bodies}.
 
@@ -8571,7 +8571,7 @@
 @samp{cortex-a8}, @samp{cortex-r4}, @samp{cortex-m3},
 @samp{xscale}, @samp{iwmmxt}, @samp{ep9312}.
 
-@itemx -mtune=@var{name}
+@item -mtune=@var{name}
 @opindex mtune
 This option is very similar to the @option{-mcpu=} option, except that
 instead of specifying the actual target processor type, and hence
diff -ru gcc-4.3.6/gcc/toplev.c gcc-4.3.6.nn2/gcc/toplev.c
--- gcc-4.3.6/gcc/toplev.c	2009-04-29 08:24:21.000000000 +0200
+++ gcc-4.3.6.nn2/gcc/toplev.c	2020-05-16 02:08:25.530969235 +0200
@@ -536,7 +536,7 @@
    for floor_log2 and exact_log2; see toplev.h.  That construct, however,
    conflicts with the ISO C++ One Definition Rule.   */
 
-#if GCC_VERSION < 3004 || !defined (__cplusplus)
+#if GCC_VERSION < 3004
 
 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
    If X is 0, return -1.  */
@@ -588,7 +588,7 @@
 #endif
 }
 
-#endif /*  GCC_VERSION < 3004 || !defined (__cplusplus)  */
+#endif /*  GCC_VERSION < 3004 */
 
 /* Handler for fatal signals, such as SIGSEGV.  These are transformed
    into ICE messages, which is much more user friendly.  In case the
diff -ru gcc-4.3.6/gcc/toplev.h gcc-4.3.6.nn2/gcc/toplev.h
--- gcc-4.3.6/gcc/toplev.h	2007-09-23 21:18:27.000000000 +0200
+++ gcc-4.3.6.nn2/gcc/toplev.h	2020-05-16 02:47:16.675026789 +0200
@@ -154,14 +154,17 @@
 /* Return true iff flags are set as if -ffast-math.  */
 extern bool fast_math_flags_set_p	(void);
 
+#if GCC_VERSION < 3004
+
 /* Return log2, or -1 if not exact.  */
 extern int exact_log2                  (unsigned HOST_WIDE_INT);
 
 /* Return floor of log2, with -1 for zero.  */
 extern int floor_log2                  (unsigned HOST_WIDE_INT);
 
+#else
 /* Inline versions of the above for speed.  */
-#if GCC_VERSION >= 3004
+
 # if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
 #  define CLZ_HWI __builtin_clzl
 #  define CTZ_HWI __builtin_ctzl
@@ -173,13 +176,13 @@
 #  define CTZ_HWI __builtin_ctz
 # endif
 
-extern inline int
+static inline int
 floor_log2 (unsigned HOST_WIDE_INT x)
 {
   return x ? HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x) : -1;
 }
 
-extern inline int
+static inline int
 exact_log2 (unsigned HOST_WIDE_INT x)
 {
   return x == (x & -x) && x ? (int) CTZ_HWI (x) : -1;

--45Z9DzgjV8m4Oswq
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="sum2.diff"

diff -ru gcc-4.3.6/gcc/Makefile.in gcc-4.3.6.nn2/gcc/Makefile.in
--- gcc-4.3.6/gcc/Makefile.in	2010-05-14 14:51:31.000000000 +0200
+++ gcc-4.3.6.nn2/gcc/Makefile.in	2020-05-16 02:46:26.399025548 +0200
@@ -3300,6 +3300,7 @@
   -DTOOL_INCLUDE_DIR=\"$(gcc_tooldir)/include\" \
   -DPREFIX=\"$(prefix)/\" \
   -DSTANDARD_EXEC_PREFIX=\"$(libdir)/gcc/\" \
+  -DTARGET_MACHINE=\"x86_64-linux-gnu\" \
   @TARGET_SYSTEM_ROOT_DEFINE@
 
 cppdefault.o: cppdefault.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
diff -ru gcc-4.3.6/gcc/config/i386/linux64.h gcc-4.3.6.nn2/gcc/config/i386/linux64.h
--- gcc-4.3.6/gcc/config/i386/linux64.h	2007-08-02 12:49:31.000000000 +0200
+++ gcc-4.3.6.nn2/gcc/config/i386/linux64.h	2020-05-16 04:20:46.139165283 +0200
@@ -81,7 +81,7 @@
    %{mpc32:crtprec32.o%s} \
    %{mpc64:crtprec64.o%s} \
    %{mpc80:crtprec80.o%s} \
-   %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s"
+   %{shared|pie:crtendS.o%s;:crtend.o%s} /usr/lib/x86_64-linux-gnu/crtn.o%s"
 
 #if TARGET_64BIT_DEFAULT
 #define MULTILIB_DEFAULTS { "m64" }
diff -ru gcc-4.3.6/gcc/config/linux.h gcc-4.3.6.nn2/gcc/config/linux.h
--- gcc-4.3.6/gcc/config/linux.h	2007-08-02 12:49:31.000000000 +0200
+++ gcc-4.3.6.nn2/gcc/config/linux.h	2020-05-16 04:20:46.231165285 +0200
@@ -40,12 +40,12 @@
 #undef	STARTFILE_SPEC
 #if defined HAVE_LD_PIE
 #define STARTFILE_SPEC \
-  "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
+  "%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:/usr/lib/x86_64-linux-gnu/crt1.o%s}} \
+   /usr/lib/x86_64-linux-gnu/crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
 #else
 #define STARTFILE_SPEC \
-  "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \
-   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
+  "%{!shared: %{pg|p|profile:gcrt1.o%s;:/usr/lib/x86_64-linux-gnu/crt1.o%s}} \
+   /usr/lib/x86_64-linux-gnu/crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}"
 #endif
 
 /* Provide a ENDFILE_SPEC appropriate for GNU/Linux.  Here we tack on
diff -ru gcc-4.3.6/gcc/cppdefault.c gcc-4.3.6.nn2/gcc/cppdefault.c
--- gcc-4.3.6/gcc/cppdefault.c	2007-07-26 10:37:01.000000000 +0200
+++ gcc-4.3.6.nn2/gcc/cppdefault.c	2020-05-16 02:46:26.559025552 +0200
@@ -29,6 +29,14 @@
 #define STANDARD_INCLUDE_DIR "/usr/include"
 #endif
 
+#ifndef MULTIARCH_STANDARD_INCLUDE_DIR
+#define MULTIARCH_STANDARD_INCLUDE_DIR STANDARD_INCLUDE_DIR "/" TARGET_MACHINE
+#endif
+
+#ifndef MULTIARCH_LOCAL_INCLUDE_DIR
+#define MULTIARCH_LOCAL_INCLUDE_DIR LOCAL_INCLUDE_DIR "/" TARGET_MACHINE
+#endif
+
 #ifndef STANDARD_INCLUDE_COMPONENT
 #define STANDARD_INCLUDE_COMPONENT 0
 #endif
@@ -62,6 +70,10 @@
     /* /usr/local/include comes before the fixincluded header files.  */
     { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
 #endif
+#ifdef MULTIARCH_LOCAL_INCLUDE_DIR
+    /* /usr/local/include/$target_alias comes before the fixincluded header files.  */
+    { MULTIARCH_LOCAL_INCLUDE_DIR, 0, 0, 1, 1 },
+#endif
 #ifdef PREFIX_INCLUDE_DIR
     { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0 },
 #endif
@@ -93,6 +105,9 @@
     /* Some systems have an extra dir of include files.  */
     { SYSTEM_INCLUDE_DIR, 0, 0, 0, 1, 0 },
 #endif
+#ifdef MULTIARCH_STANDARD_INCLUDE_DIR
+    { MULTIARCH_STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0, 1 },
+#endif
 #ifdef STANDARD_INCLUDE_DIR
     /* /usr/include comes dead last.  */
     { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0, 1, 0 },

--45Z9DzgjV8m4Oswq
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Gpc mailing list
[email protected]
https://www.g-n-u.de/mailman/listinfo/gpc

--45Z9DzgjV8m4Oswq--