Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Jun 2003 01:48:34 +0200
From:      Dag-Erling Smorgrav <des@ofug.org>
To:        John Polstra <jdp@polstra.com>
Cc:        arch@freebsd.org
Subject:   Re: unbreaking alloca
Message-ID:  <xzpbrx02pbh.fsf@flood.ping.uio.no>
In-Reply-To: <200306142308.h5EN8VEK015107@strings.polstra.com> (John Polstra's message of "Sat, 14 Jun 2003 16:08:31 -0700 (PDT)")
References:  <xzp1xxw65o7.fsf@flood.ping.uio.no> <200306142308.h5EN8VEK015107@strings.polstra.com>

next in thread | previous in thread | raw e-mail | index | archive | help
--=-=-=

John Polstra <jdp@polstra.com> writes:
> I tried your patch, but it broke world in ranlib:

I got that too, you need to wrap the #define in #ifndef alloca /
#endif.  See the attached updated patch.

DES
-- 
Dag-Erling Smorgrav - des@ofug.org


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment; filename=alloca.diff

Index: sys/sys/cdefs.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/cdefs.h,v
retrieving revision 1.70
diff -u -r1.70 cdefs.h
--- sys/sys/cdefs.h	14 Jun 2003 06:01:35 -0000	1.70
+++ sys/sys/cdefs.h	14 Jun 2003 15:04:29 -0000
@@ -142,11 +142,6 @@
 #define	__section(x)	__attribute__((__section__(x)))
 #endif
 #endif
-#ifdef __GNUC__
-#define	alloca(sz)	__builtin_alloca(sz)
-#else
-#error FreeBSD alloca support needed for this compiler
-#endif
 
 /* XXX: should use `#if __STDC_VERSION__ < 199901'. */
 #if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3)
Index: include/stdlib.h
===================================================================
RCS file: /home/ncvs/src/include/stdlib.h,v
retrieving revision 1.48
diff -u -r1.48 stdlib.h
--- include/stdlib.h	12 Mar 2003 20:29:58 -0000	1.48
+++ include/stdlib.h	14 Jun 2003 23:47:55 -0000
@@ -222,7 +222,23 @@
 extern void (*_malloc_message)(const char *, const char *, const char *,
 	    const char *);
 
-void	*alloca(size_t);		/* built-in for gcc */
+#ifndef alloca
+/*
+ * The alloca() function can't be implemented in C, and on some
+ * platforms it can't be implemented at all as a callable function.
+ * The GNU C compiler provides a built-in alloca() which we can use;
+ * in all other cases, provide a prototype, mainly to pacify various
+ * incarnations of lint.  On platforms where alloca() is not in libc,
+ * programs which use it will fail to link when compiled with non-GNU
+ * compilers.
+ */
+#ifdef __GNUC__
+#define alloca(sz)	__builtin_alloca(sz)
+#else
+void	*alloca(size_t);
+#endif
+#endif
+
 __uint32_t
 	 arc4random(void);
 void	 arc4random_addrandom(unsigned char *dat, int datlen);

--=-=-=--


Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpbrx02pbh.fsf>