hc
2023-11-20 2e7bd41e4e8ab3d1efdabd9e263a2f7fe79bff8c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From c810a0aca3f1148d2072d44b91b8cc9caeb4cf19 Mon Sep 17 00:00:00 2001
From: James Knight <james.knight@rockwellcollins.com>
Date: Wed, 16 Nov 2016 15:54:46 -0500
Subject: [PATCH] configure.ac: correct stack protector check
 
If a used toolchain accepts the `-fstack-protector` option but does not
provide a stack smashing protector implementation (ex. libssp), linking
will fail:
 
 .libs/rpmio.o: In function `Fdescr':
 rpmio.c:(.text+0x672): undefined reference to `__stack_chk_fail_local'
 .libs/rpmio.o: In function `Fdopen':
 rpmio.c:(.text+0xce9): undefined reference to `__stack_chk_fail_local'
 .libs/rpmio.o: In function `ufdCopy':
 rpmio.c:(.text+0x10f7): undefined reference to `__stack_chk_fail_local'
 ...
 
This is a result of testing for `-fstack-protector` support using a main
that GCC does not inject guards. GCC's manual notes that stack protector
code is only added when "[functions] that call alloca, and functions
with buffers larger than 8 bytes" [1]. This commit adjusts the stack
protector check to allocate memory on the stack (via `alloca`).
 
[1]: https://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Optimize-Options.html
 
Signed-off-by: James Knight <james.knight@rockwellcollins.com>
[Upstream commit: https://github.com/rpm-software-management/rpm/commit/c810a0aca3f1148d2072d44b91b8cc9caeb4cf19]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
 
diff --git a/configure.ac b/configure.ac
index a9730d3bc..b4b3fe8fb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,7 +43,7 @@ if test "$GCC" = yes; then
     echo
     for flag in $cflags_to_try; do
         CFLAGS="$CFLAGS $flag -Werror"
-        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[return 0;]])],[
+        AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[alloca(100);]])],[
                 echo "   $flag"
                 RPMCFLAGS="$RPMCFLAGS $flag"
         ],[])