Hello,

I'm proposing the attached patch to silence GCC errors related
to unbound stack usage in selected elfutils tests.

Martin

From 7a1c7716819786f935077872d2080a81a9ecbf7e Mon Sep 17 00:00:00 2001
From: Martin Cermak <[email protected]>
Date: Wed, 25 Nov 2026 15:11:28 +0100
Subject: [PATCH] tests: Avoid "unbounded stack usage" in selected tests
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This update avoids gcc-16.2.1 complaints like the following:

eu_search_cfi.c:150:3: error: ISO C90 forbids variable length
array ‘threads’ [-Werror=vla]
  150 |   pthread_t threads[num_threads];
      |   ^~~~~~~~~
eu_search_cfi.c:117:5: error: stack usage might be unbounded
[-Werror=stack-usage=]
  117 | int main (int argc, char *argv[])
      |     ^~~~
cc1: all warnings being treated as errors

More detailed diagnostics generated with gcc -Wvla.

Signed-off-by: Martin Cermak <[email protected]>
---
 tests/eu_search_cfi.c    |  9 +++++----
 tests/eu_search_die.c    | 11 ++++++-----
 tests/eu_search_lines.c  | 11 ++++++-----
 tests/eu_search_macros.c |  9 +++++----
 4 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/tests/eu_search_cfi.c b/tests/eu_search_cfi.c
index 4a46ab1c..b5a6c05e 100644
--- a/tests/eu_search_cfi.c
+++ b/tests/eu_search_cfi.c
@@ -33,6 +33,8 @@
 #include "system.h"
 #include <pthread.h>
 
+#define NUM_THREADS 4
+
 static void handle_section (char *name, const unsigned char e_ident[],
 			   Elf_Scn *scn, const bool is_eh);
 static void *thread_work (void *arg);
@@ -146,8 +148,7 @@ int main (int argc, char *argv[])
 
   size_t strndx = ehdr.e_shstrndx;
 
-  int num_threads = 4;
-  pthread_t threads[num_threads];
+  pthread_t threads[NUM_THREADS];
   ThreadData thread_data;
 
   Elf_Scn *scn = NULL;
@@ -173,7 +174,7 @@ int main (int argc, char *argv[])
 	      thread_data.scn = scn;
 	      thread_data.is_eh = is_eh;
 
-	      for (int i = 0; i < num_threads; i++)
+	      for (int i = 0; i < NUM_THREADS; i++)
 		if (pthread_create (&threads[i], NULL, thread_work,
 				    &thread_data) != 0)
 		  {
@@ -187,7 +188,7 @@ int main (int argc, char *argv[])
 		    return 1;
 		  }
 
-	      for (int i = 0; i < num_threads; i++)
+	      for (int i = 0; i < NUM_THREADS; i++)
 		if (pthread_join (threads[i], NULL) != 0)
 		  perror ("pthread_join");
 	    }
diff --git a/tests/eu_search_die.c b/tests/eu_search_die.c
index a4510d3b..8fd2defd 100644
--- a/tests/eu_search_die.c
+++ b/tests/eu_search_die.c
@@ -31,6 +31,8 @@
 #include <unistd.h>
 #include <pthread.h>
 
+#define NUM_THREADS 4
+
 static int check_die (Dwarf_Die *die, Dwarf *dbg);
 static int check_dbg (Dwarf *dbg);
 
@@ -187,11 +189,10 @@ int main (int argc, char *argv[])
 
   printf ("checking %s\n", name);
 
-  int num_threads = 4;
-  pthread_t threads[num_threads];
-  int thread_results[num_threads];
+  pthread_t threads[NUM_THREADS];
+  int thread_results[NUM_THREADS];
 
-  for (int i = 0; i < num_threads; i++)
+  for (int i = 0; i < NUM_THREADS; i++)
     {
       if (pthread_create (&threads[i], NULL, thread_work,
 			  &thread_results[i]) != 0)
@@ -207,7 +208,7 @@ int main (int argc, char *argv[])
     }
 
   int res = 0;
-  for (int i = 0; i < num_threads; i++)
+  for (int i = 0; i < NUM_THREADS; i++)
     {
       if (pthread_join (threads[i], NULL) != 0)
 	{
diff --git a/tests/eu_search_lines.c b/tests/eu_search_lines.c
index d5a7de6d..433c5659 100644
--- a/tests/eu_search_lines.c
+++ b/tests/eu_search_lines.c
@@ -26,6 +26,8 @@
 #include <stdlib.h>
 #include <pthread.h>
 
+#define NUM_THREADS 4
+
 static Dwarf *dbg;
 
 static void *thread_work (void *arg)
@@ -171,11 +173,10 @@ int main (int argc, char *argv[])
 
   printf ("checking %s\n", name);
 
-  int num_threads = 4;
-  pthread_t threads[num_threads];
-  int thread_results[num_threads];
+  pthread_t threads[NUM_THREADS];
+  int thread_results[NUM_THREADS];
 
-  for (int i = 0; i < num_threads; ++i)
+  for (int i = 0; i < NUM_THREADS; ++i)
     {
       if (pthread_create (&threads[i], NULL, thread_work,
 			  &thread_results[i]) != 0)
@@ -192,7 +193,7 @@ int main (int argc, char *argv[])
     }
 
   int res = 0;
-  for (int i = 0; i < num_threads; ++i)
+  for (int i = 0; i < NUM_THREADS; ++i)
     {
       if (pthread_join (threads[i], NULL) != 0)
 	{
diff --git a/tests/eu_search_macros.c b/tests/eu_search_macros.c
index 0f70eef2..f5cb2a0a 100644
--- a/tests/eu_search_macros.c
+++ b/tests/eu_search_macros.c
@@ -31,6 +31,8 @@
 #include <unistd.h>
 #include <error.h>
 
+#define NUM_THREADS 4
+
 static void *thread_work (void * arg);
 static int mac (Dwarf_Macro *macro, void *arg);
 static int include (Dwarf_Off macoff, ptrdiff_t token);
@@ -142,10 +144,9 @@ int main (int argc, char *argv[])
   dbg = dwarf_begin (fd, DWARF_C_READ);
   cuoff = strtol (argv[2], NULL, 0);
 
-  int num_threads = 4;
-  pthread_t threads[num_threads];
+  pthread_t threads[NUM_THREADS];
 
-  for (int i = 0; i < num_threads; i++)
+  for (int i = 0; i < NUM_THREADS; i++)
     {
       if (pthread_create (&threads[i], NULL, thread_work, NULL) != 0)
 	{
@@ -160,7 +161,7 @@ int main (int argc, char *argv[])
 	}
     }
 
-  for (int i = 0; i < num_threads; i++)
+  for (int i = 0; i < NUM_THREADS; i++)
     {
       if (pthread_join (threads[i], NULL) != 0)
 	{
-- 
2.56.1

Reply via email to