zdtm: gcs: add opt-in GCS test support for AArch64

Introduce an opt-in mode for building and running ZDTM static tests
with Guarded Control Stack (GCS) enabled on AArch64.

Changes:
 - Support `GCS_ENABLE=1` builds, adding `-mbranch-protection=standard`
   and `-z experimental-gcs=check` to CFLAGS/LDFLAGS.
 - Export required GLIBC_TUNABLES at runtime via `TEST_ENV`.
 - %.pid rules to prefix test binaries with `$(TEST_ENV)`
   so the tunables are set when running tests.
 - Makefile rules for selectively enabling GCS in tests

Usage:
    # Build and run with GCS enabled
    make -C zdtm/static GCS_ENABLE=1 posix_timers
    GCS_ENABLE=1 ./zdtm.py run --keep-img=always \
        -t zdtm/static/posix_timers

By default (`GCS_ENABLE` unset or 0), test builds and runs are
unchanged.

NOTE: This assumes that the test victim was compiled also using
      GCS_ENABLE=1 so that the proper GCS AArch64 ELF headers are present

Signed-off-by: Igor Svilenkov Bozic <svilenkov@gmail.com>
Reviewed-by: Alexander Mikhalitsyn aleksandr.mikhalitsyn@canonical.com
This commit is contained in:
Igor Svilenkov Bozic 2025-11-23 17:27:49 +01:00 committed by Alexander Mikhalitsyn
parent d591e320e0
commit f78bea8d34
2 changed files with 17 additions and 9 deletions

View file

@ -79,6 +79,14 @@ define pkg-cflags
$(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" $(PKG_CONFIG) --cflags $(1))
endef
ifeq ($(GCS_ENABLE),1)
CFLAGS += -mbranch-protection=standard
LDFLAGS += -z experimental-gcs=check
TEST_ENV = GLIBC_TUNABLES=glibc.cpu.aarch64_gcs=1:glibc.cpu.aarch64_gcs_policy=2
else
TEST_ENV =
endif
%.d: %.c
$(E) " DEP " $@
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -MM -MP $< -o $@

View file

@ -520,30 +520,30 @@ install: all
.PHONY: all install
$(TST_NOFILE:%=%.pid): %.pid: %
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out
$(TEST_ENV) $(<D)/$(<F) --pidfile=$@ --outfile=$<.out
$(TST_FILE:%=%.pid): %.pid: %
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --filename=$<.test
$(TEST_ENV) $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --filename=$<.test
$(TST_DIR:%=%.pid): %.pid: %
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.test
$(TEST_ENV) $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.test
$(TST_DIR_FILE:%=%.pid): %.pid: %
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.dir.test --filename=$<.test
$(TEST_ENV) $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --dirname=$<.dir.test --filename=$<.test
cmdlinenv00.pid: cmdlinenv00
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --arg1=arg1 --arg2=arg2 --arg3=arg3
$(TEST_ENV) $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --arg1=arg1 --arg2=arg2 --arg3=arg3
shm-unaligned.pid: shm-unaligned
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --shmem_size=5000
$(TEST_ENV) $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --shmem_size=5000
shm-hugetlb.pid: shm-hugetlb
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --shmem_size=4194304
$(TEST_ENV) $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --shmem_size=4194304
env00.pid: env00
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --envname=ENV_00_TEST
$(TEST_ENV) $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --envname=ENV_00_TEST
umask00.pid: umask00
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --mask=0345
$(TEST_ENV) $(<D)/$(<F) --pidfile=$@ --outfile=$<.out --mask=0345
fifo-rowo-pair.pid: fifo-rowo-pair
$(<D)/$(<F) --pidfile=$@ --outfile=$<.out --name_master=$<.master.test --name_slave=$<.slave.test