Index: kernel/meson.build
===================================================================
--- kernel/meson.build	(revision 4dbcdf32e0c1a607a6dbbccd4b6d203714340894)
+++ kernel/meson.build	(revision 068dd86441c1b48ecb3ea38e369c81ba75496a5c)
@@ -87,9 +87,9 @@
 kernel_link_args = arch_kernel_link_args + [
 	'-Wl,--nmagic',
-	# The kernel is built as ELF but then copied as a blob of bytes and
-	# the permissions are not relevant anyway (needed for binutils 2.39+).
-	'-Wl,--no-warn-rwx-segments',
 	'-T', meson.current_build_dir() / '_link.ld',
 ]
+# The kernel is built as ELF but then copied as a blob of bytes and
+# the permissions are not relevant anyway (needed for binutils 2.39+).
+kernel_link_args += ldflags_ignore_rwx_segments
 
 if CONFIG_LTO
@@ -104,14 +104,17 @@
 kernel_c_args = arch_kernel_c_args + kernel_defs + [
 	'-ffreestanding',
-	# When accessing specific memory addresses that are below normal page size,
-	# the compiler may assume that we actually dereferenced NULL pointer and
-	# warns us about that. But in kernel we often need to access these
-	# addresses directly hence we need to ignore these warnings.
-	#
-	# TODO: might make more sense to disable this selectively in specific
-	# files (or better yet, for specific lines).
-	'--param=min-pagesize=0',
-	# TODO: remove this flag
-	cc.get_supported_arguments([ '-Wno-cast-function-type' ]),
+	cc.get_supported_arguments([
+		# TODO: remove this flag
+		'-Wno-cast-function-type',
+		# When accessing specific memory addresses that are below normal page
+		# size, the compiler may assume that we actually dereferenced NULL
+		# pointer and warns us about that. But in kernel we often need to
+		# access these addresses directly hence we need to ignore these
+		# warnings.
+		#
+		# TODO: might make more sense to disable this selectively in specific
+		# files (or better yet, for specific lines).
+		'--param=min-pagesize=0',
+	]),
 ]
 
Index: meson/arch/arm64/meson.build
===================================================================
--- meson/arch/arm64/meson.build	(revision 4dbcdf32e0c1a607a6dbbccd4b6d203714340894)
+++ meson/arch/arm64/meson.build	(revision 068dd86441c1b48ecb3ea38e369c81ba75496a5c)
@@ -44,6 +44,5 @@
 # -mstrict-align option is therefore not needed.
 arch_boot_c_args = arch_uspace_c_args + [ '-fpic', '-fvisibility=hidden', '-fno-function-sections' ]
-arch_boot_link_args = [ '-Wl,-shared', '-Wl,--no-gc-sections' ]
-arch_boot_link_args += ['-Wl,--no-warn-rwx-segments']
+arch_boot_link_args = [ '-Wl,-shared', '-Wl,--no-gc-sections' ] + ldflags_ignore_rwx_segments
 
 if MACHINE == 'virt'
Index: meson/arch/ia64/meson.build
===================================================================
--- meson/arch/ia64/meson.build	(revision 4dbcdf32e0c1a607a6dbbccd4b6d203714340894)
+++ meson/arch/ia64/meson.build	(revision 068dd86441c1b48ecb3ea38e369c81ba75496a5c)
@@ -38,5 +38,5 @@
 arch_uspace_link_args = [ '-nostdlib', '-lgcc' ]
 arch_kernel_link_args = [ '-nostdlib', '-Wl,-EL' ]
-arch_boot_link_args = ['-Wl,--no-warn-rwx-segments']
+arch_boot_link_args = ldflags_ignore_rwx_segments
 
 
Index: meson/arch/ppc32/meson.build
===================================================================
--- meson/arch/ppc32/meson.build	(revision 4dbcdf32e0c1a607a6dbbccd4b6d203714340894)
+++ meson/arch/ppc32/meson.build	(revision 068dd86441c1b48ecb3ea38e369c81ba75496a5c)
@@ -37,6 +37,6 @@
 arch_kernel_link_args = [ '-nostdlib', '-Wl,-z,max-page-size=0x1000', '-Wl,--no-check-sections', '-Wl,--no-gc-sections' ]
 arch_uspace_link_args = [ '-nostdlib', '-lgcc', '-Wl,-z,max-page-size=0x1000' ]
-arch_uspace_link_args += ['-Wl,--no-warn-rwx-segments']
-arch_boot_link_args = ['-Wl,--no-warn-rwx-segments']
+arch_uspace_link_args += ldflags_ignore_rwx_segments
+arch_boot_link_args = ldflags_ignore_rwx_segments
 
 
Index: meson/arch/riscv64/meson.build
===================================================================
--- meson/arch/riscv64/meson.build	(revision 4dbcdf32e0c1a607a6dbbccd4b6d203714340894)
+++ meson/arch/riscv64/meson.build	(revision 068dd86441c1b48ecb3ea38e369c81ba75496a5c)
@@ -33,5 +33,5 @@
 arch_kernel_link_args = [ '-nostdlib' ]
 arch_uspace_link_args = [ '-nostdlib', '-lgcc' ]
-arch_boot_link_args = ['-Wl,--no-warn-rwx-segments']
+arch_boot_link_args = ldflags_ignore_rwx_segments
 
 rd_essential += [
Index: meson/part/compiler_args/meson.build
===================================================================
--- meson/part/compiler_args/meson.build	(revision 4dbcdf32e0c1a607a6dbbccd4b6d203714340894)
+++ meson/part/compiler_args/meson.build	(revision 068dd86441c1b48ecb3ea38e369c81ba75496a5c)
@@ -129,2 +129,15 @@
 	add_project_link_arguments(extra_cflags, language : [ lang ])
 endforeach
+
+# This flag is needed at several places, hence we define it here.
+#
+# For backwards compatibility we try to detect --no-warn-rwx-segments.
+# However, the autodetection done by Meson also results in
+# "cannot find entry symbol _start; defaulting to 00000000004000b0"
+# thus the option is never supported alone. So when detecting we also
+# specify --entry=main so that the stub source provided by Meson is build
+# correctly.
+ldflags_ignore_rwx_segments = []
+if cc.has_link_argument('-Wl,--no-warn-rwx-segments,--entry=main')
+    ldflags_ignore_rwx_segments += ['-Wl,--no-warn-rwx-segments']
+endif
