From: Thomas Huth <thuth@redhat.com>
To: kvm@vger.kernel.org, "Paolo Bonzini" <pbonzini@redhat.com>,
"Nico Böhr" <nrb@linux.ibm.com>,
"Claudio Imbrenda" <imbrenda@linux.ibm.com>,
"Janosch Frank" <frankja@linux.ibm.com>,
"Andrew Jones" <andrew.jones@linux.dev>
Cc: kvmarm@lists.linux.dev, linux-s390@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org,
Laurent Vivier <lvivier@redhat.com>,
David Hildenbrand <david@redhat.com>
Subject: [kvm-unit-tests PATCH 1/2] Rework the common LDFLAGS to become more useful again
Date: Fri, 23 Jun 2023 14:54:15 +0200 [thread overview]
Message-ID: <20230623125416.481755-2-thuth@redhat.com> (raw)
In-Reply-To: <20230623125416.481755-1-thuth@redhat.com>
Currently the LDFLAGS settings from the main Makefile are ignored in
most architecture specific directories (except s390x), which is very
confusing when you try to add a linker switch for all architectures.
Let's change this so that all architectures extend the common LDFLAGS
instead of replacing them. So it is sufficient now to specify the
"-nostdlib" switch in the main Makefile now instead of repeating it
everywhere.
While we're at it, avoid to repeat the whole set of CFLAGS in the
common LDFLAGS - the options that are meant for the C compiler should
not be exposed unconditionally to the linker.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
Makefile | 2 +-
arm/Makefile.common | 2 +-
powerpc/Makefile.common | 2 +-
s390x/Makefile | 2 +-
x86/Makefile.common | 4 ++--
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
index 6ed5deac..0e5d85a1 100644
--- a/Makefile
+++ b/Makefile
@@ -96,7 +96,7 @@ CFLAGS += -Woverride-init -Wmissing-prototypes -Wstrict-prototypes
autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d
-LDFLAGS += $(CFLAGS)
+LDFLAGS += -nostdlib
$(libcflat): $(cflatobjs)
$(AR) rcs $@ $^
diff --git a/arm/Makefile.common b/arm/Makefile.common
index 1bbec64f..e2cb1a56 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -60,7 +60,7 @@ libeabi = lib/arm/libeabi.a
eabiobjs = lib/arm/eabi_compat.o
FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libeabi)
-%.elf: LDFLAGS = -nostdlib $(arch_LDFLAGS)
+%.elf: LDFLAGS += $(arch_LDFLAGS)
%.elf: %.o $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o)
$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c \
-DPROGNAME=\"$(@:.elf=.flat)\" -DAUXFLAGS=$(AUXFLAGS)
diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common
index 8ce00340..f8f47490 100644
--- a/powerpc/Makefile.common
+++ b/powerpc/Makefile.common
@@ -49,7 +49,7 @@ OBJDIRS += lib/powerpc
FLATLIBS = $(libcflat) $(LIBFDT_archive)
%.elf: CFLAGS += $(arch_CFLAGS)
-%.elf: LDFLAGS = $(arch_LDFLAGS) -nostdlib -pie -n
+%.elf: LDFLAGS += $(arch_LDFLAGS) -pie -n
%.elf: %.o $(FLATLIBS) $(SRCDIR)/powerpc/flat.lds $(cstart.o) $(reloc.o)
$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c \
-DPROGNAME=\"$@\"
diff --git a/s390x/Makefile b/s390x/Makefile
index a80db538..d75e86c2 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -76,7 +76,7 @@ CFLAGS += -O2
CFLAGS += -march=zEC12
CFLAGS += -mbackchain
CFLAGS += -fno-delete-null-pointer-checks
-LDFLAGS += -nostdlib -Wl,--build-id=none
+LDFLAGS += -Wl,--build-id=none
# We want to keep intermediate files
.PRECIOUS: %.o %.lds
diff --git a/x86/Makefile.common b/x86/Makefile.common
index 365e199f..e64aac52 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -31,7 +31,7 @@ endif
OBJDIRS += lib/x86
-$(libcflat): LDFLAGS += -nostdlib $(arch_LDFLAGS)
+$(libcflat): LDFLAGS += $(arch_LDFLAGS)
$(libcflat): CFLAGS += -ffreestanding -I $(SRCDIR)/lib -I lib
COMMON_CFLAGS += -m$(bits)
@@ -62,7 +62,7 @@ else
# We want to keep intermediate file: %.elf and %.o
.PRECIOUS: %.elf %.o
-%.elf: LDFLAGS = -nostdlib $(arch_LDFLAGS)
+%.elf: LDFLAGS += $(arch_LDFLAGS)
%.elf: %.o $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o)
$(LD) $(LDFLAGS) -T $(SRCDIR)/x86/flat.lds -o $@ \
$(filter %.o, $^) $(FLATLIBS)
--
2.39.3
next prev parent reply other threads:[~2023-06-23 12:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-23 12:54 [kvm-unit-tests PATCH 0/2] Rework LDFLAGS and link with noexecstack Thomas Huth
2023-06-23 12:54 ` Thomas Huth [this message]
2023-06-23 12:54 ` [kvm-unit-tests PATCH 2/2] Link with "-z noexecstack" to avoid warning from newer versions of ld Thomas Huth
2023-06-23 14:24 ` Sean Christopherson
2023-06-23 16:03 ` Thomas Huth
2023-06-26 22:34 ` Sean Christopherson
2023-08-14 10:15 ` Thomas Huth
2023-06-23 14:46 ` [kvm-unit-tests PATCH 0/2] Rework LDFLAGS and link with noexecstack Andrew Jones
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=20230623125416.481755-2-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=andrew.jones@linux.dev \
--cc=david@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--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 \
/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;
as well as URLs for NNTP newsgroup(s).