[m-rev.] for review: fix GNU ld warning about executable stack
Peter Wang
novalazy at gmail.com
Fri Apr 4 11:47:54 AEDT 2025
The first change is for our fork of bdwgc.
The second change is in the mercury repository.
-------------------
Add var to control inclusion of atomic_ops_sysdeps.o
Makefile.direct:
Only include atomic_ops_sysdeps.o in OBJS if enabled
by a variable BOEHM_NEED_ATOMIC_OPS_ASM.
diff --git a/Makefile.direct b/Makefile.direct
index 40c768c3..3ea4ee49 100644
--- a/Makefile.direct
+++ b/Makefile.direct
@@ -144,7 +144,18 @@ OBJS= alloc.o reclaim.o allchblk.o misc.o mach_dep.o os_dep.o mark_rts.o \
malloc.o checksums.o pthread_support.o pthread_stop_world.o \
darwin_stop_world.o typd_mlc.o ptr_chck.o mallocx.o gcj_mlc.o specific.o \
gc_dlopen.o backgraph.o win32_threads.o pthread_start.o \
- thread_local_alloc.o fnlz_mlc.o atomic_ops.o atomic_ops_sysdeps.o
+ thread_local_alloc.o fnlz_mlc.o atomic_ops.o
+
+# Mercury-specific: atomic_ops_sysdeps.o will be empty (devoid of sections)
+# except when targeting Solaris/SPARC with a compiler other than GCC.
+# If the empty object file is linked in, GNU ld will treat the executable or
+# shared library as requiring an executable stack, and newer versions of GNU ld
+# will warn that "missing .note.GNU-stack section implies executable stack".
+# Therefore, we allow atomic_ops_sysdeps.o to be omitted from OBJS
+# when not required, which is usually the case.
+ifeq ($(BOEHM_NEED_ATOMIC_OPS_ASM),yes)
+OBJS+= atomic_ops_sysdeps.o
+endif
CSRCS= reclaim.c allchblk.c misc.c alloc.c mach_dep.c os_dep.c mark_rts.c \
headers.c mark.c obj_map.c blacklst.c finalize.c \
-------------------
Prevent executable stack warning while building Boehm GC.
The file boehm_gc/atomic_ops_sysdeps.o is built from an assembly file,
and will be empty (devoid of sections) except when targeting
Solaris/SPARC with a compiler other than GCC. If the empty object file
is linked in, GNU ld will treat the executable or shared library as
requiring an executable stack, and newer versions of GNU ld will
warn that "missing .note.GNU-stack section implies executable stack".
Mmake.common.in:
Introduce a variable BOEHM_NEED_ATOMIC_OPS_ASM,
to be consulted by boehm_gc/Makefile.direct.
configure.ac:
Set BOEHM_NEED_ATOMIC_OPS_ASM=yes only when building for
Solaris/SPARC with a compiler other than GCC.
diff --git a/Mmake.common.in b/Mmake.common.in
index 151b307ab..e697f921c 100644
--- a/Mmake.common.in
+++ b/Mmake.common.in
@@ -2,7 +2,7 @@
# vim: ts=8 sw=8 noexpandtab ft=make
#-----------------------------------------------------------------------------#
# Copyright (C) 1995-2006, 2009-2012 The University of Melbourne.
-# Copyright (C) 2013-2014, 2016-2017, 2019-2020, 2022-2024 The Mercury team.
+# Copyright (C) 2013-2014, 2016-2017, 2019-2020, 2022-2025 The Mercury team.
# This file may only be copied under the terms of the GNU General
# Public Licence - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
@@ -185,6 +185,9 @@ BOEHM_CFLAGS_FOR_THREADS = @BOEHM_CFLAGS_FOR_THREADS@ \
@ENABLE_BOEHM_THREAD_LOCAL_ALLOC@ \
@ENABLE_BOEHM_PARALLEL_MARK@
+# Whether Boehm-GC needs object files built from libatomic_ops .S files.
+BOEHM_NEED_ATOMIC_OPS_ASM = @BOEHM_NEED_ATOMIC_OPS_ASM@
+
# The CPU type to pass via the "cpu" argument of boehm_gc/NT_MAKEFILE.
# (This is only relevant when using MSVC.)
BOEHM_WINDOWS_CPU_TYPE = @BOEHM_WINDOWS_CPU_TYPE@
diff --git a/configure.ac b/configure.ac
index f8469a441..be3094824 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# vim: ts=4 sw=4 expandtab
#-----------------------------------------------------------------------------#
# Copyright (C) 1995-2012 The University of Melbourne.
-# Copyright (C) 2013-2024 The Mercury team.
+# Copyright (C) 2013-2025 The Mercury team.
# This file may only be copied under the terms of the GNU General
# Public Licence - see the file COPYING in the Mercury distribution.
#-----------------------------------------------------------------------------#
@@ -2977,6 +2977,8 @@ ENABLE_BOEHM_PARALLEL_MARK=
#
BOEHM_CFLAGS_FOR_THREADS="-DGC_THREADS"
+BOEHM_NEED_ATOMIC_OPS_ASM=no
+
# This should be set if both the system malloc and Boehm GC (in the default
# configuration) may both call sbrk.
avoid_sbrk=
@@ -2987,6 +2989,13 @@ case "$host" in
THREAD_LIBS="-lpthread -lrt -ldl"
ENABLE_BOEHM_THREAD_LOCAL_ALLOC="-DTHREAD_LOCAL_ALLOC"
ENABLE_BOEHM_PARALLEL_MARK="-DPARALLEL_MARK"
+ case "$host" in
+ sparc*)
+ if test "$mercury_cv_cc_type" != gcc; then
+ BOEHM_NEED_ATOMIC_OPS_ASM=yes
+ fi
+ ;;
+ esac
;;
*linux*)
@@ -3136,6 +3145,7 @@ AC_SUBST(LD_LIBFLAGS_FOR_THREADS)
AC_SUBST(ENABLE_BOEHM_THREAD_LOCAL_ALLOC)
AC_SUBST(ENABLE_BOEHM_PARALLEL_MARK)
AC_SUBST(BOEHM_CFLAGS_FOR_THREADS)
+AC_SUBST(BOEHM_NEED_ATOMIC_OPS_ASM)
save_LIBS="$LIBS"
LIBS="$THREAD_LIBS"
More information about the reviews
mailing list