Merge "fix(build): resolve build issue for older toolchains"
diff --git a/Makefile b/Makefile
index e4b9066..0bcd3e3 100644
--- a/Makefile
+++ b/Makefile
@@ -229,10 +229,6 @@
 
 COMMON_LDFLAGS		+=	--fatal-warnings -O1 --gc-sections --build-id=none
 
-# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
-# are not loaded by a elf loader.
-COMMON_LDFLAGS		+=	--no-warn-rwx-segments
-
 CC			:=	${CROSS_COMPILE}gcc
 CPP			:=	${CROSS_COMPILE}cpp
 AS			:=	${CROSS_COMPILE}gcc
@@ -243,6 +239,10 @@
 NM			:=	${CROSS_COMPILE}nm
 PP			:=	${CROSS_COMPILE}gcc
 
+# With ld.bfd version 2.39 and newer new warnings are added. Skip those since we
+# are not loaded by a elf loader.
+COMMON_LDFLAGS		+=	$(call ld_option, --no-warn-rwx-segments)
+
 ################################################################################
 
 TFTF_SOURCES		:= ${FRAMEWORK_SOURCES}	${TESTS_SOURCES} ${PLAT_SOURCES} ${LIBC_SRCS} ${LIBFDT_SRCS}
diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk
index 0ac1505..80f8649 100644
--- a/make_helpers/build_macros.mk
+++ b/make_helpers/build_macros.mk
@@ -28,3 +28,9 @@
   $(call CREATE_SEQ,$(1),$(2))\
 )
 endef
+
+# Convenience function to check for a given linker option. An call to
+# $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker
+define ld_option
+	$(shell if $(LD) $(1) -v >/dev/null 2>&1; then echo $(1); fi )
+endef