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