LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] Move position-independant code flags into the target specific Makefiles
@ 2026-11-13 12:01 Thomas Huth
  0 siblings, 0 replies; only message in thread
From: Thomas Huth @ 2026-11-13 12:01 UTC (permalink / raw)
  To: Andrew Jones, Paolo Bonzini, kvm
  Cc: Laurent Vivier, Claudio Imbrenda, Janosch Frank, Nico Böhr,
	Chinmay Rath, kvmarm, linuxppc-dev, kvm-riscv, linux-s390,
	Amit Machhiwal

The settings for position-independant code are currently quite a mess:
It depends on the target whether we need the flags or rather should even
disable PIC / PIE, but currently the settings are spread between the
main Makefile (-fno-pic is the default, unless CONFIG_EFI has been set)
and the target specific Makefiles.
This leads to some weird situations where we have -fno-pic in the CFLAGS,
but link with -pie in the LDFLAGS since we still want to get a relocation
table, but then again need to add a "-z notext" to the linker flags to
avoid warnings about relocation entries in the text segment.
Let's face it: Always adding -fno-pic / -no-pie in the main Makefile is
a bad idea. Move the settings to the target specific Makefiles instead
where we know what we really want, and then we can finally drop the
"-z notext" settings, too.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 Makefile            | 6 +-----
 arm/Makefile.arm    | 2 ++
 arm/Makefile.arm64  | 3 +--
 powerpc/Makefile    | 5 ++++-
 riscv/Makefile      | 1 +
 s390x/Makefile      | 3 +++
 x86/Makefile.common | 5 +++++
 7 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 8e002043..b0a0b89f 100644
--- a/Makefile
+++ b/Makefile
@@ -70,8 +70,6 @@ fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "")
 fno_stack_protector := $(call cc-option, -fno-stack-protector, "")
 fno_stack_protector_all := $(call cc-option, -fno-stack-protector-all, "")
 wno_frame_address := $(call cc-option, -Wno-frame-address, "")
-fno_pic := $(call cc-option, -fno-pic, "")
-no_pie := $(call cc-option, -no-pie, "")
 wclobbered := $(call cc-option, -Wclobbered, "")
 wunused_but_set_parameter := $(call cc-option, -Wunused-but-set-parameter, "")
 wmissing_parameter_type := $(call cc-option, -Wmissing-parameter-type, "")
@@ -85,8 +83,6 @@ COMMON_CFLAGS += $(wno_frame_address)
 COMMON_CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,)
 ifeq ($(CONFIG_EFI),y)
 COMMON_CFLAGS += $(EFI_CFLAGS)
-else
-COMMON_CFLAGS += $(fno_pic)
 endif
 COMMON_CFLAGS += $(wclobbered)
 COMMON_CFLAGS += $(wunused_but_set_parameter)
@@ -103,7 +99,7 @@ CFLAGS += $(LATE_CFLAGS)
 
 autodepend-flags = -MMD -MP -MF $(dir $*).$(notdir $*).d
 
-LDFLAGS += -nostdlib $(no_pie) -z noexecstack
+LDFLAGS += -nostdlib -z noexecstack
 
 $(libcflat): $(cflatobjs)
 	$(AR) rcs $@ $^
diff --git a/arm/Makefile.arm b/arm/Makefile.arm
index 7734e17f..7313c843 100644
--- a/arm/Makefile.arm
+++ b/arm/Makefile.arm
@@ -13,6 +13,8 @@ endif
 
 CFLAGS += $(machine)
 CFLAGS += -mno-unaligned-access
+CFLAGS += -fno-pic
+LDFLAGS += -no-pie
 
 ifeq ($(TARGET),qemu)
 arch_LDFLAGS = -Ttext=40010000
diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64
index a40c830d..ea0202eb 100644
--- a/arm/Makefile.arm64
+++ b/arm/Makefile.arm64
@@ -7,8 +7,7 @@ bits = 64
 ldarch = elf64-littleaarch64
 
 arch_LDFLAGS = -pie -n
-arch_LDFLAGS += -z notext
-CFLAGS += -mstrict-align
+CFLAGS += -fpie -mstrict-align
 
 sve_flag := $(call cc-option, -march=armv8.5-a+sve, "")
 ifneq ($(strip $(sve_flag)),)
diff --git a/powerpc/Makefile b/powerpc/Makefile
index 41e752b0..eff129b0 100644
--- a/powerpc/Makefile
+++ b/powerpc/Makefile
@@ -66,6 +66,9 @@ CFLAGS += -ffreestanding
 CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec)
 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib
 CFLAGS += -Wa,-mregnames
+CFLAGS += -fpie
+
+LDFLAGS += -pie
 
 # We want to keep intermediate files
 .PRECIOUS: %.o
@@ -78,7 +81,7 @@ include $(SRCDIR)/scripts/asm-offsets.mak
 
 FLATLIBS = $(libcflat) $(LIBFDT_archive)
 %.elf: CFLAGS += $(arch_CFLAGS)
-%.elf: LDFLAGS += $(arch_LDFLAGS) -pie -n
+%.elf: LDFLAGS += $(arch_LDFLAGS) -n
 %.elf: %.o $(FLATLIBS) $(SRCDIR)/powerpc/flat.lds $(cstart.o) $(reloc.o) %.aux.o
 	$(LD) $(LDFLAGS) -o $@ \
 		-T $(SRCDIR)/powerpc/flat.lds --build-id=none \
diff --git a/riscv/Makefile b/riscv/Makefile
index 348a30a7..79a9c1ad 100644
--- a/riscv/Makefile
+++ b/riscv/Makefile
@@ -93,6 +93,7 @@ CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
 CFLAGS += -O2
 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib -I $(SRCDIR)/riscv
+CFLAGS += -fno-pic
 
 asm-offsets = lib/riscv/asm-offsets.h riscv/sbi-asm-offsets.h
 include $(SRCDIR)/scripts/asm-offsets.mak
diff --git a/s390x/Makefile b/s390x/Makefile
index 97ed0b47..29bea5cc 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -88,7 +88,10 @@ CFLAGS += -O2
 CFLAGS += -march=zEC12
 CFLAGS += -mbackchain
 CFLAGS += -fno-delete-null-pointer-checks
+CFLAGS += -fno-pic
+
 LDFLAGS += -Wl,--build-id=none
+LDFLAGS += -no-pie
 
 # We want to keep intermediate files
 .PRECIOUS: %.o %.lds
diff --git a/x86/Makefile.common b/x86/Makefile.common
index 054e2391..a0201fcd 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -40,6 +40,11 @@ COMMON_CFLAGS += -Wa,--divide
 endif
 COMMON_CFLAGS += -O1
 
+ifneq ($(CONFIG_EFI),y)
+CFLAGS += -fno-pic
+LDFLAGS += -no-pie
+endif
+
 # stack.o relies on frame pointers.
 KEEP_FRAME_POINTER := y
 
-- 
2.56.0



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-13 12:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 12:01 [kvm-unit-tests PATCH] Move position-independant code flags into the target specific Makefiles Thomas Huth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox