libbacktrace patch committed: Always build tests with -g

Message ID CAOyqgcWyXL_5ahyAO8A3J1RfqdgfSb+UVziDoHue2AyUQNQ6gQ@mail.gmail.com
State New
Headers show
Series
  • libbacktrace patch committed: Always build tests with -g
Related show

Commit Message

Ian Lance Taylor Feb. 4, 2020, 2:13 a.m.
This patch ensures that the libbacktrace tests are always built with
-g.  It also builds them with the default warning flags, so I had to
add a few casts to ztest.c to get it pass without warnings.  This
should fix PR 90636.  Bootstrapped and ran libbacktrace tests on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

2020-02-03  Ian Lance Taylor  <iant@golang.org>

* Makefile.am (libbacktrace_TEST_CFLAGS): Define.
(test_elf32_CFLAGS): Use $(libbacktrace_test_CFLAGS).
(test_elf_64_CFLAGS, test_xcoff_32_CFLAGS): Likewise.
(test_xcoff_64_CFLAGS, test_pecoff_CFLAGS): Likewise.
(test_unknown_CFLAGS, unittest_CFLAGS): Likewise.
(unittest_alloc_CFLAGS, allocfail_CFLAGS): Likewise.
(b2test_CFLAGS, b3test_CFLAGS, btest_CFLAGS): Likewise.
(btest_lto_CFLAGS, btest_alloc_CFLAGS, stest_CFLAGS): Likewise.
(stest_alloc_CFLAGS): Likewise.
* Makefile.in: Regenerate.
* ztest.c (error_callback_compress): Mark vdata unused.
(test_large): Add casts to avoid warnings.

Patch

diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index b251b7bc34a..c73f6633a76 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -93,6 +93,9 @@  TESTS =
 # Add test to this variable, if you want it to be build and run.
 BUILDTESTS =
 
+# Flags to use when compiling test programs.
+libbacktrace_TEST_CFLAGS = $(EXTRA_FLAGS) $(WARN_FLAGS) -g
+
 if NATIVE
 check_LTLIBRARIES = libbacktrace_alloc.la
 
@@ -149,41 +152,49 @@  xcoff_%.c: xcoff.c
 	mv $@.tmp $@
 
 test_elf_32_SOURCES = test_format.c testlib.c
+test_elf_32_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 test_elf_32_LDADD = libbacktrace_noformat.la elf_32.lo
 
 BUILDTESTS += test_elf_32
 
 test_elf_64_SOURCES = test_format.c testlib.c
+test_elf_64_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 test_elf_64_LDADD = libbacktrace_noformat.la elf_64.lo
 
 BUILDTESTS += test_elf_64
 
 test_xcoff_32_SOURCES = test_format.c testlib.c
+test_xcoff_32_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 test_xcoff_32_LDADD = libbacktrace_noformat.la xcoff_32.lo
 
 BUILDTESTS += test_xcoff_32
 
 test_xcoff_64_SOURCES = test_format.c testlib.c
+test_xcoff_64_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 test_xcoff_64_LDADD = libbacktrace_noformat.la xcoff_64.lo
 
 BUILDTESTS += test_xcoff_64
 
 test_pecoff_SOURCES = test_format.c testlib.c
+test_pecoff_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 test_pecoff_LDADD = libbacktrace_noformat.la pecoff.lo
 
 BUILDTESTS += test_pecoff
 
 test_unknown_SOURCES = test_format.c testlib.c
+test_unknown_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 test_unknown_LDADD = libbacktrace_noformat.la unknown.lo
 
 BUILDTESTS += test_unknown
 
 unittest_SOURCES = unittest.c testlib.c
+unittest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 unittest_LDADD = libbacktrace.la
 
 BUILDTESTS += unittest
 
 unittest_alloc_SOURCES = $(unittest_SOURCES)
+unittest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 unittest_alloc_LDADD = libbacktrace_alloc.la
 
 BUILDTESTS += unittest_alloc
@@ -200,6 +211,7 @@  libbacktrace_instrumented_alloc_la_DEPENDENCIES = \
 instrumented_alloc.lo: alloc.c
 
 allocfail_SOURCES = allocfail.c testlib.c
+allocfail_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 allocfail_LDADD = libbacktrace_instrumented_alloc.la
 
 check_PROGRAMS += allocfail
@@ -212,7 +224,7 @@  if HAVE_ELF
 if HAVE_OBJCOPY_DEBUGLINK
 
 b2test_SOURCES = $(btest_SOURCES)
-b2test_CFLAGS = $(btest_CFLAGS)
+b2test_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 b2test_LDFLAGS = -Wl,--build-id
 b2test_LDADD = libbacktrace_elf_for_test.la
 
@@ -222,7 +234,7 @@  TESTS += b2test_buildid
 if HAVE_DWZ
 
 b3test_SOURCES = $(btest_SOURCES)
-b3test_CFLAGS = $(btest_CFLAGS)
+b3test_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 b3test_LDFLAGS = -Wl,--build-id
 b3test_LDADD = libbacktrace_elf_for_test.la
 
@@ -235,7 +247,7 @@  endif HAVE_OBJCOPY_DEBUGLINK
 endif HAVE_ELF
 
 btest_SOURCES = btest.c testlib.c
-btest_CFLAGS = $(AM_CFLAGS) -g -O
+btest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O
 btest_LDADD = libbacktrace.la
 
 BUILDTESTS += btest
@@ -243,7 +255,7 @@  BUILDTESTS += btest
 if HAVE_ELF
 
 btest_lto_SOURCES = btest.c testlib.c
-btest_lto_CFLAGS = $(AM_CFLAGS) -g -O -flto
+btest_lto_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O -flto
 btest_lto_LDADD = libbacktrace.la
 
 BUILDTESTS += btest_lto
@@ -251,7 +263,7 @@  BUILDTESTS += btest_lto
 endif HAVE_ELF
 
 btest_alloc_SOURCES = $(btest_SOURCES)
-btest_alloc_CFLAGS = $(btest_CFLAGS)
+btest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 btest_alloc_LDADD = libbacktrace_alloc.la
 
 BUILDTESTS += btest_alloc
@@ -277,11 +289,13 @@  endif HAVE_OBJCOPY_DEBUGLINK
 endif HAVE_DWZ
 
 stest_SOURCES = stest.c
+stest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 stest_LDADD = libbacktrace.la
 
 BUILDTESTS += stest
 
 stest_alloc_SOURCES = $(stest_SOURCES)
+stest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 stest_alloc_LDADD = libbacktrace_alloc.la
 
 BUILDTESTS += stest_alloc
@@ -289,7 +303,7 @@  BUILDTESTS += stest_alloc
 if HAVE_ELF
 
 ztest_SOURCES = ztest.c testlib.c
-ztest_CFLAGS = -DSRCDIR=\"$(srcdir)\"
+ztest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -DSRCDIR=\"$(srcdir)\"
 ztest_LDADD = libbacktrace.la
 ztest_alloc_LDADD = libbacktrace_alloc.la
 
@@ -310,11 +324,13 @@  BUILDTESTS += ztest_alloc
 endif HAVE_ELF
 
 edtest_SOURCES = edtest.c edtest2_build.c testlib.c
+edtest_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 edtest_LDADD = libbacktrace.la
 
 BUILDTESTS += edtest
 
 edtest_alloc_SOURCES = $(edtest_SOURCES)
+edtest_alloc_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 edtest_alloc_LDADD = libbacktrace_alloc.la
 
 BUILDTESTS += edtest_alloc
@@ -330,7 +346,7 @@  if HAVE_PTHREAD
 BUILDTESTS += ttest
 
 ttest_SOURCES = ttest.c testlib.c
-ttest_CFLAGS = $(AM_CFLAGS) -pthread
+ttest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -pthread
 ttest_LDADD = libbacktrace.la
 
 BUILDTESTS += ttest_alloc
@@ -360,12 +376,12 @@  endif HAVE_OBJCOPY_DEBUGLINK
 if HAVE_COMPRESSED_DEBUG
 
 ctestg_SOURCES = btest.c testlib.c
-ctestg_CFLAGS = $(AM_CFLAGS) -g
+ctestg_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 ctestg_LDFLAGS = -Wl,--compress-debug-sections=zlib-gnu
 ctestg_LDADD = libbacktrace.la
 
 ctesta_SOURCES = btest.c testlib.c
-ctesta_CFLAGS = $(AM_CFLAGS) -g
+ctesta_CFLAGS = $(libbacktrace_TEST_CFLAGS)
 ctesta_LDFLAGS = -Wl,--compress-debug-sections=zlib-gabi
 ctesta_LDADD = libbacktrace.la
 
@@ -388,7 +404,7 @@  endif
 if HAVE_DWARF5
 
 dwarf5_SOURCES = btest.c testlib.c
-dwarf5_CFLAGS = $(AM_CFLAGS) -gdwarf-5
+dwarf5_CFLAGS = $(libbacktrace_TEST_CFLAGS) -gdwarf-5
 dwarf5_LDADD = libbacktrace.la
 
 BUILDTESTS += dwarf5
diff --git a/libbacktrace/ztest.c b/libbacktrace/ztest.c
index de7e7f02845..40f9c389a2a 100644
--- a/libbacktrace/ztest.c
+++ b/libbacktrace/ztest.c
@@ -89,7 +89,8 @@  struct zlib_test
 /* Error callback.  */
 
 static void
-error_callback_compress (void *vdata, const char *msg, int errnum)
+error_callback_compress (void *vdata ATTRIBUTE_UNUSED, const char *msg,
+			 int errnum)
 {
   fprintf (stderr, "%s", msg);
   if (errnum > 0)
@@ -360,7 +361,7 @@  test_large (struct backtrace_state *state)
       fclose (e);
       if (got > 0)
 	{
-	  orig_buf = rbuf;
+	  orig_buf = (unsigned char *) rbuf;
 	  orig_bufsize = got;
 	  break;
 	}
@@ -383,7 +384,7 @@  test_large (struct backtrace_state *state)
     }
 
   compress_sizearg = compressed_bufsize - 12;
-  r = compress (compressed_buf + 12, &compress_sizearg,
+  r = compress ((unsigned char *) compressed_buf + 12, &compress_sizearg,
 		orig_buf, orig_bufsize);
   if (r != Z_OK)
     {
@@ -406,7 +407,8 @@  test_large (struct backtrace_state *state)
     }
   uncompressed_bufsize = orig_bufsize;
 
-  if (!backtrace_uncompress_zdebug (state, compressed_buf, compressed_bufsize,
+  if (!backtrace_uncompress_zdebug (state, (unsigned char *) compressed_buf,
+				    compressed_bufsize,
 				    error_callback_compress, NULL,
 				    &uncompressed_buf, &uncompressed_bufsize))
     {
@@ -443,7 +445,8 @@  test_large (struct backtrace_state *state)
 	  return;
 	}
 
-      if (!backtrace_uncompress_zdebug (state, compressed_buf,
+      if (!backtrace_uncompress_zdebug (state,
+					(unsigned char *) compressed_buf,
 					compressed_bufsize,
 					error_callback_compress, NULL,
 					&uncompressed_buf,
@@ -472,8 +475,9 @@  test_large (struct backtrace_state *state)
 	}
 
       uncompress_sizearg = uncompressed_bufsize;
-      r = uncompress (uncompressed_buf, &uncompress_sizearg,
-		      compressed_buf + 12, compressed_bufsize - 12);
+      r = uncompress ((unsigned char *) uncompressed_buf, &uncompress_sizearg,
+		      (unsigned char *) compressed_buf + 12,
+		      compressed_bufsize - 12);
 
       if (clock_gettime (cid, &ts2) < 0)
 	{