kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bill Wendling <morbo@google.com>
To: kvm@vger.kernel.org, pbonzini@redhat.com
Cc: jmattson@google.com, Bill Wendling <morbo@google.com>
Subject: [kvm-unit-tests PATCH] Makefile: do not use "libgcc" for clang
Date: Mon,  8 Mar 2021 20:52:50 -0800	[thread overview]
Message-ID: <20210309045250.3333311-1-morbo@google.com> (raw)

The -nostdlib flag disables the driver from adding libclang_rt.*.a
during linking. Adding a specific library to the command line then
causes the linker to report unresolved symbols, because the libraries
that resolve those symbols aren't automatically added. Turns out clang
doesn't need to specify that library.

Signed-off-by: Bill Wendling <morbo@google.com>
---
 Makefile            | 6 ++++++
 arm/Makefile.common | 2 ++
 x86/Makefile.common | 2 ++
 3 files changed, 10 insertions(+)

diff --git a/Makefile b/Makefile
index e0828fe..61a1276 100644
--- a/Makefile
+++ b/Makefile
@@ -22,10 +22,16 @@ DESTDIR := $(PREFIX)/share/kvm-unit-tests/
 cc-option = $(shell if $(CC) -Werror $(1) -S -o /dev/null -xc /dev/null \
               > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 
+# cc-name
+# Expands to either gcc or clang
+cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
+
 #make sure env CFLAGS variable is not used
 CFLAGS =
 
+ifneq ($(cc-name),clang)
 libgcc := $(shell $(CC) --print-libgcc-file-name)
+endif
 
 libcflat := lib/libcflat.a
 cflatobjs := \
diff --git a/arm/Makefile.common b/arm/Makefile.common
index a123e85..94922aa 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -58,7 +58,9 @@ OBJDIRS += lib/arm
 libeabi = lib/arm/libeabi.a
 eabiobjs = lib/arm/eabi_compat.o
 
+ifneq ($(cc-name),clang)
 libgcc := $(shell $(CC) $(machine) --print-libgcc-file-name)
+endif
 
 FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libgcc) $(libeabi)
 %.elf: LDFLAGS = -nostdlib $(arch_LDFLAGS)
diff --git a/x86/Makefile.common b/x86/Makefile.common
index 55f7f28..a96b236 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -37,7 +37,9 @@ COMMON_CFLAGS += -O1
 # stack.o relies on frame pointers.
 KEEP_FRAME_POINTER := y
 
+ifneq ($(cc-name),clang)
 libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
+endif
 
 # We want to keep intermediate file: %.elf and %.o 
 .PRECIOUS: %.elf %.o
-- 
2.30.1.766.gb4fecdf3b7-goog


             reply	other threads:[~2021-03-09  4:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-09  4:52 Bill Wendling [this message]
2021-04-27 21:15 ` [kvm-unit-tests PATCH] Makefile: do not use "libgcc" for clang Bill Wendling
2021-05-04 17:07 ` Jim Mattson
2021-05-05 12:31 ` Paolo Bonzini

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=20210309045250.3333311-1-morbo@google.com \
    --to=morbo@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --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).