TscanCode icon indicating copy to clipboard operation
TscanCode copied to clipboard

Failed to compile the code, cause SIGSTKSZ is now a run-time variable since glibc 2.34!

Open laplacedoge opened this issue 2 years ago • 1 comments

For my virtual machine, the clang++ version is "Ubuntu clang version 14.0.0-1ubuntu1", and the g++ version is "gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)".

I tried both of them, but still got failed to compile it, here is the terminal output when using clang++:

clang++ -Ilib -Icommon -Iexternals/tinyxml   -std=c++0x -O2 -include lib/cxx11emu.h -DNDEBUG -Wall -Wno-sign-compare -Wno-unknown-pragmas -Wno-reorder  -c -o cli/tscexecutor.o cli/tscexecutor.cpp
cli/tscexecutor.cpp:322:13: error: variable length array declaration not allowed at file scope
static char mytstack[MYSTACKSIZE]; // alternative stack for signal handler
            ^        ~~~~~~~~~~~
1 error generated.
make: *** [Makefile:284: cli/tscexecutor.o] Error 1

Obviously, the option "-std=c++0x" is already specified in the compile command, but the compiler still said the length of the array "mytstack" is not constant, so I checked the code at cli/tscexecutor.cpp:322:13:

static const size_t MYSTACKSIZE = 16 * 1024 + SIGSTKSZ; // wild guess about a reasonable buffer
static char mytstack[MYSTACKSIZE]; // alternative stack for signal handler
static bool bStackBelowHeap = false; // lame attempt to locate heap vs. stack address space

SIGTKSZ is now not a macro anymore, here is the news.

Maybe it's a better choice to allocate this array dynamically now.

laplacedoge avatar Mar 15 '23 06:03 laplacedoge

i don't know how is the SIGSTKSZ calculated, but i use one random from GitHub search, but, it's look work for me:

diff --git a/trunk/cli/tscexecutor.cpp b/trunk/cli/tscexecutor.cpp
index e384c09..3205cc3 100644
--- a/trunk/cli/tscexecutor.cpp
+++ b/trunk/cli/tscexecutor.cpp
@@ -318,7 +318,8 @@ static void print_stacktrace(FILE* f, bool demangling, int maxdepth)
 #endif
 }
 
-static const size_t MYSTACKSIZE = 16 * 1024 + SIGSTKSZ; // wild guess about a reasonable buffer
+
+static const size_t MYSTACKSIZE = 16 * 1024 + (int)250L; // wild guess about a reasonable buffer
 static char mytstack[MYSTACKSIZE]; // alternative stack for signal handler
 static bool bStackBelowHeap = false; // lame attempt to locate heap vs. stack address space
 
diff --git a/trunk/cli/tscthreadexecutor.cpp b/trunk/cli/tscthreadexecutor.cpp
index 551a88d..5a4e7ca 100644
--- a/trunk/cli/tscthreadexecutor.cpp
+++ b/trunk/cli/tscthreadexecutor.cpp
@@ -1,4 +1,4 @@
-
+#include <cstdint>
 
 #include "tscthreadexecutor.h"
 #include "tscancode.h"

ayoubelmhamdi avatar Mar 09 '24 11:03 ayoubelmhamdi