|
|
08c3a6 |
commit f8c2f620f1929ad78cb0a247601bec972f140c51
|
|
|
08c3a6 |
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
|
|
08c3a6 |
Date: Wed Jan 12 23:34:23 2022 +0530
|
|
|
08c3a6 |
|
|
|
08c3a6 |
debug: Autogenerate _FORTIFY_SOURCE tests
|
|
|
08c3a6 |
|
|
|
08c3a6 |
Rename debug/tst-chk1.c to debug/tst-fortify.c and add make hackery to
|
|
|
08c3a6 |
autogenerate tests with different macros enabled to build and run the
|
|
|
08c3a6 |
same test with different configurations as well as different
|
|
|
08c3a6 |
fortification levels.
|
|
|
08c3a6 |
|
|
|
08c3a6 |
The change also ends up expanding the -lfs tests to include
|
|
|
08c3a6 |
_FORTIFY_SOURCE=3.
|
|
|
08c3a6 |
|
|
|
08c3a6 |
Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
|
|
|
08c3a6 |
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
|
08c3a6 |
(cherry picked from commit db27f1251b008280a29d540b4f8ab2a38a0d80af)
|
|
|
08c3a6 |
|
|
|
08c3a6 |
diff --git a/Makerules b/Makerules
|
|
|
08c3a6 |
index 596fa68376f45298..7fbe85719aacc230 100644
|
|
|
08c3a6 |
--- a/Makerules
|
|
|
08c3a6 |
+++ b/Makerules
|
|
|
08c3a6 |
@@ -424,6 +424,12 @@ $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
|
|
|
08c3a6 |
endef
|
|
|
08c3a6 |
object-suffixes-left := $(all-object-suffixes)
|
|
|
08c3a6 |
include $(o-iterator)
|
|
|
08c3a6 |
+
|
|
|
08c3a6 |
+define o-iterator-doit
|
|
|
08c3a6 |
+$(objpfx)%$o: $(objpfx)%.cc $(before-compile); $$(compile-command.cc)
|
|
|
08c3a6 |
+endef
|
|
|
08c3a6 |
+object-suffixes-left := $(all-object-suffixes)
|
|
|
08c3a6 |
+include $(o-iterator)
|
|
|
08c3a6 |
endif
|
|
|
08c3a6 |
|
|
|
08c3a6 |
# Generate .dT files as we compile.
|
|
|
08c3a6 |
diff --git a/debug/Makefile b/debug/Makefile
|
|
|
08c3a6 |
index bc37e466eed490fa..acc1b8f6ad029c62 100644
|
|
|
08c3a6 |
--- a/debug/Makefile
|
|
|
08c3a6 |
+++ b/debug/Makefile
|
|
|
08c3a6 |
@@ -1,4 +1,5 @@
|
|
|
08c3a6 |
-# Copyright (C) 1998-2021 Free Software Foundation, Inc.
|
|
|
08c3a6 |
+# Copyright (C) 1998-2022 Free Software Foundation, Inc.
|
|
|
08c3a6 |
+# Copyright The GNU Toolchain Authors.
|
|
|
08c3a6 |
# This file is part of the GNU C Library.
|
|
|
08c3a6 |
|
|
|
08c3a6 |
# The GNU C Library is free software; you can redistribute it and/or
|
|
|
08c3a6 |
@@ -110,32 +111,60 @@ CFLAGS-tst-longjmp_chk3.c += -fexceptions -fasynchronous-unwind-tables
|
|
|
08c3a6 |
CPPFLAGS-tst-longjmp_chk3.c += -D_FORTIFY_SOURCE=1
|
|
|
08c3a6 |
CPPFLAGS-tst-realpath-chk.c += -D_FORTIFY_SOURCE=2
|
|
|
08c3a6 |
|
|
|
08c3a6 |
+# _FORTIFY_SOURCE tests.
|
|
|
08c3a6 |
+# Auto-generate tests for _FORTIFY_SOURCE for different levels, compilers and
|
|
|
08c3a6 |
+# preprocessor conditions based on tst-fortify.c.
|
|
|
08c3a6 |
+#
|
|
|
08c3a6 |
+# To add a new test condition, define a cflags-$(cond) make variable to set
|
|
|
08c3a6 |
+# CFLAGS for the file.
|
|
|
08c3a6 |
+
|
|
|
08c3a6 |
+tests-all-chk = tst-fortify
|
|
|
08c3a6 |
+tests-c-chk =
|
|
|
08c3a6 |
+tests-cc-chk =
|
|
|
08c3a6 |
+
|
|
|
08c3a6 |
+CFLAGS-tst-fortify.c += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
+
|
|
|
08c3a6 |
+# No additional flags for the default tests.
|
|
|
08c3a6 |
+define cflags-default
|
|
|
08c3a6 |
+endef
|
|
|
08c3a6 |
+
|
|
|
08c3a6 |
+define cflags-lfs
|
|
|
08c3a6 |
+CFLAGS-tst-fortify-$(1)-lfs-$(2).$(1) += -D_FILE_OFFSET_BITS=64
|
|
|
08c3a6 |
+endef
|
|
|
08c3a6 |
+
|
|
|
08c3a6 |
# We know these tests have problems with format strings, this is what
|
|
|
08c3a6 |
# we are testing. Disable that warning. They are also testing
|
|
|
08c3a6 |
# deprecated functions (notably gets) so disable that warning as well.
|
|
|
08c3a6 |
# And they also generate warnings from warning attributes, which
|
|
|
08c3a6 |
# cannot be disabled via pragmas, so require -Wno-error to be used.
|
|
|
08c3a6 |
-CFLAGS-tst-chk1.c += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-chk2.c += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-chk3.c += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-chk4.cc += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-chk5.cc += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-chk6.cc += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-chk7.c += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-chk8.cc += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-lfschk1.c += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-lfschk2.c += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-lfschk3.c += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-lfschk4.cc += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-lfschk5.cc += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-CFLAGS-tst-lfschk6.cc += -Wno-format -Wno-deprecated-declarations -Wno-error
|
|
|
08c3a6 |
-LDLIBS-tst-chk4 = -lstdc++
|
|
|
08c3a6 |
-LDLIBS-tst-chk5 = -lstdc++
|
|
|
08c3a6 |
-LDLIBS-tst-chk6 = -lstdc++
|
|
|
08c3a6 |
-LDLIBS-tst-chk8 = -lstdc++
|
|
|
08c3a6 |
-LDLIBS-tst-lfschk4 = -lstdc++
|
|
|
08c3a6 |
-LDLIBS-tst-lfschk5 = -lstdc++
|
|
|
08c3a6 |
-LDLIBS-tst-lfschk6 = -lstdc++
|
|
|
08c3a6 |
+define gen-chk-test
|
|
|
08c3a6 |
+tests-$(1)-chk += tst-fortify-$(1)-$(2)-$(3)
|
|
|
08c3a6 |
+CFLAGS-tst-fortify-$(1)-$(2)-$(3).$(1) += -D_FORTIFY_SOURCE=$(3) -Wno-format \
|
|
|
08c3a6 |
+ -Wno-deprecated-declarations \
|
|
|
08c3a6 |
+ -Wno-error
|
|
|
08c3a6 |
+$(eval $(call cflags-$(2),$(1),$(3)))
|
|
|
08c3a6 |
+$(objpfx)tst-fortify-$(1)-$(2)-$(3).$(1): tst-fortify.c Makefile
|
|
|
08c3a6 |
+ ( echo "/* Autogenerated from Makefile. */"; \
|
|
|
08c3a6 |
+ echo ""; \
|
|
|
08c3a6 |
+ echo "#include \"tst-fortify.c\"" ) > $$@.tmp
|
|
|
08c3a6 |
+ mv $$@.tmp $$@
|
|
|
08c3a6 |
+endef
|
|
|
08c3a6 |
+
|
|
|
08c3a6 |
+chk-extensions = c cc
|
|
|
08c3a6 |
+chk-types = default lfs
|
|
|
08c3a6 |
+chk-levels = 1 2 3
|
|
|
08c3a6 |
+
|
|
|
08c3a6 |
+$(foreach e,$(chk-extensions), \
|
|
|
08c3a6 |
+ $(foreach t,$(chk-types), \
|
|
|
08c3a6 |
+ $(foreach l,$(chk-levels), \
|
|
|
08c3a6 |
+ $(eval $(call gen-chk-test,$(e),$(t),$(l))))))
|
|
|
08c3a6 |
+
|
|
|
08c3a6 |
+tests-all-chk += $(tests-c-chk) $(tests-cc-chk)
|
|
|
08c3a6 |
+
|
|
|
08c3a6 |
+define link-cc
|
|
|
08c3a6 |
+LDLIBS-$(1) = -lstdc++
|
|
|
08c3a6 |
+endef
|
|
|
08c3a6 |
+$(foreach t,$(tests-cc-chk), $(eval $(call link-cc,$(t))))
|
|
|
08c3a6 |
|
|
|
08c3a6 |
# backtrace_symbols only works if we link with -rdynamic. backtrace
|
|
|
08c3a6 |
# requires unwind tables on most architectures.
|
|
|
08c3a6 |
@@ -152,19 +181,25 @@ LDFLAGS-tst-backtrace6 = -rdynamic
|
|
|
08c3a6 |
|
|
|
08c3a6 |
CFLAGS-tst-ssp-1.c += -fstack-protector-all
|
|
|
08c3a6 |
|
|
|
08c3a6 |
-tests = backtrace-tst tst-longjmp_chk tst-chk1 tst-chk2 tst-chk3 \
|
|
|
08c3a6 |
- tst-lfschk1 tst-lfschk2 tst-lfschk3 test-strcpy_chk test-stpcpy_chk \
|
|
|
08c3a6 |
- tst-chk4 tst-chk5 tst-chk6 tst-chk7 tst-chk8 tst-lfschk4 tst-lfschk5 \
|
|
|
08c3a6 |
- tst-lfschk6 tst-longjmp_chk2 tst-backtrace2 tst-backtrace3 \
|
|
|
08c3a6 |
- tst-backtrace4 tst-backtrace5 tst-backtrace6 tst-realpath-chk
|
|
|
08c3a6 |
+tests = backtrace-tst \
|
|
|
08c3a6 |
+ tst-longjmp_chk \
|
|
|
08c3a6 |
+ test-strcpy_chk \
|
|
|
08c3a6 |
+ test-stpcpy_chk \
|
|
|
08c3a6 |
+ tst-longjmp_chk2 \
|
|
|
08c3a6 |
+ tst-backtrace2 \
|
|
|
08c3a6 |
+ tst-backtrace3 \
|
|
|
08c3a6 |
+ tst-backtrace4 \
|
|
|
08c3a6 |
+ tst-backtrace5 \
|
|
|
08c3a6 |
+ tst-backtrace6 \
|
|
|
08c3a6 |
+ tst-realpath-chk \
|
|
|
08c3a6 |
+ $(tests-all-chk)
|
|
|
08c3a6 |
|
|
|
08c3a6 |
ifeq ($(have-ssp),yes)
|
|
|
08c3a6 |
tests += tst-ssp-1
|
|
|
08c3a6 |
endif
|
|
|
08c3a6 |
|
|
|
08c3a6 |
ifeq (,$(CXX))
|
|
|
08c3a6 |
-tests-unsupported = tst-chk4 tst-chk5 tst-chk6 tst-chk8 \
|
|
|
08c3a6 |
- tst-lfschk4 tst-lfschk5 tst-lfschk6
|
|
|
08c3a6 |
+tests-unsupported = $(tests-cc-chk)
|
|
|
08c3a6 |
endif
|
|
|
08c3a6 |
|
|
|
08c3a6 |
extra-libs = libSegFault libpcprofile
|
|
|
08c3a6 |
@@ -191,20 +226,10 @@ ifeq ($(run-built-tests),yes)
|
|
|
08c3a6 |
LOCALES := de_DE.UTF-8
|
|
|
08c3a6 |
include ../gen-locales.mk
|
|
|
08c3a6 |
|
|
|
08c3a6 |
-$(objpfx)tst-chk1.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-chk2.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-chk3.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-chk4.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-chk5.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-chk6.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-chk7.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-chk8.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-lfschk1.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-lfschk2.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-lfschk3.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-lfschk4.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-lfschk5.out: $(gen-locales)
|
|
|
08c3a6 |
-$(objpfx)tst-lfschk6.out: $(gen-locales)
|
|
|
08c3a6 |
+define chk-gen-locales
|
|
|
08c3a6 |
+$(objpfx)$(1).out: $(gen-locales)
|
|
|
08c3a6 |
+endef
|
|
|
08c3a6 |
+$(foreach t, $(tests-all-chk), $(eval $(call chk-gen-locales,$(t))))
|
|
|
08c3a6 |
endif
|
|
|
08c3a6 |
|
|
|
08c3a6 |
sLIBdir := $(shell echo $(slibdir) | sed 's,lib\(\|64\)$$,\\\\$$LIB,')
|
|
|
08c3a6 |
diff --git a/debug/tst-chk2.c b/debug/tst-chk2.c
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index be37ce2d22f0760a..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-chk2.c
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FORTIFY_SOURCE 1
|
|
|
08c3a6 |
-#include "tst-chk1.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-chk3.c b/debug/tst-chk3.c
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index 38b8e4fb360ba722..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-chk3.c
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FORTIFY_SOURCE 2
|
|
|
08c3a6 |
-#include "tst-chk1.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-chk4.cc b/debug/tst-chk4.cc
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index c82e6aac86038791..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-chk4.cc
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1 +0,0 @@
|
|
|
08c3a6 |
-#include "tst-chk1.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-chk5.cc b/debug/tst-chk5.cc
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index be37ce2d22f0760a..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-chk5.cc
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FORTIFY_SOURCE 1
|
|
|
08c3a6 |
-#include "tst-chk1.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-chk6.cc b/debug/tst-chk6.cc
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index 38b8e4fb360ba722..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-chk6.cc
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FORTIFY_SOURCE 2
|
|
|
08c3a6 |
-#include "tst-chk1.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-chk7.c b/debug/tst-chk7.c
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index 2a7b32381268135c..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-chk7.c
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FORTIFY_SOURCE 3
|
|
|
08c3a6 |
-#include "tst-chk1.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-chk8.cc b/debug/tst-chk8.cc
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index 2a7b32381268135c..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-chk8.cc
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FORTIFY_SOURCE 3
|
|
|
08c3a6 |
-#include "tst-chk1.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-chk1.c b/debug/tst-fortify.c
|
|
|
08c3a6 |
similarity index 100%
|
|
|
08c3a6 |
rename from debug/tst-chk1.c
|
|
|
08c3a6 |
rename to debug/tst-fortify.c
|
|
|
08c3a6 |
diff --git a/debug/tst-lfschk1.c b/debug/tst-lfschk1.c
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index f3e6d47d5e4484c3..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-lfschk1.c
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FILE_OFFSET_BITS 64
|
|
|
08c3a6 |
-#include "tst-chk1.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-lfschk2.c b/debug/tst-lfschk2.c
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index 95d4db1d32d2eeb3..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-lfschk2.c
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FILE_OFFSET_BITS 64
|
|
|
08c3a6 |
-#include "tst-chk2.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-lfschk3.c b/debug/tst-lfschk3.c
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index 50a1ae1258f1553d..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-lfschk3.c
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FILE_OFFSET_BITS 64
|
|
|
08c3a6 |
-#include "tst-chk3.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-lfschk4.cc b/debug/tst-lfschk4.cc
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index f3e6d47d5e4484c3..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-lfschk4.cc
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FILE_OFFSET_BITS 64
|
|
|
08c3a6 |
-#include "tst-chk1.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-lfschk5.cc b/debug/tst-lfschk5.cc
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index 95d4db1d32d2eeb3..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-lfschk5.cc
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FILE_OFFSET_BITS 64
|
|
|
08c3a6 |
-#include "tst-chk2.c"
|
|
|
08c3a6 |
diff --git a/debug/tst-lfschk6.cc b/debug/tst-lfschk6.cc
|
|
|
08c3a6 |
deleted file mode 100644
|
|
|
08c3a6 |
index 50a1ae1258f1553d..0000000000000000
|
|
|
08c3a6 |
--- a/debug/tst-lfschk6.cc
|
|
|
08c3a6 |
+++ /dev/null
|
|
|
08c3a6 |
@@ -1,2 +0,0 @@
|
|
|
08c3a6 |
-#define _FILE_OFFSET_BITS 64
|
|
|
08c3a6 |
-#include "tst-chk3.c"
|