public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Add tests for Guarded Control Stack
@ 2025-01-23 14:13 Yury Khrustalev
  2025-01-23 14:13 ` [PATCH 1/4] aarch64: " Yury Khrustalev
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Yury Khrustalev @ 2025-01-23 14:13 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella

This patch adds AArch64 specific tests related to Guarded Control Stack [1].

There is no urgency to include this into the 2.41 release of Glibc.

There might be better ways of arranging these tests in terms of using
the test framework of the library. Any feedback is appreciated.

These tests are supposed to be built for AArch64 target and will run on
systems with and without GCS support. In the latter case they would be
reported as UNSUPPORTED.

The tests use "-z gcs=<value>" linker flag that may not be supported by
older binutils. In this case it is expected that the tests will run on
a system that does not support GCS. Linker will show a warning about
unused command line flag.

If tests are intended to be run on a system that supports GCS, then it
is expected that they are built with a toolchain that supports GCS.

When runtime target supports GCS, tests are run with all supported
values of the GCS tunable to check its effects.

Regression tested on aarch64 and no regressions have been found.

OK for trunk?

[1] https://developer.arm.com/documentation/ddi0487/ka/ (chapter D11)

---

Yury Khrustalev (4):
  aarch64: Add tests for Guarded Control Stack
  aarch64: Add GCS tests for transitive dependencies
  aarch64: Add GCS tests for dlopen
  aarch64: Add GCS test with signal handler

 Makeconfig                                    |   2 +-
 sysdeps/unix/sysv/linux/aarch64/Makefile      | 121 ++++++++++++++++++
 .../unix/sysv/linux/aarch64/tst-gcs-abort.sh  |  40 ++++++
 .../linux/aarch64/tst-gcs-disabled-static.c   |   1 +
 .../sysv/linux/aarch64/tst-gcs-disabled.c     |   2 +
 .../linux/aarch64/tst-gcs-dlopen-disabled.c   |   3 +
 .../linux/aarch64/tst-gcs-dlopen-enforced.c   |   3 +
 .../aarch64/tst-gcs-dlopen-optional-off.c     |   3 +
 .../aarch64/tst-gcs-dlopen-optional-on.c      |   3 +
 .../linux/aarch64/tst-gcs-dlopen-override.c   |   3 +
 .../unix/sysv/linux/aarch64/tst-gcs-dlopen.c  |  62 +++++++++
 .../linux/aarch64/tst-gcs-enforced-abort.c    |   2 +
 .../aarch64/tst-gcs-enforced-static-abort.c   |   1 +
 .../linux/aarch64/tst-gcs-enforced-static.c   |   1 +
 .../sysv/linux/aarch64/tst-gcs-enforced.c     |   2 +
 .../unix/sysv/linux/aarch64/tst-gcs-helper.h  |  39 ++++++
 .../unix/sysv/linux/aarch64/tst-gcs-mod1.c    |  27 ++++
 .../unix/sysv/linux/aarch64/tst-gcs-mod2.c    |  25 ++++
 .../unix/sysv/linux/aarch64/tst-gcs-mod3.c    |  25 ++++
 .../sysv/linux/aarch64/tst-gcs-noreturn.c     |  96 ++++++++++++++
 .../sysv/linux/aarch64/tst-gcs-optional-off.c |   2 +
 .../sysv/linux/aarch64/tst-gcs-optional-on.c  |   2 +
 .../aarch64/tst-gcs-optional-static-off.c     |   1 +
 .../aarch64/tst-gcs-optional-static-on.c      |   1 +
 .../linux/aarch64/tst-gcs-override-static.c   |   1 +
 .../sysv/linux/aarch64/tst-gcs-override.c     |   2 +
 .../linux/aarch64/tst-gcs-shared-disabled.c   |   2 +
 .../aarch64/tst-gcs-shared-enforced-abort.c   |   2 +
 .../linux/aarch64/tst-gcs-shared-optional.c   |   2 +
 .../linux/aarch64/tst-gcs-shared-override.c   |   2 +
 .../unix/sysv/linux/aarch64/tst-gcs-shared.c  |  41 ++++++
 .../sysv/linux/aarch64/tst-gcs-skeleton.c     |  43 +++++++
 32 files changed, 561 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-disabled.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-enforced.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-optional-off.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-optional-on.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-override.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-helper.h
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod1.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod2.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod3.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-noreturn.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-disabled.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-enforced-abort.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-optional.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-override.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c

-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/4] aarch64: Add tests for Guarded Control Stack
  2025-01-23 14:13 [PATCH 0/4] Add tests for Guarded Control Stack Yury Khrustalev
@ 2025-01-23 14:13 ` Yury Khrustalev
  2025-01-27 20:47   ` Adhemerval Zanella Netto
  2025-01-23 14:13 ` [PATCH 2/4] aarch64: Add GCS tests for transitive dependencies Yury Khrustalev
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Yury Khrustalev @ 2025-01-23 14:13 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella

These tests validate that GCS tunable works as expected depending
on the GCS markings in the test binaries.

Tests validate both static and dynamically linked binaries.

Test will build and run on AArch64 targets only and if GCS is not
enabled on the platform running tests, they will be reported as
UNSUPPORTED.

When linking tests a new linker command line flag -z gcs=<value>
is used. If the toolchain used to build these tests doesn't support
this flag, there will be a warning that is expected and should be
ignored.
---
 sysdeps/unix/sysv/linux/aarch64/Makefile      | 64 +++++++++++++++++++
 .../unix/sysv/linux/aarch64/tst-gcs-abort.sh  | 40 ++++++++++++
 .../linux/aarch64/tst-gcs-disabled-static.c   |  1 +
 .../sysv/linux/aarch64/tst-gcs-disabled.c     |  2 +
 .../linux/aarch64/tst-gcs-enforced-abort.c    |  2 +
 .../aarch64/tst-gcs-enforced-static-abort.c   |  1 +
 .../linux/aarch64/tst-gcs-enforced-static.c   |  1 +
 .../sysv/linux/aarch64/tst-gcs-enforced.c     |  2 +
 .../sysv/linux/aarch64/tst-gcs-optional-off.c |  2 +
 .../sysv/linux/aarch64/tst-gcs-optional-on.c  |  2 +
 .../aarch64/tst-gcs-optional-static-off.c     |  1 +
 .../aarch64/tst-gcs-optional-static-on.c      |  1 +
 .../linux/aarch64/tst-gcs-override-static.c   |  1 +
 .../sysv/linux/aarch64/tst-gcs-override.c     |  2 +
 .../sysv/linux/aarch64/tst-gcs-skeleton.c     | 58 +++++++++++++++++
 15 files changed, 180 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c

diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
index 1fdad67fae..82a992bc14 100644
--- a/sysdeps/unix/sysv/linux/aarch64/Makefile
+++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
@@ -1,8 +1,72 @@
 ifeq ($(subdir),misc)
 sysdep_headers += sys/elf.h
+
+gcs-tests-dynamic = \
+  tst-gcs-disabled \
+  tst-gcs-enforced \
+  tst-gcs-enforced-abort \
+  tst-gcs-optional-off \
+  tst-gcs-optional-on \
+  tst-gcs-override \
+  # gcs-tests-dynamic
+
+gcs-tests-static = \
+  tst-gcs-disabled-static \
+  tst-gcs-enforced-static \
+  tst-gcs-enforced-static-abort \
+  tst-gcs-optional-static-off \
+  tst-gcs-optional-static-on \
+  tst-gcs-override-static \
+  # gcs-tests-static
+
 tests += \
+  $(gcs-tests-dynamic) \
+  $(gcs-tests-static) \
   tst-aarch64-pkey \
   # tests
+
+tests-static += \
+  $(gcs-tests-static) \
+  # tests-static
+
+define run-gcs-abort-test
+  $(test-wrapper-env) $(run-program-env) \
+  $(tst-gcs-$*-abort-ENV) $(host-test-program-cmd)
+endef
+
+$(objpfx)tst-gcs-%-abort.out: $(..)sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh \
+	$(objpfx)tst-gcs-%-abort
+	$(SHELL) $< $(common-objpfx) $(test-name) '$(run-gcs-abort-test)'; \
+	$(evaluate-test)
+
+LDFLAGS-tst-gcs-disabled += -Wl,-z gcs=always
+LDFLAGS-tst-gcs-enforced += -Wl,-z gcs=always
+LDFLAGS-tst-gcs-enforced-abort += -Wl,-z gcs=never
+LDFLAGS-tst-gcs-optional-on += -Wl,-z gcs=always
+LDFLAGS-tst-gcs-optional-off += -Wl,-z gcs=never
+LDFLAGS-tst-gcs-override += -Wl,-z gcs=never
+
+LDFLAGS-tst-gcs-disabled-static += -Wl,-z gcs=always
+LDFLAGS-tst-gcs-enforced-static += -Wl,-z gcs=always
+LDFLAGS-tst-gcs-enforced-static-abort += -Wl,-z gcs=never
+LDFLAGS-tst-gcs-optional-static-on += -Wl,-z gcs=always
+LDFLAGS-tst-gcs-optional-static-off += -Wl,-z gcs=never
+LDFLAGS-tst-gcs-override-static += -Wl,-z gcs=never
+
+tst-gcs-disabled-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
+tst-gcs-enforced-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
+tst-gcs-enforced-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
+tst-gcs-optional-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
+tst-gcs-optional-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
+tst-gcs-override-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
+
+tst-gcs-disabled-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
+tst-gcs-enforced-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
+tst-gcs-enforced-static-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
+tst-gcs-optional-static-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
+tst-gcs-optional-static-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
+tst-gcs-override-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
+
 endif
 
 ifeq ($(subdir),stdlib)
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
new file mode 100644
index 0000000000..5c1889bfcd
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Test wrapper for AArch64 tests for GCS that are expected to abort.
+# Copyright (C) 2001-2025 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/>.
+
+objpfx=$1; shift
+tstname=$1; shift
+tstrun=$1; shift
+
+logfile=$objpfx/$tstname.out
+
+rm -vf $logfile
+touch $logfile
+
+${tstrun} 2>> $logfile >> $logfile; status=$?
+
+if test $status -eq 127 \
+  && grep -q -w "not GCS compatible" "$logfile" ; then
+  exit 0
+elif test $status -eq 77; then
+  exit 77
+else
+  echo "unexpected test output or exit status $status"
+  exit 1
+fi
+
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
new file mode 100644
index 0000000000..c71d68cb86
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
@@ -0,0 +1 @@
+#include "tst-gcs-disabled.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
new file mode 100644
index 0000000000..bd688785bb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
@@ -0,0 +1,2 @@
+#define TEST_GCS_EXPECT_ENABLED 0
+#include "tst-gcs-skeleton.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
new file mode 100644
index 0000000000..608318f26d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
@@ -0,0 +1,2 @@
+#define TEST_GCS_EXPECT_ENABLED 1
+#include "tst-gcs-skeleton.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
new file mode 100644
index 0000000000..c20a999f6b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
@@ -0,0 +1 @@
+#include "tst-gcs-enforced-abort.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
new file mode 100644
index 0000000000..bb39dada55
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
@@ -0,0 +1 @@
+#include "tst-gcs-enforced.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
new file mode 100644
index 0000000000..608318f26d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
@@ -0,0 +1,2 @@
+#define TEST_GCS_EXPECT_ENABLED 1
+#include "tst-gcs-skeleton.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
new file mode 100644
index 0000000000..bd688785bb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
@@ -0,0 +1,2 @@
+#define TEST_GCS_EXPECT_ENABLED 0
+#include "tst-gcs-skeleton.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
new file mode 100644
index 0000000000..608318f26d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
@@ -0,0 +1,2 @@
+#define TEST_GCS_EXPECT_ENABLED 1
+#include "tst-gcs-skeleton.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
new file mode 100644
index 0000000000..54e3b9a0d5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
@@ -0,0 +1 @@
+#include "tst-gcs-optional-off.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
new file mode 100644
index 0000000000..11b884b429
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
@@ -0,0 +1 @@
+#include "tst-gcs-optional-on.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
new file mode 100644
index 0000000000..09055dcdc4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
@@ -0,0 +1 @@
+#include "tst-gcs-override.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
new file mode 100644
index 0000000000..608318f26d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
@@ -0,0 +1,2 @@
+#define TEST_GCS_EXPECT_ENABLED 1
+#include "tst-gcs-skeleton.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
new file mode 100644
index 0000000000..37692c96d0
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
@@ -0,0 +1,58 @@
+/* AArch64 tests for GCS.
+   Copyright (C) 2025 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/>.  */
+
+#include <support/check.h>
+#include <support/support.h>
+#include <support/test-driver.h>
+
+#include <stdio.h>
+#include <sys/auxv.h>
+
+static bool __check_gcs_status (void)
+{
+  register unsigned long x16 asm ("x16");
+  asm volatile (
+    "mov	x16, #1 /* _CHKFEAT_GCS */\n"
+    "hint	40 /* CHKFEAT_X16 */\n"
+    : "=r" (x16));
+  return x16 ^ 1;
+}
+
+static int
+do_test (void)
+{
+  /* Check if GCS could possible by enabled.  */
+  if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
+    {
+      puts ("kernel or CPU does not support GCS");
+      return EXIT_UNSUPPORTED;
+    }
+  bool gcs_enabled = __check_gcs_status ();
+  if (gcs_enabled)
+    puts ("GCS enabled");
+  else
+    puts ("GCS not enabled");
+#if TEST_GCS_EXPECT_ENABLED
+  TEST_VERIFY (gcs_enabled);
+#else
+  TEST_VERIFY (!gcs_enabled);
+#endif
+  return 0;
+}
+
+#include <support/test-driver.c>
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/4] aarch64: Add GCS tests for transitive dependencies
  2025-01-23 14:13 [PATCH 0/4] Add tests for Guarded Control Stack Yury Khrustalev
  2025-01-23 14:13 ` [PATCH 1/4] aarch64: " Yury Khrustalev
@ 2025-01-23 14:13 ` Yury Khrustalev
  2025-01-23 14:14 ` [PATCH 3/4] aarch64: Add GCS tests for dlopen Yury Khrustalev
  2025-01-23 14:14 ` [PATCH 4/4] aarch64: Add GCS test with signal handler Yury Khrustalev
  3 siblings, 0 replies; 11+ messages in thread
From: Yury Khrustalev @ 2025-01-23 14:13 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella

---
 sysdeps/unix/sysv/linux/aarch64/Makefile      | 29 +++++++++++++
 .../unix/sysv/linux/aarch64/tst-gcs-helper.h  | 39 ++++++++++++++++++
 .../unix/sysv/linux/aarch64/tst-gcs-mod1.c    | 27 ++++++++++++
 .../unix/sysv/linux/aarch64/tst-gcs-mod2.c    | 25 +++++++++++
 .../unix/sysv/linux/aarch64/tst-gcs-mod3.c    | 25 +++++++++++
 .../linux/aarch64/tst-gcs-shared-disabled.c   |  2 +
 .../aarch64/tst-gcs-shared-enforced-abort.c   |  2 +
 .../linux/aarch64/tst-gcs-shared-optional.c   |  2 +
 .../linux/aarch64/tst-gcs-shared-override.c   |  2 +
 .../unix/sysv/linux/aarch64/tst-gcs-shared.c  | 41 +++++++++++++++++++
 .../sysv/linux/aarch64/tst-gcs-skeleton.c     | 17 +-------
 11 files changed, 195 insertions(+), 16 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-helper.h
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod1.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod2.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod3.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-disabled.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-enforced-abort.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-optional.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-override.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared.c

diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
index 82a992bc14..8a9258f949 100644
--- a/sysdeps/unix/sysv/linux/aarch64/Makefile
+++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
@@ -8,6 +8,10 @@ gcs-tests-dynamic = \
   tst-gcs-optional-off \
   tst-gcs-optional-on \
   tst-gcs-override \
+  tst-gcs-shared-disabled \
+  tst-gcs-shared-enforced-abort \
+  tst-gcs-shared-optional \
+  tst-gcs-shared-override \
   # gcs-tests-dynamic
 
 gcs-tests-static = \
@@ -67,6 +71,31 @@ tst-gcs-optional-static-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
 tst-gcs-optional-static-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
 tst-gcs-override-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
 
+# force one of the dependencies to be unmarked
+LDFLAGS-tst-gcs-mod2.so += -Wl,-z gcs=never
+
+LDFLAGS-tst-gcs-shared-disabled = -Wl,-z gcs=always
+LDFLAGS-tst-gcs-shared-enforced-abort = -Wl,-z gcs=always
+LDFLAGS-tst-gcs-shared-optional = -Wl,-z gcs=always
+LDFLAGS-tst-gcs-shared-override = -Wl,-z gcs=always
+
+modules-names += \
+  tst-gcs-mod1 \
+  tst-gcs-mod2 \
+  tst-gcs-mod3 \
+  # modules-names
+
+$(objpfx)tst-gcs-shared-disabled: $(objpfx)tst-gcs-mod1.so $(objpfx)tst-gcs-mod3.so
+$(objpfx)tst-gcs-shared-enforced-abort: $(objpfx)tst-gcs-mod1.so $(objpfx)tst-gcs-mod3.so
+$(objpfx)tst-gcs-shared-optional: $(objpfx)tst-gcs-mod1.so $(objpfx)tst-gcs-mod3.so
+$(objpfx)tst-gcs-shared-override: $(objpfx)tst-gcs-mod1.so $(objpfx)tst-gcs-mod3.so
+$(objpfx)tst-gcs-mod1.so: $(objpfx)tst-gcs-mod2.so
+
+tst-gcs-shared-disabled-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
+tst-gcs-shared-enforced-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
+tst-gcs-shared-optional-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
+tst-gcs-shared-override-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
+
 endif
 
 ifeq ($(subdir),stdlib)
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-helper.h b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-helper.h
new file mode 100644
index 0000000000..ba092d47f5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-helper.h
@@ -0,0 +1,39 @@
+/* AArch64 tests for GCS.
+   Copyright (C) 2025 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/>.  */
+
+#ifndef TST_GCS_HELPER_H
+#define POINTER_GUARD_H
+
+#include <support/check.h>
+#include <support/support.h>
+#include <support/test-driver.h>
+
+#include <stdio.h>
+#include <sys/auxv.h>
+
+static bool __check_gcs_status (void)
+{
+  register unsigned long x16 asm ("x16");
+  asm volatile (
+    "mov	x16, #1 /* _CHKFEAT_GCS */\n"
+    "hint	40 /* CHKFEAT_X16 */\n"
+    : "=r" (x16));
+  return x16 ^ 1;
+}
+
+#endif // POINTER_GUARD_H
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod1.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod1.c
new file mode 100644
index 0000000000..283d64f5d0
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod1.c
@@ -0,0 +1,27 @@
+/* DSO for testing GCS.
+   Copyright (C) 2021-2025 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/>.  */
+
+#include <stdio.h>
+
+int fun2 (void); // tst-gcs-mod2.c
+
+int fun1 (void)
+{
+  puts ("called function fun1");
+  return fun2 ();
+}
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod2.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod2.c
new file mode 100644
index 0000000000..9039e032fb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod2.c
@@ -0,0 +1,25 @@
+/* DSO for testing GCS.
+   Copyright (C) 2021-2025 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/>.  */
+
+#include <stdio.h>
+
+int fun2 (void)
+{
+  puts ("called function fun2");
+  return 0;
+}
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod3.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod3.c
new file mode 100644
index 0000000000..44d052c859
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-mod3.c
@@ -0,0 +1,25 @@
+/* DSO for testing GCS.
+   Copyright (C) 2021-2025 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/>.  */
+
+#include <stdio.h>
+
+int fun3 (void)
+{
+  puts ("called function fun3");
+  return 0;
+}
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-disabled.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-disabled.c
new file mode 100644
index 0000000000..8598dc44b5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-disabled.c
@@ -0,0 +1,2 @@
+#define TEST_GCS_EXPECT_ENABLED 0
+#include "tst-gcs-shared.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-enforced-abort.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-enforced-abort.c
new file mode 100644
index 0000000000..f1333cee9d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-enforced-abort.c
@@ -0,0 +1,2 @@
+#define TEST_GCS_EXPECT_ENABLED 1
+#include "tst-gcs-shared.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-optional.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-optional.c
new file mode 100644
index 0000000000..8598dc44b5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-optional.c
@@ -0,0 +1,2 @@
+#define TEST_GCS_EXPECT_ENABLED 0
+#include "tst-gcs-shared.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-override.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-override.c
new file mode 100644
index 0000000000..f1333cee9d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared-override.c
@@ -0,0 +1,2 @@
+#define TEST_GCS_EXPECT_ENABLED 1
+#include "tst-gcs-shared.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared.c
new file mode 100644
index 0000000000..1192de69fc
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-shared.c
@@ -0,0 +1,41 @@
+/* AArch64 tests for GCS.
+   Copyright (C) 2025 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/>.  */
+
+#include "tst-gcs-helper.h"
+
+int fun1 (void); // tst-gcs-mod1.c
+int fun3 (void); // tst-gcs-mod3.c
+
+static int
+do_test (void)
+{
+  /* Check if GCS could possible by enabled.  */
+  if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
+    {
+      puts ("kernel or CPU does not support GCS");
+      return EXIT_UNSUPPORTED;
+    }
+#if TEST_GCS_EXPECT_ENABLED
+  TEST_VERIFY (__check_gcs_status ());
+#else
+  TEST_VERIFY (!__check_gcs_status ());
+#endif
+  return fun1 () + fun3 ();
+}
+
+#include <support/test-driver.c>
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
index 37692c96d0..feb5e33ebf 100644
--- a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
@@ -16,22 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#include <support/check.h>
-#include <support/support.h>
-#include <support/test-driver.h>
-
-#include <stdio.h>
-#include <sys/auxv.h>
-
-static bool __check_gcs_status (void)
-{
-  register unsigned long x16 asm ("x16");
-  asm volatile (
-    "mov	x16, #1 /* _CHKFEAT_GCS */\n"
-    "hint	40 /* CHKFEAT_X16 */\n"
-    : "=r" (x16));
-  return x16 ^ 1;
-}
+#include "tst-gcs-helper.h"
 
 static int
 do_test (void)
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 3/4] aarch64: Add GCS tests for dlopen
  2025-01-23 14:13 [PATCH 0/4] Add tests for Guarded Control Stack Yury Khrustalev
  2025-01-23 14:13 ` [PATCH 1/4] aarch64: " Yury Khrustalev
  2025-01-23 14:13 ` [PATCH 2/4] aarch64: Add GCS tests for transitive dependencies Yury Khrustalev
@ 2025-01-23 14:14 ` Yury Khrustalev
  2025-01-23 14:14 ` [PATCH 4/4] aarch64: Add GCS test with signal handler Yury Khrustalev
  3 siblings, 0 replies; 11+ messages in thread
From: Yury Khrustalev @ 2025-01-23 14:14 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella

---
 Makeconfig                                    |  2 +-
 sysdeps/unix/sysv/linux/aarch64/Makefile      | 23 +++++++
 .../linux/aarch64/tst-gcs-dlopen-disabled.c   |  3 +
 .../linux/aarch64/tst-gcs-dlopen-enforced.c   |  3 +
 .../aarch64/tst-gcs-dlopen-optional-off.c     |  3 +
 .../aarch64/tst-gcs-dlopen-optional-on.c      |  3 +
 .../linux/aarch64/tst-gcs-dlopen-override.c   |  3 +
 .../unix/sysv/linux/aarch64/tst-gcs-dlopen.c  | 62 +++++++++++++++++++
 8 files changed, 101 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-disabled.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-enforced.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-optional-off.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-optional-on.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-override.c
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen.c

diff --git a/Makeconfig b/Makeconfig
index d0108d2caa..aa547a443f 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -633,7 +633,7 @@ link-libc-printers-tests = $(link-libc-rpath) \
 			   $(link-libc-tests-after-rpath-link)
 
 # This is how to find at build-time things that will be installed there.
-rpath-dirs = math elf dlfcn nss nis rt resolv mathvec support
+rpath-dirs = math elf dlfcn nss nis rt resolv mathvec support misc
 rpath-link = \
 $(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%)))
 else  # build-static
diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
index 8a9258f949..31f4d80a94 100644
--- a/sysdeps/unix/sysv/linux/aarch64/Makefile
+++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
@@ -3,6 +3,11 @@ sysdep_headers += sys/elf.h
 
 gcs-tests-dynamic = \
   tst-gcs-disabled \
+  tst-gcs-dlopen-disabled \
+  tst-gcs-dlopen-enforced \
+  tst-gcs-dlopen-optional-off \
+  tst-gcs-dlopen-optional-on \
+  tst-gcs-dlopen-override \
   tst-gcs-enforced \
   tst-gcs-enforced-abort \
   tst-gcs-optional-off \
@@ -96,6 +101,24 @@ tst-gcs-shared-enforced-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
 tst-gcs-shared-optional-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
 tst-gcs-shared-override-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
 
+LDFLAGS-tst-gcs-dlopen-disabled = -Wl,-z gcs=always
+LDFLAGS-tst-gcs-dlopen-enforced = -Wl,-z gcs=always
+LDFLAGS-tst-gcs-dlopen-optional-on = -Wl,-z gcs=always
+LDFLAGS-tst-gcs-dlopen-optional-off = -Wl,-z gcs=never
+LDFLAGS-tst-gcs-dlopen-override = -Wl,-z gcs=always
+
+tst-gcs-dlopen-disabled-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
+tst-gcs-dlopen-enforced-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
+tst-gcs-dlopen-optional-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
+tst-gcs-dlopen-optional-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
+tst-gcs-dlopen-override-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
+
+$(objpfx)tst-gcs-dlopen-disabled.out: $(objpfx)tst-gcs-mod2.so
+$(objpfx)tst-gcs-dlopen-enforced.out: $(objpfx)tst-gcs-mod2.so
+$(objpfx)tst-gcs-dlopen-optional-on.out: $(objpfx)tst-gcs-mod2.so
+$(objpfx)tst-gcs-dlopen-optional-off.out: $(objpfx)tst-gcs-mod2.so
+$(objpfx)tst-gcs-dlopen-override.out: $(objpfx)tst-gcs-mod2.so
+
 endif
 
 ifeq ($(subdir),stdlib)
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-disabled.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-disabled.c
new file mode 100644
index 0000000000..34395280a3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-disabled.c
@@ -0,0 +1,3 @@
+#define TEST_GCS_EXPECT_ENABLED 0
+#define TEST_GCS_EXPECT_DLOPEN 1
+#include "tst-gcs-dlopen.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-enforced.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-enforced.c
new file mode 100644
index 0000000000..d8489ecd24
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-enforced.c
@@ -0,0 +1,3 @@
+#define TEST_GCS_EXPECT_ENABLED 1
+#define TEST_GCS_EXPECT_DLOPEN 0
+#include "tst-gcs-dlopen.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-optional-off.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-optional-off.c
new file mode 100644
index 0000000000..34395280a3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-optional-off.c
@@ -0,0 +1,3 @@
+#define TEST_GCS_EXPECT_ENABLED 0
+#define TEST_GCS_EXPECT_DLOPEN 1
+#include "tst-gcs-dlopen.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-optional-on.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-optional-on.c
new file mode 100644
index 0000000000..d8489ecd24
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-optional-on.c
@@ -0,0 +1,3 @@
+#define TEST_GCS_EXPECT_ENABLED 1
+#define TEST_GCS_EXPECT_DLOPEN 0
+#include "tst-gcs-dlopen.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-override.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-override.c
new file mode 100644
index 0000000000..152ffcf207
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen-override.c
@@ -0,0 +1,3 @@
+#define TEST_GCS_EXPECT_ENABLED 1
+#define TEST_GCS_EXPECT_DLOPEN 1
+#include "tst-gcs-dlopen.c"
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen.c
new file mode 100644
index 0000000000..6e0801c63a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-dlopen.c
@@ -0,0 +1,62 @@
+/* AArch64 tests for GCS for dlopen use case.
+   Copyright (C) 2025 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/>.  */
+
+#include "tst-gcs-helper.h"
+
+#include <dlfcn.h>
+#include <string.h>
+
+static int
+do_test (void)
+{
+  /* Check if GCS could possible by enabled.  */
+  if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
+    {
+      puts ("kernel or CPU does not support GCS");
+      return EXIT_UNSUPPORTED;
+    }
+  /* The tst-gcs-mod2.so test library does not have GCS marking.  */
+  void *h = dlopen ("tst-gcs-mod2.so", RTLD_NOW);
+  const char *err = dlerror ();
+
+#if TEST_GCS_EXPECT_DLOPEN
+  TEST_VERIFY (h != NULL);
+#else
+  TEST_VERIFY (h == NULL);
+  /* Only accept expected GCS-related errors.  */
+  TEST_VERIFY (strstr (err, "not GCS compatible") != NULL);
+#endif
+
+#if TEST_GCS_EXPECT_ENABLED
+  TEST_VERIFY (__check_gcs_status ());
+#else
+  TEST_VERIFY (!__check_gcs_status ());
+#endif
+
+  if (h == NULL)
+    printf ("dlopen error: %s\n", err);
+  else
+    {
+      puts ("library loaded normally");
+      dlclose (h);
+    }
+
+  return 0;
+}
+
+#include <support/test-driver.c>
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 4/4] aarch64: Add GCS test with signal handler
  2025-01-23 14:13 [PATCH 0/4] Add tests for Guarded Control Stack Yury Khrustalev
                   ` (2 preceding siblings ...)
  2025-01-23 14:14 ` [PATCH 3/4] aarch64: Add GCS tests for dlopen Yury Khrustalev
@ 2025-01-23 14:14 ` Yury Khrustalev
  3 siblings, 0 replies; 11+ messages in thread
From: Yury Khrustalev @ 2025-01-23 14:14 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella

Test that when we return from a function that enabled GCS at runtime
we get SIGSEGV. Also test that ucontext contains GCS block with the
GCS pointer.
---
 sysdeps/unix/sysv/linux/aarch64/Makefile      |  5 +
 .../sysv/linux/aarch64/tst-gcs-noreturn.c     | 96 +++++++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-noreturn.c

diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
index 31f4d80a94..067852ecf9 100644
--- a/sysdeps/unix/sysv/linux/aarch64/Makefile
+++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
@@ -10,6 +10,7 @@ gcs-tests-dynamic = \
   tst-gcs-dlopen-override \
   tst-gcs-enforced \
   tst-gcs-enforced-abort \
+  tst-gcs-noreturn \
   tst-gcs-optional-off \
   tst-gcs-optional-on \
   tst-gcs-override \
@@ -119,6 +120,10 @@ $(objpfx)tst-gcs-dlopen-optional-on.out: $(objpfx)tst-gcs-mod2.so
 $(objpfx)tst-gcs-dlopen-optional-off.out: $(objpfx)tst-gcs-mod2.so
 $(objpfx)tst-gcs-dlopen-override.out: $(objpfx)tst-gcs-mod2.so
 
+LDFLAGS-tst-gcs-noreturn = -Wl,-z gcs=always
+
+tst-gcs-noreturn-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
+
 endif
 
 ifeq ($(subdir),stdlib)
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-noreturn.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-noreturn.c
new file mode 100644
index 0000000000..c8f0d080d0
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-noreturn.c
@@ -0,0 +1,96 @@
+/* AArch64 test for GCS abort when returning to non-GCS address.
+   Copyright (C) 2025 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/>.  */
+
+#include "tst-gcs-helper.h"
+
+#include <sys/prctl.h>
+#include <signal.h>
+#include <stdlib.h>
+
+# ifndef PR_SET_SHADOW_STACK_STATUS
+#  define PR_SET_SHADOW_STACK_STATUS	75
+#  define PR_SHADOW_STACK_ENABLE	(1UL << 0)
+# endif
+
+static void
+run_with_gcs (void)
+{
+  int r = prctl(PR_SET_SHADOW_STACK_STATUS, PR_SHADOW_STACK_ENABLE, 0, 0, 0);
+  /* Syscall should succeed.  */
+  TEST_VERIFY (r == 0);
+  bool gcs_enabled = __check_gcs_status ();
+  /* Now GCS should be enabled.  */
+  TEST_VERIFY (gcs_enabled);
+  printf ("GCS is %s\n", gcs_enabled ? "enabled" : "disabled");
+}
+
+static struct _aarch64_ctx *
+extension (void *p)
+{
+  return p;
+}
+
+static void
+handler (int sig, siginfo_t *si, void *ctx)
+{
+  TEST_VERIFY (sig == SIGSEGV);
+  ucontext_t *uc = ctx;
+  void *p = uc->uc_mcontext.__reserved;
+  if (extension (p)->magic == FPSIMD_MAGIC)
+    p = (char *)p + extension (p)->size;
+  if (extension (p)->magic == GCS_MAGIC)
+    {
+      struct { uint64_t x, gcspr, y, z; } *q = p;
+      printf ("GCS pointer: %016lx\n", q->gcspr);
+      exit (0);
+    }
+  else
+    exit (3);
+}
+
+static int
+do_test (void)
+{
+  /* Check if GCS could possible by enabled.  */
+  if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
+    {
+      puts ("kernel or CPU does not support GCS");
+      return EXIT_UNSUPPORTED;
+    }
+  bool gcs_enabled = __check_gcs_status ();
+  /* This test should be rung with GCS initially disabled.  */
+  TEST_VERIFY (!gcs_enabled);
+
+  /* We can't use EXPECTED_SIGNAL because of cases when
+     this test runs on a system that does not support GCS
+     which is being detected at runtime.  */
+  struct sigaction sigact;
+  sigemptyset (&sigact.sa_mask);
+  sigact.sa_flags = 0;
+  sigact.sa_flags = sigact.sa_flags | SA_SIGINFO;
+  sigact.sa_sigaction = handler;
+  sigaction (SIGSEGV, &sigact, NULL);
+
+  run_with_gcs ();
+  /* If we reached this point, then something went wrong.
+     Returning from a function that enabled GCS should result in
+     SIGSEGV that we catch with the handler set up above.  */
+  return 2;
+}
+
+#include <support/test-driver.c>
-- 
2.39.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] aarch64: Add tests for Guarded Control Stack
  2025-01-23 14:13 ` [PATCH 1/4] aarch64: " Yury Khrustalev
@ 2025-01-27 20:47   ` Adhemerval Zanella Netto
  2025-01-28 10:08     ` Yury Khrustalev
  0 siblings, 1 reply; 11+ messages in thread
From: Adhemerval Zanella Netto @ 2025-01-27 20:47 UTC (permalink / raw)
  To: Yury Khrustalev, libc-alpha



On 23/01/25 11:13, Yury Khrustalev wrote:
> These tests validate that GCS tunable works as expected depending
> on the GCS markings in the test binaries.
> 
> Tests validate both static and dynamically linked binaries.
> 
> Test will build and run on AArch64 targets only and if GCS is not
> enabled on the platform running tests, they will be reported as
> UNSUPPORTED.
> 
> When linking tests a new linker command line flag -z gcs=<value>
> is used. If the toolchain used to build these tests doesn't support
> this flag, there will be a warning that is expected and should be
> ignored.

I think it would be better to add a configure check for '-z gcs=' support
and do not enable them if linker does not support it.

Making them UNSUPPORTED might be somewhat misleading without also check the
build outout for '-z gcs=always ignored', because on systems with HWCAP_GCS 
it will result in some unexpect results for __check_gcs_status.

> ---
>  sysdeps/unix/sysv/linux/aarch64/Makefile      | 64 +++++++++++++++++++
>  .../unix/sysv/linux/aarch64/tst-gcs-abort.sh  | 40 ++++++++++++
>  .../linux/aarch64/tst-gcs-disabled-static.c   |  1 +
>  .../sysv/linux/aarch64/tst-gcs-disabled.c     |  2 +
>  .../linux/aarch64/tst-gcs-enforced-abort.c    |  2 +
>  .../aarch64/tst-gcs-enforced-static-abort.c   |  1 +
>  .../linux/aarch64/tst-gcs-enforced-static.c   |  1 +
>  .../sysv/linux/aarch64/tst-gcs-enforced.c     |  2 +
>  .../sysv/linux/aarch64/tst-gcs-optional-off.c |  2 +
>  .../sysv/linux/aarch64/tst-gcs-optional-on.c  |  2 +
>  .../aarch64/tst-gcs-optional-static-off.c     |  1 +
>  .../aarch64/tst-gcs-optional-static-on.c      |  1 +
>  .../linux/aarch64/tst-gcs-override-static.c   |  1 +
>  .../sysv/linux/aarch64/tst-gcs-override.c     |  2 +
>  .../sysv/linux/aarch64/tst-gcs-skeleton.c     | 58 +++++++++++++++++
>  15 files changed, 180 insertions(+)
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
> 
> diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
> index 1fdad67fae..82a992bc14 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/Makefile
> +++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
> @@ -1,8 +1,72 @@
>  ifeq ($(subdir),misc)
>  sysdep_headers += sys/elf.h
> +
> +gcs-tests-dynamic = \
> +  tst-gcs-disabled \
> +  tst-gcs-enforced \
> +  tst-gcs-enforced-abort \
> +  tst-gcs-optional-off \
> +  tst-gcs-optional-on \
> +  tst-gcs-override \
> +  # gcs-tests-dynamic
> +
> +gcs-tests-static = \
> +  tst-gcs-disabled-static \
> +  tst-gcs-enforced-static \
> +  tst-gcs-enforced-static-abort \
> +  tst-gcs-optional-static-off \
> +  tst-gcs-optional-static-on \
> +  tst-gcs-override-static \
> +  # gcs-tests-static
> +
>  tests += \
> +  $(gcs-tests-dynamic) \
> +  $(gcs-tests-static) \
>    tst-aarch64-pkey \
>    # tests
> +
> +tests-static += \
> +  $(gcs-tests-static) \
> +  # tests-static
> +
> +define run-gcs-abort-test
> +  $(test-wrapper-env) $(run-program-env) \
> +  $(tst-gcs-$*-abort-ENV) $(host-test-program-cmd)
> +endef
> +
> +$(objpfx)tst-gcs-%-abort.out: $(..)sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh \
> +	$(objpfx)tst-gcs-%-abort
> +	$(SHELL) $< $(common-objpfx) $(test-name) '$(run-gcs-abort-test)'; \
> +	$(evaluate-test)
> +
> +LDFLAGS-tst-gcs-disabled += -Wl,-z gcs=always
> +LDFLAGS-tst-gcs-enforced += -Wl,-z gcs=always
> +LDFLAGS-tst-gcs-enforced-abort += -Wl,-z gcs=never
> +LDFLAGS-tst-gcs-optional-on += -Wl,-z gcs=always
> +LDFLAGS-tst-gcs-optional-off += -Wl,-z gcs=never
> +LDFLAGS-tst-gcs-override += -Wl,-z gcs=never
> +
> +LDFLAGS-tst-gcs-disabled-static += -Wl,-z gcs=always
> +LDFLAGS-tst-gcs-enforced-static += -Wl,-z gcs=always
> +LDFLAGS-tst-gcs-enforced-static-abort += -Wl,-z gcs=never
> +LDFLAGS-tst-gcs-optional-static-on += -Wl,-z gcs=always
> +LDFLAGS-tst-gcs-optional-static-off += -Wl,-z gcs=never
> +LDFLAGS-tst-gcs-override-static += -Wl,-z gcs=never
> +
> +tst-gcs-disabled-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
> +tst-gcs-enforced-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
> +tst-gcs-enforced-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
> +tst-gcs-optional-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
> +tst-gcs-optional-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
> +tst-gcs-override-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
> +
> +tst-gcs-disabled-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
> +tst-gcs-enforced-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
> +tst-gcs-enforced-static-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
> +tst-gcs-optional-static-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
> +tst-gcs-optional-static-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
> +tst-gcs-override-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
> +
>  endif
>  
>  ifeq ($(subdir),stdlib)
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
> new file mode 100644
> index 0000000000..5c1889bfcd
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
> @@ -0,0 +1,40 @@
> +#!/bin/sh
> +# Test wrapper for AArch64 tests for GCS that are expected to abort.
> +# Copyright (C) 2001-2025 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/>.
> +
> +objpfx=$1; shift
> +tstname=$1; shift
> +tstrun=$1; shift
> +
> +logfile=$objpfx/$tstname.out
> +
> +rm -vf $logfile
> +touch $logfile
> +
> +${tstrun} 2>> $logfile >> $logfile; status=$?
> +
> +if test $status -eq 127 \
> +  && grep -q -w "not GCS compatible" "$logfile" ; then
> +  exit 0
> +elif test $status -eq 77; then
> +  exit 77
> +else
> +  echo "unexpected test output or exit status $status"
> +  exit 1
> +fi
> +
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
> new file mode 100644
> index 0000000000..c71d68cb86
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
> @@ -0,0 +1 @@
> +#include "tst-gcs-disabled.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
> new file mode 100644
> index 0000000000..bd688785bb
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
> @@ -0,0 +1,2 @@
> +#define TEST_GCS_EXPECT_ENABLED 0
> +#include "tst-gcs-skeleton.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
> new file mode 100644
> index 0000000000..608318f26d
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
> @@ -0,0 +1,2 @@
> +#define TEST_GCS_EXPECT_ENABLED 1
> +#include "tst-gcs-skeleton.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
> new file mode 100644
> index 0000000000..c20a999f6b
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
> @@ -0,0 +1 @@
> +#include "tst-gcs-enforced-abort.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
> new file mode 100644
> index 0000000000..bb39dada55
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
> @@ -0,0 +1 @@
> +#include "tst-gcs-enforced.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
> new file mode 100644
> index 0000000000..608318f26d
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
> @@ -0,0 +1,2 @@
> +#define TEST_GCS_EXPECT_ENABLED 1
> +#include "tst-gcs-skeleton.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
> new file mode 100644
> index 0000000000..bd688785bb
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
> @@ -0,0 +1,2 @@
> +#define TEST_GCS_EXPECT_ENABLED 0
> +#include "tst-gcs-skeleton.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
> new file mode 100644
> index 0000000000..608318f26d
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
> @@ -0,0 +1,2 @@
> +#define TEST_GCS_EXPECT_ENABLED 1
> +#include "tst-gcs-skeleton.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
> new file mode 100644
> index 0000000000..54e3b9a0d5
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
> @@ -0,0 +1 @@
> +#include "tst-gcs-optional-off.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
> new file mode 100644
> index 0000000000..11b884b429
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
> @@ -0,0 +1 @@
> +#include "tst-gcs-optional-on.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
> new file mode 100644
> index 0000000000..09055dcdc4
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
> @@ -0,0 +1 @@
> +#include "tst-gcs-override.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
> new file mode 100644
> index 0000000000..608318f26d
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
> @@ -0,0 +1,2 @@
> +#define TEST_GCS_EXPECT_ENABLED 1
> +#include "tst-gcs-skeleton.c"
> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
> new file mode 100644
> index 0000000000..37692c96d0
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
> @@ -0,0 +1,58 @@
> +/* AArch64 tests for GCS.
> +   Copyright (C) 2025 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/>.  */
> +
> +#include <support/check.h>
> +#include <support/support.h>
> +#include <support/test-driver.h>
> +
> +#include <stdio.h>
> +#include <sys/auxv.h>
> +
> +static bool __check_gcs_status (void)
> +{
> +  register unsigned long x16 asm ("x16");
> +  asm volatile (
> +    "mov	x16, #1 /* _CHKFEAT_GCS */\n"
> +    "hint	40 /* CHKFEAT_X16 */\n"
> +    : "=r" (x16));
> +  return x16 ^ 1;
> +}
> +
> +static int
> +do_test (void)
> +{
> +  /* Check if GCS could possible by enabled.  */
> +  if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
> +    {
> +      puts ("kernel or CPU does not support GCS");
> +      return EXIT_UNSUPPORTED;
> +    }
> +  bool gcs_enabled = __check_gcs_status ();
> +  if (gcs_enabled)
> +    puts ("GCS enabled");
> +  else
> +    puts ("GCS not enabled");
> +#if TEST_GCS_EXPECT_ENABLED
> +  TEST_VERIFY (gcs_enabled);
> +#else
> +  TEST_VERIFY (!gcs_enabled);
> +#endif
> +  return 0;
> +}
> +
> +#include <support/test-driver.c>

The rest looks ok.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] aarch64: Add tests for Guarded Control Stack
  2025-01-27 20:47   ` Adhemerval Zanella Netto
@ 2025-01-28 10:08     ` Yury Khrustalev
  2025-01-28 11:49       ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 11+ messages in thread
From: Yury Khrustalev @ 2025-01-28 10:08 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: libc-alpha

On Mon, Jan 27, 2025 at 05:47:21PM -0300, Adhemerval Zanella Netto wrote:
> 
> On 23/01/25 11:13, Yury Khrustalev wrote:
> > These tests validate that GCS tunable works as expected depending
> > on the GCS markings in the test binaries.
> > 
> > Tests validate both static and dynamically linked binaries.
> > 
> > Test will build and run on AArch64 targets only and if GCS is not
> > enabled on the platform running tests, they will be reported as
> > UNSUPPORTED.
> > 
> > When linking tests a new linker command line flag -z gcs=<value>
> > is used. If the toolchain used to build these tests doesn't support
> > this flag, there will be a warning that is expected and should be
> > ignored.
> 
> I think it would be better to add a configure check for '-z gcs=' support
> and do not enable them if linker does not support it.

Such an option would only be needed for tests however it may give an
impression that it can be used for the library code as well which would
be incorrect. I'm not sure what is the best approach here but it would
be good to use some sort of test-only configuration.

> Making them UNSUPPORTED might be somewhat misleading without also check the
> build outout for '-z gcs=always ignored', because on systems with HWCAP_GCS 
> it will result in some unexpect results for __check_gcs_status.

This is true, some of the tests will fail on such a system. I'm using assumption
that the toolchain supports GCS if we intend to run tests on a system that has
HWCAP_GCS.

Please note that there is v2 of this series:
https://inbox.sourceware.org/libc-alpha/20250124122858.3788655-1-yury.khrustalev@arm.com/
 
> > ---
> >  sysdeps/unix/sysv/linux/aarch64/Makefile      | 64 +++++++++++++++++++
> >  .../unix/sysv/linux/aarch64/tst-gcs-abort.sh  | 40 ++++++++++++
> >  .../linux/aarch64/tst-gcs-disabled-static.c   |  1 +
> >  .../sysv/linux/aarch64/tst-gcs-disabled.c     |  2 +
> >  .../linux/aarch64/tst-gcs-enforced-abort.c    |  2 +
> >  .../aarch64/tst-gcs-enforced-static-abort.c   |  1 +
> >  .../linux/aarch64/tst-gcs-enforced-static.c   |  1 +
> >  .../sysv/linux/aarch64/tst-gcs-enforced.c     |  2 +
> >  .../sysv/linux/aarch64/tst-gcs-optional-off.c |  2 +
> >  .../sysv/linux/aarch64/tst-gcs-optional-on.c  |  2 +
> >  .../aarch64/tst-gcs-optional-static-off.c     |  1 +
> >  .../aarch64/tst-gcs-optional-static-on.c      |  1 +
> >  .../linux/aarch64/tst-gcs-override-static.c   |  1 +
> >  .../sysv/linux/aarch64/tst-gcs-override.c     |  2 +
> >  .../sysv/linux/aarch64/tst-gcs-skeleton.c     | 58 +++++++++++++++++
> >  15 files changed, 180 insertions(+)
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
> >  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
> > 
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
> > index 1fdad67fae..82a992bc14 100644
> > --- a/sysdeps/unix/sysv/linux/aarch64/Makefile
> > +++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
> > @@ -1,8 +1,72 @@
> >  ifeq ($(subdir),misc)
> >  sysdep_headers += sys/elf.h
> > +
> > +gcs-tests-dynamic = \
> > +  tst-gcs-disabled \
> > +  tst-gcs-enforced \
> > +  tst-gcs-enforced-abort \
> > +  tst-gcs-optional-off \
> > +  tst-gcs-optional-on \
> > +  tst-gcs-override \
> > +  # gcs-tests-dynamic
> > +
> > +gcs-tests-static = \
> > +  tst-gcs-disabled-static \
> > +  tst-gcs-enforced-static \
> > +  tst-gcs-enforced-static-abort \
> > +  tst-gcs-optional-static-off \
> > +  tst-gcs-optional-static-on \
> > +  tst-gcs-override-static \
> > +  # gcs-tests-static
> > +
> >  tests += \
> > +  $(gcs-tests-dynamic) \
> > +  $(gcs-tests-static) \
> >    tst-aarch64-pkey \
> >    # tests
> > +
> > +tests-static += \
> > +  $(gcs-tests-static) \
> > +  # tests-static
> > +
> > +define run-gcs-abort-test
> > +  $(test-wrapper-env) $(run-program-env) \
> > +  $(tst-gcs-$*-abort-ENV) $(host-test-program-cmd)
> > +endef
> > +
> > +$(objpfx)tst-gcs-%-abort.out: $(..)sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh \
> > +	$(objpfx)tst-gcs-%-abort
> > +	$(SHELL) $< $(common-objpfx) $(test-name) '$(run-gcs-abort-test)'; \
> > +	$(evaluate-test)
> > +
> > +LDFLAGS-tst-gcs-disabled += -Wl,-z gcs=always
> > +LDFLAGS-tst-gcs-enforced += -Wl,-z gcs=always
> > +LDFLAGS-tst-gcs-enforced-abort += -Wl,-z gcs=never
> > +LDFLAGS-tst-gcs-optional-on += -Wl,-z gcs=always
> > +LDFLAGS-tst-gcs-optional-off += -Wl,-z gcs=never
> > +LDFLAGS-tst-gcs-override += -Wl,-z gcs=never
> > +
> > +LDFLAGS-tst-gcs-disabled-static += -Wl,-z gcs=always
> > +LDFLAGS-tst-gcs-enforced-static += -Wl,-z gcs=always
> > +LDFLAGS-tst-gcs-enforced-static-abort += -Wl,-z gcs=never
> > +LDFLAGS-tst-gcs-optional-static-on += -Wl,-z gcs=always
> > +LDFLAGS-tst-gcs-optional-static-off += -Wl,-z gcs=never
> > +LDFLAGS-tst-gcs-override-static += -Wl,-z gcs=never
> > +
> > +tst-gcs-disabled-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
> > +tst-gcs-enforced-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
> > +tst-gcs-enforced-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
> > +tst-gcs-optional-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
> > +tst-gcs-optional-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
> > +tst-gcs-override-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
> > +
> > +tst-gcs-disabled-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
> > +tst-gcs-enforced-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
> > +tst-gcs-enforced-static-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
> > +tst-gcs-optional-static-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
> > +tst-gcs-optional-static-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
> > +tst-gcs-override-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
> > +
> >  endif
> >  
> >  ifeq ($(subdir),stdlib)
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
> > new file mode 100644
> > index 0000000000..5c1889bfcd
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
> > @@ -0,0 +1,40 @@
> > +#!/bin/sh
> > +# Test wrapper for AArch64 tests for GCS that are expected to abort.
> > +# Copyright (C) 2001-2025 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/>.
> > +
> > +objpfx=$1; shift
> > +tstname=$1; shift
> > +tstrun=$1; shift
> > +
> > +logfile=$objpfx/$tstname.out
> > +
> > +rm -vf $logfile
> > +touch $logfile
> > +
> > +${tstrun} 2>> $logfile >> $logfile; status=$?
> > +
> > +if test $status -eq 127 \
> > +  && grep -q -w "not GCS compatible" "$logfile" ; then
> > +  exit 0
> > +elif test $status -eq 77; then
> > +  exit 77
> > +else
> > +  echo "unexpected test output or exit status $status"
> > +  exit 1
> > +fi
> > +
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
> > new file mode 100644
> > index 0000000000..c71d68cb86
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
> > @@ -0,0 +1 @@
> > +#include "tst-gcs-disabled.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
> > new file mode 100644
> > index 0000000000..bd688785bb
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
> > @@ -0,0 +1,2 @@
> > +#define TEST_GCS_EXPECT_ENABLED 0
> > +#include "tst-gcs-skeleton.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
> > new file mode 100644
> > index 0000000000..608318f26d
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
> > @@ -0,0 +1,2 @@
> > +#define TEST_GCS_EXPECT_ENABLED 1
> > +#include "tst-gcs-skeleton.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
> > new file mode 100644
> > index 0000000000..c20a999f6b
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
> > @@ -0,0 +1 @@
> > +#include "tst-gcs-enforced-abort.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
> > new file mode 100644
> > index 0000000000..bb39dada55
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
> > @@ -0,0 +1 @@
> > +#include "tst-gcs-enforced.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
> > new file mode 100644
> > index 0000000000..608318f26d
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
> > @@ -0,0 +1,2 @@
> > +#define TEST_GCS_EXPECT_ENABLED 1
> > +#include "tst-gcs-skeleton.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
> > new file mode 100644
> > index 0000000000..bd688785bb
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
> > @@ -0,0 +1,2 @@
> > +#define TEST_GCS_EXPECT_ENABLED 0
> > +#include "tst-gcs-skeleton.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
> > new file mode 100644
> > index 0000000000..608318f26d
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
> > @@ -0,0 +1,2 @@
> > +#define TEST_GCS_EXPECT_ENABLED 1
> > +#include "tst-gcs-skeleton.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
> > new file mode 100644
> > index 0000000000..54e3b9a0d5
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
> > @@ -0,0 +1 @@
> > +#include "tst-gcs-optional-off.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
> > new file mode 100644
> > index 0000000000..11b884b429
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
> > @@ -0,0 +1 @@
> > +#include "tst-gcs-optional-on.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
> > new file mode 100644
> > index 0000000000..09055dcdc4
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
> > @@ -0,0 +1 @@
> > +#include "tst-gcs-override.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
> > new file mode 100644
> > index 0000000000..608318f26d
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
> > @@ -0,0 +1,2 @@
> > +#define TEST_GCS_EXPECT_ENABLED 1
> > +#include "tst-gcs-skeleton.c"
> > diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
> > new file mode 100644
> > index 0000000000..37692c96d0
> > --- /dev/null
> > +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
> > @@ -0,0 +1,58 @@
> > +/* AArch64 tests for GCS.
> > +   Copyright (C) 2025 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/>.  */
> > +
> > +#include <support/check.h>
> > +#include <support/support.h>
> > +#include <support/test-driver.h>
> > +
> > +#include <stdio.h>
> > +#include <sys/auxv.h>
> > +
> > +static bool __check_gcs_status (void)
> > +{
> > +  register unsigned long x16 asm ("x16");
> > +  asm volatile (
> > +    "mov	x16, #1 /* _CHKFEAT_GCS */\n"
> > +    "hint	40 /* CHKFEAT_X16 */\n"
> > +    : "=r" (x16));
> > +  return x16 ^ 1;
> > +}
> > +
> > +static int
> > +do_test (void)
> > +{
> > +  /* Check if GCS could possible by enabled.  */
> > +  if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
> > +    {
> > +      puts ("kernel or CPU does not support GCS");
> > +      return EXIT_UNSUPPORTED;
> > +    }
> > +  bool gcs_enabled = __check_gcs_status ();
> > +  if (gcs_enabled)
> > +    puts ("GCS enabled");
> > +  else
> > +    puts ("GCS not enabled");
> > +#if TEST_GCS_EXPECT_ENABLED
> > +  TEST_VERIFY (gcs_enabled);
> > +#else
> > +  TEST_VERIFY (!gcs_enabled);
> > +#endif
> > +  return 0;
> > +}
> > +
> > +#include <support/test-driver.c>
> 
> The rest looks ok.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] aarch64: Add tests for Guarded Control Stack
  2025-01-28 10:08     ` Yury Khrustalev
@ 2025-01-28 11:49       ` Adhemerval Zanella Netto
  2025-01-28 13:23         ` Yury Khrustalev
  0 siblings, 1 reply; 11+ messages in thread
From: Adhemerval Zanella Netto @ 2025-01-28 11:49 UTC (permalink / raw)
  To: Yury Khrustalev; +Cc: libc-alpha



On 28/01/25 07:08, Yury Khrustalev wrote:
> On Mon, Jan 27, 2025 at 05:47:21PM -0300, Adhemerval Zanella Netto wrote:
>>
>> On 23/01/25 11:13, Yury Khrustalev wrote:
>>> These tests validate that GCS tunable works as expected depending
>>> on the GCS markings in the test binaries.
>>>
>>> Tests validate both static and dynamically linked binaries.
>>>
>>> Test will build and run on AArch64 targets only and if GCS is not
>>> enabled on the platform running tests, they will be reported as
>>> UNSUPPORTED.
>>>
>>> When linking tests a new linker command line flag -z gcs=<value>
>>> is used. If the toolchain used to build these tests doesn't support
>>> this flag, there will be a warning that is expected and should be
>>> ignored.
>>
>> I think it would be better to add a configure check for '-z gcs=' support
>> and do not enable them if linker does not support it.
> 
> Such an option would only be needed for tests however it may give an
> impression that it can be used for the library code as well which would
> be incorrect. I'm not sure what is the best approach here but it would
> be good to use some sort of test-only configuration.

But this would be done automatically and only enabled during tests, as we
for various linker options on multiple Makefiles like have-test-stb-gnu-unique,
have-fpie, have-test-cc-trampoline, etc.  

I don't see much value in building a test that user will need to debug further 
to understand what it is failing (for instance on a system with HWCAP_GCS, but
without a toolchain that support -z gcs).

> 
>> Making them UNSUPPORTED might be somewhat misleading without also check the
>> build outout for '-z gcs=always ignored', because on systems with HWCAP_GCS 
>> it will result in some unexpect results for __check_gcs_status.
> 
> This is true, some of the tests will fail on such a system. I'm using assumption
> that the toolchain supports GCS if we intend to run tests on a system that has
> HWCAP_GCS.
> > Please note that there is v2 of this series:
> https://inbox.sourceware.org/libc-alpha/20250124122858.3788655-1-yury.khrustalev@arm.com/

Right, I missed that. I will focus on this version.

>  
>>> ---
>>>  sysdeps/unix/sysv/linux/aarch64/Makefile      | 64 +++++++++++++++++++
>>>  .../unix/sysv/linux/aarch64/tst-gcs-abort.sh  | 40 ++++++++++++
>>>  .../linux/aarch64/tst-gcs-disabled-static.c   |  1 +
>>>  .../sysv/linux/aarch64/tst-gcs-disabled.c     |  2 +
>>>  .../linux/aarch64/tst-gcs-enforced-abort.c    |  2 +
>>>  .../aarch64/tst-gcs-enforced-static-abort.c   |  1 +
>>>  .../linux/aarch64/tst-gcs-enforced-static.c   |  1 +
>>>  .../sysv/linux/aarch64/tst-gcs-enforced.c     |  2 +
>>>  .../sysv/linux/aarch64/tst-gcs-optional-off.c |  2 +
>>>  .../sysv/linux/aarch64/tst-gcs-optional-on.c  |  2 +
>>>  .../aarch64/tst-gcs-optional-static-off.c     |  1 +
>>>  .../aarch64/tst-gcs-optional-static-on.c      |  1 +
>>>  .../linux/aarch64/tst-gcs-override-static.c   |  1 +
>>>  .../sysv/linux/aarch64/tst-gcs-override.c     |  2 +
>>>  .../sysv/linux/aarch64/tst-gcs-skeleton.c     | 58 +++++++++++++++++
>>>  15 files changed, 180 insertions(+)
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
>>>  create mode 100644 sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
>>>
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
>>> index 1fdad67fae..82a992bc14 100644
>>> --- a/sysdeps/unix/sysv/linux/aarch64/Makefile
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
>>> @@ -1,8 +1,72 @@
>>>  ifeq ($(subdir),misc)
>>>  sysdep_headers += sys/elf.h
>>> +
>>> +gcs-tests-dynamic = \
>>> +  tst-gcs-disabled \
>>> +  tst-gcs-enforced \
>>> +  tst-gcs-enforced-abort \
>>> +  tst-gcs-optional-off \
>>> +  tst-gcs-optional-on \
>>> +  tst-gcs-override \
>>> +  # gcs-tests-dynamic
>>> +
>>> +gcs-tests-static = \
>>> +  tst-gcs-disabled-static \
>>> +  tst-gcs-enforced-static \
>>> +  tst-gcs-enforced-static-abort \
>>> +  tst-gcs-optional-static-off \
>>> +  tst-gcs-optional-static-on \
>>> +  tst-gcs-override-static \
>>> +  # gcs-tests-static
>>> +
>>>  tests += \
>>> +  $(gcs-tests-dynamic) \
>>> +  $(gcs-tests-static) \
>>>    tst-aarch64-pkey \
>>>    # tests
>>> +
>>> +tests-static += \
>>> +  $(gcs-tests-static) \
>>> +  # tests-static
>>> +
>>> +define run-gcs-abort-test
>>> +  $(test-wrapper-env) $(run-program-env) \
>>> +  $(tst-gcs-$*-abort-ENV) $(host-test-program-cmd)
>>> +endef
>>> +
>>> +$(objpfx)tst-gcs-%-abort.out: $(..)sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh \
>>> +	$(objpfx)tst-gcs-%-abort
>>> +	$(SHELL) $< $(common-objpfx) $(test-name) '$(run-gcs-abort-test)'; \
>>> +	$(evaluate-test)
>>> +
>>> +LDFLAGS-tst-gcs-disabled += -Wl,-z gcs=always
>>> +LDFLAGS-tst-gcs-enforced += -Wl,-z gcs=always
>>> +LDFLAGS-tst-gcs-enforced-abort += -Wl,-z gcs=never
>>> +LDFLAGS-tst-gcs-optional-on += -Wl,-z gcs=always
>>> +LDFLAGS-tst-gcs-optional-off += -Wl,-z gcs=never
>>> +LDFLAGS-tst-gcs-override += -Wl,-z gcs=never
>>> +
>>> +LDFLAGS-tst-gcs-disabled-static += -Wl,-z gcs=always
>>> +LDFLAGS-tst-gcs-enforced-static += -Wl,-z gcs=always
>>> +LDFLAGS-tst-gcs-enforced-static-abort += -Wl,-z gcs=never
>>> +LDFLAGS-tst-gcs-optional-static-on += -Wl,-z gcs=always
>>> +LDFLAGS-tst-gcs-optional-static-off += -Wl,-z gcs=never
>>> +LDFLAGS-tst-gcs-override-static += -Wl,-z gcs=never
>>> +
>>> +tst-gcs-disabled-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
>>> +tst-gcs-enforced-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
>>> +tst-gcs-enforced-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
>>> +tst-gcs-optional-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
>>> +tst-gcs-optional-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
>>> +tst-gcs-override-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
>>> +
>>> +tst-gcs-disabled-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=0
>>> +tst-gcs-enforced-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
>>> +tst-gcs-enforced-static-abort-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1
>>> +tst-gcs-optional-static-on-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
>>> +tst-gcs-optional-static-off-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=2
>>> +tst-gcs-override-static-ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=3
>>> +
>>>  endif
>>>  
>>>  ifeq ($(subdir),stdlib)
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
>>> new file mode 100644
>>> index 0000000000..5c1889bfcd
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-abort.sh
>>> @@ -0,0 +1,40 @@
>>> +#!/bin/sh
>>> +# Test wrapper for AArch64 tests for GCS that are expected to abort.
>>> +# Copyright (C) 2001-2025 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/>.
>>> +
>>> +objpfx=$1; shift
>>> +tstname=$1; shift
>>> +tstrun=$1; shift
>>> +
>>> +logfile=$objpfx/$tstname.out
>>> +
>>> +rm -vf $logfile
>>> +touch $logfile
>>> +
>>> +${tstrun} 2>> $logfile >> $logfile; status=$?
>>> +
>>> +if test $status -eq 127 \
>>> +  && grep -q -w "not GCS compatible" "$logfile" ; then
>>> +  exit 0
>>> +elif test $status -eq 77; then
>>> +  exit 77
>>> +else
>>> +  echo "unexpected test output or exit status $status"
>>> +  exit 1
>>> +fi
>>> +
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
>>> new file mode 100644
>>> index 0000000000..c71d68cb86
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled-static.c
>>> @@ -0,0 +1 @@
>>> +#include "tst-gcs-disabled.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
>>> new file mode 100644
>>> index 0000000000..bd688785bb
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-disabled.c
>>> @@ -0,0 +1,2 @@
>>> +#define TEST_GCS_EXPECT_ENABLED 0
>>> +#include "tst-gcs-skeleton.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
>>> new file mode 100644
>>> index 0000000000..608318f26d
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-abort.c
>>> @@ -0,0 +1,2 @@
>>> +#define TEST_GCS_EXPECT_ENABLED 1
>>> +#include "tst-gcs-skeleton.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
>>> new file mode 100644
>>> index 0000000000..c20a999f6b
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static-abort.c
>>> @@ -0,0 +1 @@
>>> +#include "tst-gcs-enforced-abort.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
>>> new file mode 100644
>>> index 0000000000..bb39dada55
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced-static.c
>>> @@ -0,0 +1 @@
>>> +#include "tst-gcs-enforced.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
>>> new file mode 100644
>>> index 0000000000..608318f26d
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-enforced.c
>>> @@ -0,0 +1,2 @@
>>> +#define TEST_GCS_EXPECT_ENABLED 1
>>> +#include "tst-gcs-skeleton.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
>>> new file mode 100644
>>> index 0000000000..bd688785bb
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-off.c
>>> @@ -0,0 +1,2 @@
>>> +#define TEST_GCS_EXPECT_ENABLED 0
>>> +#include "tst-gcs-skeleton.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
>>> new file mode 100644
>>> index 0000000000..608318f26d
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-on.c
>>> @@ -0,0 +1,2 @@
>>> +#define TEST_GCS_EXPECT_ENABLED 1
>>> +#include "tst-gcs-skeleton.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
>>> new file mode 100644
>>> index 0000000000..54e3b9a0d5
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-off.c
>>> @@ -0,0 +1 @@
>>> +#include "tst-gcs-optional-off.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
>>> new file mode 100644
>>> index 0000000000..11b884b429
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-optional-static-on.c
>>> @@ -0,0 +1 @@
>>> +#include "tst-gcs-optional-on.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
>>> new file mode 100644
>>> index 0000000000..09055dcdc4
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override-static.c
>>> @@ -0,0 +1 @@
>>> +#include "tst-gcs-override.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
>>> new file mode 100644
>>> index 0000000000..608318f26d
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-override.c
>>> @@ -0,0 +1,2 @@
>>> +#define TEST_GCS_EXPECT_ENABLED 1
>>> +#include "tst-gcs-skeleton.c"
>>> diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
>>> new file mode 100644
>>> index 0000000000..37692c96d0
>>> --- /dev/null
>>> +++ b/sysdeps/unix/sysv/linux/aarch64/tst-gcs-skeleton.c
>>> @@ -0,0 +1,58 @@
>>> +/* AArch64 tests for GCS.
>>> +   Copyright (C) 2025 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/>.  */
>>> +
>>> +#include <support/check.h>
>>> +#include <support/support.h>
>>> +#include <support/test-driver.h>
>>> +
>>> +#include <stdio.h>
>>> +#include <sys/auxv.h>
>>> +
>>> +static bool __check_gcs_status (void)
>>> +{
>>> +  register unsigned long x16 asm ("x16");
>>> +  asm volatile (
>>> +    "mov	x16, #1 /* _CHKFEAT_GCS */\n"
>>> +    "hint	40 /* CHKFEAT_X16 */\n"
>>> +    : "=r" (x16));
>>> +  return x16 ^ 1;
>>> +}
>>> +
>>> +static int
>>> +do_test (void)
>>> +{
>>> +  /* Check if GCS could possible by enabled.  */
>>> +  if (!(getauxval (AT_HWCAP) & HWCAP_GCS))
>>> +    {
>>> +      puts ("kernel or CPU does not support GCS");
>>> +      return EXIT_UNSUPPORTED;
>>> +    }
>>> +  bool gcs_enabled = __check_gcs_status ();
>>> +  if (gcs_enabled)
>>> +    puts ("GCS enabled");
>>> +  else
>>> +    puts ("GCS not enabled");
>>> +#if TEST_GCS_EXPECT_ENABLED
>>> +  TEST_VERIFY (gcs_enabled);
>>> +#else
>>> +  TEST_VERIFY (!gcs_enabled);
>>> +#endif
>>> +  return 0;
>>> +}
>>> +
>>> +#include <support/test-driver.c>
>>
>> The rest looks ok.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] aarch64: Add tests for Guarded Control Stack
  2025-01-28 11:49       ` Adhemerval Zanella Netto
@ 2025-01-28 13:23         ` Yury Khrustalev
  2025-01-28 14:28           ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 11+ messages in thread
From: Yury Khrustalev @ 2025-01-28 13:23 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: libc-alpha

On Tue, Jan 28, 2025 at 08:49:00AM -0300, Adhemerval Zanella Netto wrote:
> 
> On 28/01/25 07:08, Yury Khrustalev wrote:
> > On Mon, Jan 27, 2025 at 05:47:21PM -0300, Adhemerval Zanella Netto wrote:
> >>
> >> On 23/01/25 11:13, Yury Khrustalev wrote:
> >>> These tests validate that GCS tunable works as expected depending
> >>> on the GCS markings in the test binaries.
> >>>
> >>> Tests validate both static and dynamically linked binaries.
> >>>
> >>> Test will build and run on AArch64 targets only and if GCS is not
> >>> enabled on the platform running tests, they will be reported as
> >>> UNSUPPORTED.
> >>>
> >>> When linking tests a new linker command line flag -z gcs=<value>
> >>> is used. If the toolchain used to build these tests doesn't support
> >>> this flag, there will be a warning that is expected and should be
> >>> ignored.
> >>
> >> I think it would be better to add a configure check for '-z gcs=' support
> >> and do not enable them if linker does not support it.
> > 
> > Such an option would only be needed for tests however it may give an
> > impression that it can be used for the library code as well which would
> > be incorrect. I'm not sure what is the best approach here but it would
> > be good to use some sort of test-only configuration.
> 
> But this would be done automatically and only enabled during tests, as we
> for various linker options on multiple Makefiles like have-test-stb-gnu-unique,
> have-fpie, have-test-cc-trampoline, etc.

Would LIBC_LINKER_FEATURE be appropriate here. I see that for compiler flags
support there is a desinction between CC and TEST_CC so probably it's the
same for linker? But I can't find something like LIBC_TEST_LINKER_FEATURE.

Kind regards,
Yury


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] aarch64: Add tests for Guarded Control Stack
  2025-01-28 13:23         ` Yury Khrustalev
@ 2025-01-28 14:28           ` Adhemerval Zanella Netto
  2025-01-29  9:56             ` Yury Khrustalev
  0 siblings, 1 reply; 11+ messages in thread
From: Adhemerval Zanella Netto @ 2025-01-28 14:28 UTC (permalink / raw)
  To: Yury Khrustalev; +Cc: libc-alpha



On 28/01/25 10:23, Yury Khrustalev wrote:
> On Tue, Jan 28, 2025 at 08:49:00AM -0300, Adhemerval Zanella Netto wrote:
>>
>> On 28/01/25 07:08, Yury Khrustalev wrote:
>>> On Mon, Jan 27, 2025 at 05:47:21PM -0300, Adhemerval Zanella Netto wrote:
>>>>
>>>> On 23/01/25 11:13, Yury Khrustalev wrote:
>>>>> These tests validate that GCS tunable works as expected depending
>>>>> on the GCS markings in the test binaries.
>>>>>
>>>>> Tests validate both static and dynamically linked binaries.
>>>>>
>>>>> Test will build and run on AArch64 targets only and if GCS is not
>>>>> enabled on the platform running tests, they will be reported as
>>>>> UNSUPPORTED.
>>>>>
>>>>> When linking tests a new linker command line flag -z gcs=<value>
>>>>> is used. If the toolchain used to build these tests doesn't support
>>>>> this flag, there will be a warning that is expected and should be
>>>>> ignored.
>>>>
>>>> I think it would be better to add a configure check for '-z gcs=' support
>>>> and do not enable them if linker does not support it.
>>>
>>> Such an option would only be needed for tests however it may give an
>>> impression that it can be used for the library code as well which would
>>> be incorrect. I'm not sure what is the best approach here but it would
>>> be good to use some sort of test-only configuration.
>>
>> But this would be done automatically and only enabled during tests, as we
>> for various linker options on multiple Makefiles like have-test-stb-gnu-unique,
>> have-fpie, have-test-cc-trampoline, etc.
> 
> Would LIBC_LINKER_FEATURE be appropriate here. I see that for compiler flags
> support there is a desinction between CC and TEST_CC so probably it's the
> same for linker? But I can't find something like LIBC_TEST_LINKER_FEATURE.

I think we should LIBC_LINKER_FEATURE for now, it is used on some tests enablement
like have-z-execstack.  But the CC and TEST_CC is a good point and we might
get back to this if/when CC and TEST_CC uses a liker with different support
(which I think was not taking in consideration for TEST_CC addition).  

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/4] aarch64: Add tests for Guarded Control Stack
  2025-01-28 14:28           ` Adhemerval Zanella Netto
@ 2025-01-29  9:56             ` Yury Khrustalev
  0 siblings, 0 replies; 11+ messages in thread
From: Yury Khrustalev @ 2025-01-29  9:56 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: libc-alpha

On Tue, Jan 28, 2025 at 11:28:40AM -0300, Adhemerval Zanella Netto wrote:
> 
> > Would LIBC_LINKER_FEATURE be appropriate here. I see that for compiler flags
> > support there is a desinction between CC and TEST_CC so probably it's the
> > same for linker? But I can't find something like LIBC_TEST_LINKER_FEATURE.
> 
> I think we should LIBC_LINKER_FEATURE for now, it is used on some tests enablement
> like have-z-execstack.  But the CC and TEST_CC is a good point and we might
> get back to this if/when CC and TEST_CC uses a liker with different support
> (which I think was not taking in consideration for TEST_CC addition).

Thanks, I've sent v3 with the new configure check that allows to only enable
GCS tests if toolchain supports them, and then it run on both systems with
and without GCS (UNSUPPORTED in the latter case).

https://inbox.sourceware.org/libc-alpha/20250129094940.2643944-1-yury.khrustalev@arm.com/

Kind regards,
Yury


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-01-29  9:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-23 14:13 [PATCH 0/4] Add tests for Guarded Control Stack Yury Khrustalev
2025-01-23 14:13 ` [PATCH 1/4] aarch64: " Yury Khrustalev
2025-01-27 20:47   ` Adhemerval Zanella Netto
2025-01-28 10:08     ` Yury Khrustalev
2025-01-28 11:49       ` Adhemerval Zanella Netto
2025-01-28 13:23         ` Yury Khrustalev
2025-01-28 14:28           ` Adhemerval Zanella Netto
2025-01-29  9:56             ` Yury Khrustalev
2025-01-23 14:13 ` [PATCH 2/4] aarch64: Add GCS tests for transitive dependencies Yury Khrustalev
2025-01-23 14:14 ` [PATCH 3/4] aarch64: Add GCS tests for dlopen Yury Khrustalev
2025-01-23 14:14 ` [PATCH 4/4] aarch64: Add GCS test with signal handler Yury Khrustalev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).