From: Thomas Huth <thuth@redhat.com>
To: Andrew Jones <andrew.jones@linux.dev>,
Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org
Cc: "Laurent Vivier" <lvivier@redhat.com>,
"Claudio Imbrenda" <imbrenda@linux.ibm.com>,
"Janosch Frank" <frankja@linux.ibm.com>,
"Nico Böhr" <nrb@linux.ibm.com>,
"Chinmay Rath" <rathc@linux.ibm.com>,
kvmarm@lists.linux.dev, linuxppc-dev@lists.ozlabs.org,
kvm-riscv@lists.infradead.org, linux-s390@vger.kernel.org,
"Amit Machhiwal" <amachhiw@linux.ibm.com>
Subject: [kvm-unit-tests PATCH] Move position-independant code flags into the target specific Makefiles
Date: Fri, 13 Nov 2026 13:01:01 +0100 [thread overview]
Message-ID: <20261113120101.145183-1-thuth@redhat.com> (raw)
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
reply other threads:[~2026-11-13 12:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261113120101.145183-1-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=amachhiw@linux.ibm.com \
--cc=andrew.jones@linux.dev \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-s390@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=lvivier@redhat.com \
--cc=nrb@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=rathc@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox