no-alloca.h: Support poisoning alloca
Commit Message
2017-06-19 Florian Weimer <fweimer@redhat.com>
Support blocking VLAs and alloca at compile time.
* Makeconfig (CFLAGS-no-alloca): Define.
* include/no-alloca.h: New file.
@@ -508,6 +508,9 @@ endif # +link
# tell gcc to define IS_IN_build.
CFLAGS-printers-tests := -O0 -ggdb3 -DIS_IN_build
+# CFLAGS setting to block VLAs and alloca for select source files.
+CFLAGS-no-alloca = -Werror=vla -include $(..)include/no-alloca.h
+
ifeq (yes,$(build-shared))
# These indicate whether to link using the built ld.so or the installed one.
installed-rtld-LDFLAGS = -Wl,-dynamic-linker=$(rtlddir)/$(rtld-installed-name)
new file mode 100644
@@ -0,0 +1,25 @@
+/* Prevent the use of alloca.
+ Copyright (C) 2017 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#pragma GCC poison alloca
+#pragma GCC poison __alloca
+#pragma GCC poison __builtin_alloca
+#pragma GCC poison __builtin_alloca_with_align
+#pragma GCC poison extend_alloca
+
+#define __GLIBC_NO_ALLOCA 1
@@ -62,7 +62,7 @@ extern __typeof (strcasecmp_l) __strcasecmp_l;
extern __typeof (strncasecmp_l) __strncasecmp_l;
/* Alternative version which doesn't pollute glibc's namespace. */
-#if IS_IN (libc)
+#if IS_IN (libc) && !defined (__GLIBC_NO_ALLOCA)
# undef strndupa
# define strndupa(s, n) \
(__extension__ \
@@ -459,7 +459,7 @@ extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
/* Free a block allocated by `malloc', `realloc' or `calloc'. */
extern void free (void *__ptr) __THROW;
-#ifdef __USE_MISC
+#if defined (__USE_MISC) && !defined (__GLIBC_NO_ALLOCA)
# include <alloca.h>
#endif /* Use misc. */
@@ -174,7 +174,7 @@ extern char *strndup (const char *__string, size_t __n)
__THROW __attribute_malloc__ __nonnull ((1));
#endif
-#if defined __USE_GNU && defined __GNUC__
+#if defined __USE_GNU && defined __GNUC__ && !defined (__GLIBC_NO_ALLOCA)
/* Duplicate S, returning an identical alloca'd string. */
# define strdupa(s) \
(__extension__ \