aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Sijmen J. Mulder <ik@sjmulder.nl>2020-06-24 00:47:05 +0200
committerGravatar GitHub <noreply@github.com>2020-06-24 04:17:05 +0530
commit3686ef756a3cde8d58d8c9d8dac48863846ac9dd (patch)
tree1d91ad5548c67b3c0b15843e06bcc8660e2e9400
parent306af787ca465eaf2b075bbc804603706f00b0fa (diff)
downloadnnn-3686ef756a3cde8d58d8c9d8dac48863846ac9dd.tar.gz
Always use builtin alloca() (#666)
Fixes the build on NetBSD 9 on arm64. GCC expands alloca() to __builtin_alloca() but only in nonstandard mode, e.g. when -std=... is not supplied. In standards mode (with -std=...) alloca() is left undefined by GCC. The C library may define it but it also may not, as on NetBSD on arm64: $ uname -srp NetBSD 9.0 aarch64 $ cat alloca.c #include <stdlib.h> int main() { char *p = alloca(10); } $ gcc alloca.c $ gcc -std=c99 alloca.c alloca.c:(.text+0xc): warning: Warning: reference to the libc supplied alloca(3); this most likely will not work. Please use the compiler provided version of alloca(3), by supplying the appropriate compiler flags (e.g. not -std=c89). ld: alloca.c:(.text+0xc): undefined reference to `alloca' The fix is to either not use standards mode (undesirable) or to explicitly use the builtin, which is what this patch does. This is also sufficient for Solarius/Illumos so that check and include are removed.
-rw-r--r--src/nnn.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/nnn.c b/src/nnn.c
index ca9fef6..a8f82ed 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -90,9 +90,6 @@
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
-#ifdef __sun
-#include <alloca.h>
-#endif
#include <string.h>
#include <strings.h>
#include <time.h>
@@ -103,6 +100,15 @@
#include <ftw.h>
#include <wchar.h>
+#if !defined(alloca) && defined(__GNUC__)
+/*
+ * GCC doesn't expand alloca() to __builtin_alloca() in standards mode
+ * (-std=...) and not all standard libraries do or supply it, e.g.
+ * NetBSD/arm64 so explicitly use the builtin.
+ */
+#define alloca(size) __builtin_alloca(size)
+#endif
+
#include "nnn.h"
#include "dbg.h"