about summary refs log tree commit diff
path: root/libio
diff options
context:
space:
mode:
Diffstat (limited to 'libio')
-rw-r--r--libio/Makefile28
-rw-r--r--libio/tst-cleanup-default-static.c1
-rw-r--r--libio/tst-cleanup-default.c1
-rw-r--r--libio/tst-cleanup-nostart-stop-gc-static.c1
-rw-r--r--libio/tst-cleanup-nostart-stop-gc.c1
-rw-r--r--libio/tst-cleanup-start-stop-gc-static.c1
-rw-r--r--libio/tst-cleanup-start-stop-gc.c1
-rw-r--r--libio/tst-cleanup.c34
-rw-r--r--libio/tst-cleanup.exp1
9 files changed, 69 insertions, 0 deletions
diff --git a/libio/Makefile b/libio/Makefile
index 12ce41038f..ed0ce4ee81 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -195,6 +195,26 @@ ifeq (yes,$(build-shared))
 tests-special += $(objpfx)tst-fopenloc-cmp.out $(objpfx)tst-fopenloc-mem.out \
 		 $(objpfx)tst-bz24228-mem.out
 endif
+
+tests += tst-cleanup-default tst-cleanup-default-static
+tests-static += tst-cleanup-default-static
+tests-special += $(objpfx)tst-cleanup-default-cmp.out $(objpfx)tst-cleanup-default-static-cmp.out
+LDFLAGS-tst-cleanup-default = -Wl,--gc-sections
+LDFLAGS-tst-cleanup-default-static = -Wl,--gc-sections
+
+ifeq ($(have-gnu-retain)$(have-z-start-stop-gc),yesyes)
+tests += tst-cleanup-start-stop-gc tst-cleanup-start-stop-gc-static \
+		tst-cleanup-nostart-stop-gc tst-cleanup-nostart-stop-gc-static
+tests-static += tst-cleanup-start-stop-gc-static tst-cleanup-nostart-stop-gc-static
+tests-special += $(objpfx)tst-cleanup-start-stop-gc-cmp.out \
+		$(objpfx)tst-cleanup-start-stop-gc-static-cmp.out \
+		$(objpfx)tst-cleanup-nostart-stop-gc-cmp.out \
+		$(objpfx)tst-cleanup-nostart-stop-gc-static-cmp.out
+LDFLAGS-tst-cleanup-start-stop-gc := -Wl,--gc-sections,-z,start-stop-gc
+LDFLAGS-tst-cleanup-start-stop-gc-static := -Wl,--gc-sections,-z,start-stop-gc
+LDFLAGS-tst-cleanup-nostart-stop-gc := -Wl,--gc-sections,-z,nostart-stop-gc
+LDFLAGS-tst-cleanup-nostart-stop-gc-static := -Wl,--gc-sections,-z,nostart-stop-gc
+endif
 endif
 
 include ../Rules
@@ -224,6 +244,14 @@ $(objpfx)tst_wprintf2.out: $(gen-locales)
 $(objpfx)tst-wfile-sync.out: $(gen-locales)
 endif
 
+define gen-tst-cleanup
+$(objpfx)tst-cleanup-$1-cmp.out: tst-cleanup.exp $(objpfx)tst-cleanup-$1.out
+	cmp $$^ > $$@; $$(evaluate-test)
+endef
+
+$(foreach t,default default-static start-stop-gc start-stop-gc-static nostart-stop-gc nostart-stop-gc-static, \
+  $(eval $(call gen-tst-cleanup,$(t))))
+
 $(objpfx)test-freopen.out: test-freopen.sh $(objpfx)test-freopen
 	$(SHELL) $< $(common-objpfx) '$(test-program-prefix)'	\
 	$(common-objpfx)libio/; \
diff --git a/libio/tst-cleanup-default-static.c b/libio/tst-cleanup-default-static.c
new file mode 100644
index 0000000000..c39956e2a8
--- /dev/null
+++ b/libio/tst-cleanup-default-static.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/libio/tst-cleanup-default.c b/libio/tst-cleanup-default.c
new file mode 100644
index 0000000000..c39956e2a8
--- /dev/null
+++ b/libio/tst-cleanup-default.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/libio/tst-cleanup-nostart-stop-gc-static.c b/libio/tst-cleanup-nostart-stop-gc-static.c
new file mode 100644
index 0000000000..c39956e2a8
--- /dev/null
+++ b/libio/tst-cleanup-nostart-stop-gc-static.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/libio/tst-cleanup-nostart-stop-gc.c b/libio/tst-cleanup-nostart-stop-gc.c
new file mode 100644
index 0000000000..c39956e2a8
--- /dev/null
+++ b/libio/tst-cleanup-nostart-stop-gc.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/libio/tst-cleanup-start-stop-gc-static.c b/libio/tst-cleanup-start-stop-gc-static.c
new file mode 100644
index 0000000000..c39956e2a8
--- /dev/null
+++ b/libio/tst-cleanup-start-stop-gc-static.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/libio/tst-cleanup-start-stop-gc.c b/libio/tst-cleanup-start-stop-gc.c
new file mode 100644
index 0000000000..c39956e2a8
--- /dev/null
+++ b/libio/tst-cleanup-start-stop-gc.c
@@ -0,0 +1 @@
+#include "tst-cleanup.c"
diff --git a/libio/tst-cleanup.c b/libio/tst-cleanup.c
new file mode 100644
index 0000000000..837feac164
--- /dev/null
+++ b/libio/tst-cleanup.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+/* Test that stdout is flushed after atexit callbacks were run, even if the
+ * executable is linked with --gc-sections.  */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+hook (void)
+{
+  puts ("hello");
+}
+
+int
+main (void)
+{
+  atexit (hook);
+}
diff --git a/libio/tst-cleanup.exp b/libio/tst-cleanup.exp
new file mode 100644
index 0000000000..ce01362503
--- /dev/null
+++ b/libio/tst-cleanup.exp
@@ -0,0 +1 @@
+hello