]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[build] Use separate code segment if supported by linker
authorMichael Brown <mcb30@ipxe.org>
Fri, 30 Jun 2023 11:03:41 +0000 (12:03 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 3 Jul 2023 12:31:31 +0000 (13:31 +0100)
Some versions of ld will complain that the automatically created (and
unused by our build process) ELF program headers include a "LOAD
segment with RWX permissions".

Silence this warning by adding "-z separate-code" to the linker
options, where supported.

For BIOS builds, where the prefix will generally require writable
access to its own (tiny) code segment, simply inhibit the warning
completely via "--no-warn-rwx-segments".

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/Makefile.housekeeping
src/arch/x86/Makefile.pcbios

index b32003ea51e054e695050452a66273487a9cded3..4a90b3ca4ade5489e03a6102ddb0dca43a5e31a6 100644 (file)
@@ -502,6 +502,13 @@ LDFLAGS            += --gc-sections
 #
 LDFLAGS                += -static
 
+# Use separate code segment if supported by linker
+#
+ZSC_TEST       = $(LD) -z separate-code --version 2>&1 > /dev/null
+ZSC_FLAGS      := $(shell [ -z "`$(ZSC_TEST)`" ] && \
+                    $(ECHO) '-z separate-code -z max-page-size=4096')
+LDFLAGS                += $(ZSC_FLAGS)
+
 # compiler.h is needed for our linking and debugging system
 #
 CFLAGS         += -include include/compiler.h
index b9f8e6c2895b02eb8836b1c7ac6a69b9916382fc..38dfa087ce348349f3421b254440b2c14afbba80 100644 (file)
@@ -13,6 +13,13 @@ LDSCRIPT_PREFIX      = arch/x86/scripts/prefixonly.lds
 #
 LDFLAGS                += -N --no-check-sections
 
+# Do not warn about RWX segments (required by most prefixes)
+#
+WRWX_TEST      = $(LD) --warn-rwx-segments --version 2>&1 > /dev/null
+WRWX_FLAGS     := $(shell [ -z "`$(WRWX_TEST)`" ] && \
+                    $(ECHO) '--no-warn-rwx-segments')
+LDFLAGS                += $(WRWX_FLAGS)
+
 # Media types.
 #
 MEDIA          += rom