Skip to content

Commit 1feb9b8

Browse files
committed
250813.074146.CST fortran/tests/makefiles/Makefile.common: add -Wl,-z,noexecstack to the compiler options, to test that our code does not need executable stacks
1 parent ae298b1 commit 1feb9b8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

fortran/tests/makefiles/Makefile.common

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
# empty, then we will test both an optimized version (compiled with -O3) and a debugging version
2525
# (compiled with -g -O0); otherwise, a version indicated by FFLAGS will be tested.
2626
#
27+
# 4. `-Wl,-z,noexecstack` passes the `-z noexecstack` option to the linker and tells the linker to
28+
# set the "stack is not executable" attribute in the output file. If executable stacks are actually
29+
# needed, then it will lead to a runtime error. This is to test that our code does not require executable
30+
# stacks, which is a security risk. COBYLA used to use an internal subroutine passed as an actual
31+
# argument, which necessitates an executable stack with some compilers, but such code has been
32+
# removed on 20250812. See git commit 5e5e871 and
33+
# https://fortran-lang.discourse.group/t/implementation-of-a-parametrized-objective-function-without-using-module-variables-or-internal-subroutines
2734
# Coded by Zaikun ZHANG (www.zhangzk.net).
2835
#
2936
# Started: September 2021
@@ -361,6 +368,7 @@ ifeq ($(TESTDIM),small)
361368
endif
362369
# Strangely, with `-Mchkptr`, the compiler may not print the error message of `-Mbounds` anymore.
363370
DFORT := $(AFLANG) -std=f$(FSTD) -pedantic -Weverything -Wall -Wextra -Minform=warn -Mstandard -Mbounds -Mrecursive #-Kieee #-Mchkptr
371+
DFORT := $(DFORT) -Wl,-z,noexecstack
364372

365373
dtest_i2_r4_d1_tst_c dtest_i4_r4_d1_tst_c dtest_i8_r4_d1_tst_c dtest_i2_r4_d0_tst_c dtest_i4_r4_d0_tst_c dtest_i8_r4_d0_tst_c: \
366374
FCO := $(DFORT) $(FFLAGSO)
@@ -397,6 +405,7 @@ else
397405
FFORT := $(FFORT) -fno-stack-arrays -mmlir -fdynamic-heap-array
398406
endif
399407
FFORT := $(FFORT) -std=f2018 -pedantic # As of flang 19.0, only -std=f2018 is supported
408+
FFORT := $(FFORT) -Wl,-z,noexecstack
400409

401410
ftest_i2_r4_d1_tst_c ftest_i4_r4_d1_tst_c ftest_i8_r4_d1_tst_c ftest_i2_r4_d0_tst_c ftest_i4_r4_d0_tst_c ftest_i8_r4_d0_tst_c: \
402411
FCO := $(FFORT) $(FFLAGSO)
@@ -468,6 +477,7 @@ GFORT := $(GFORT) $(GFSTD) -fall-intrinsics -frecursive \
468477
-ftrapv
469478
#-finit-real=nan -finit-integer=-9999999 # This will hide some warnings on uninitialized variables.
470479
#-Wrealloc-lhs -Wrealloc-lhs-all
480+
GFORT := $(GFORT) -Wl,-z,noexecstack
471481

472482
gtest_i2_r4_d1_tst_c gtest_i4_r4_d1_tst_c gtest_i8_r4_d1_tst_c gtest_i2_r4_d0_tst_c gtest_i4_r4_d0_tst_c gtest_i8_r4_d0_tst_c: \
473483
FCO := $(GFORT) $(FFLAGSO) -Wno-function-elimination -ffpe-trap=zero
@@ -514,6 +524,7 @@ else
514524
IFORT := $(IFORT) -auto -heap-arrays
515525
endif
516526
IFORT := $(IFORT) -standard-semantics -assume recursion -fimplicit-none
527+
IFORT := $(IFORT) -Wl,-z,noexecstack
517528

518529
itest_i2_r4_d1_tst_c itest_i4_r4_d1_tst_c itest_i8_r4_d1_tst_c itest_i2_r4_d0_tst_c itest_i4_r4_d0_tst_c itest_i8_r4_d0_tst_c: \
519530
FCO := $(IFORT) $(FFLAGSO) -fp-trap=divzero
@@ -549,6 +560,7 @@ NFORT := $(NFORT) -I $(TESTSUITE_DIR)
549560
NFORT := $(NFORT) -colour=error:red,warn:magenta,info:cyan
550561
NFORT := $(NFORT) -f$(FSTD) -recursive -info -gline -u -C -C=alias -C=dangling -C=intovf -C=undefined -kind=unique \
551562
-Warn=constant_coindexing -Warn=subnormal #-Warn=allocation
563+
NFORT := $(NFORT) -Wl,-z,noexecstack
552564

553565
ntest_i2_r4_d1_tst_c ntest_i4_r4_d1_tst_c ntest_i8_r4_d1_tst_c ntest_i2_r4_d0_tst_c ntest_i4_r4_d0_tst_c ntest_i8_r4_d0_tst_c: \
554566
FCO := $(NFORT) $(FFLAGSO) -nan -ieee=full
@@ -582,6 +594,7 @@ else
582594
VFORT := $(VFORT) -Mnostack_arrays
583595
endif
584596
VFORT := $(VFORT) -C -Wall -Wextra -Minform=warn -Mstandard -Mrecursive -Mbounds -Mchkstk -Mchkptr -traceback
597+
VFORT := $(VFORT) -Wl,-z,noexecstack
585598

586599
vtest_i2_r4_d1_tst_c vtest_i4_r4_d1_tst_c vtest_i8_r4_d1_tst_c vtest_i2_r4_d0_tst_c vtest_i4_r4_d0_tst_c vtest_i8_r4_d0_tst_c: \
587600
FCO := $(VFORT) $(FFLAGSO) #-Ktrap=divz #-Kieee
@@ -614,6 +627,7 @@ else
614627
RFORT := $(RFORT) -fno-stack-arrays
615628
endif
616629
RFORT := $(RFORT) -std=f$(FSTD) -pedantic -Weverything -Wall -Wextra -Minform=warn -Mstandard -Mrecursive -Mbounds -Mchkptr #-Kieee
630+
RFORT := $(RFORT) -Wl,-z,noexecstack
617631

618632
rtest_i2_r4_d1_tst_c rtest_i4_r4_d1_tst_c rtest_i8_r4_d1_tst_c rtest_i2_r4_d0_tst_c rtest_i4_r4_d0_tst_c rtest_i8_r4_d0_tst_c: \
619633
FCO := $(RFORT) $(FFLAGSO)
@@ -643,6 +657,7 @@ ifeq ($(TESTDIM),small)
643657
SFORT := $(SFORT) -stackvar # Force all automatic arrays to be on the stack to test whether stack overflow can occur
644658
endif
645659
SFORT := $(SFORT) -w3 -u -U -ansi -xcheck=%all -C
660+
SFORT := $(SFORT) -Wl,-z,noexecstack
646661

647662
stest_i2_r4_d1_tst_c stest_i4_r4_d1_tst_c stest_i8_r4_d1_tst_c stest_i2_r4_d0_tst_c stest_i4_r4_d0_tst_c stest_i8_r4_d0_tst_c: \
648663
FCO := $(SFORT) $(FFLAGSO) -fnonstd -ftrap=division
@@ -682,6 +697,7 @@ else
682697
XFORT := $(XFORT) -auto -heap-arrays
683698
endif
684699
XFORT := $(XFORT) -standard-semantics -assume recursion -fimplicit-none
700+
XFORT := $(XFORT) -Wl,-z,noexecstack
685701

686702
# In the following, `-check all,nouninit` can be changed to `-check all` later, probably with OneAPI 2024.1. See
687703
# https://community.intel.com/t5/Intel-Fortran-Compiler/ifx-missing-clang-rt-msan-to-link-Fortran-program-in-debug-build/m-p/1533430
@@ -723,6 +739,7 @@ xtest_i2_r16_d1_tst_c xtest_i4_r16_d1_tst_c xtest_i8_r16_d1_tst_c xtest_i2_r16_d
723739
-Werror=100,113,115,137,146,147,159,163 \
724740
-Wimplicit-none -Wline-truncation -Wprecision-loss -Wunused-module-vars -Wunused-vars -Wunset-vars \
725741
-fimplicit-none -fbounds-check -ftrace=full -freal=nan -fmodule-private
742+
9FORT := $(9FORT) -Wl,-z,noexecstack
726743

727744
9test_i2_r4_d1_tst_c 9test_i4_r4_d1_tst_c 9test_i8_r4_d1_tst_c 9test_i2_r4_d0_tst_c 9test_i4_r4_d0_tst_c 9test_i8_r4_d0_tst_c: \
728745
FCO := $(9FORT) $(FFLAGSO)

0 commit comments

Comments
 (0)