public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
From: Yang Yujie <yangyujie@loongson.cn>
To: jit@gcc.gnu.org
Subject: [PATCH] libgccjit: allow common objects in $(EXTRA_GCC_OBJS) and $(EXTRA_OBJS)
Date: Wed, 27 Apr 2022 09:27:28 +0800	[thread overview]
Message-ID: <97c2395c-d25e-734d-cb74-0db8497f4777@loongson.cn> (raw)
In-Reply-To: <d0d9c114-c9b5-48e7-5239-18e14918d468@loongson.cn>

[-- Attachment #1: Type: text/plain, Size: 696 bytes --]

Hello,

This patch fixes libgccjit link failure on loongarch* targets,
and could probably be useful for future ports.

Currently libgccjit is linked with objects from $(EXTRA_GCC_OBJS) and
libbackend.a, which is in turn linked with $(EXTRA_OBJS) files.
Thus, common object files that's shared between those two $(EXTRA_*)
lists would cause the linker to abort for "redefined symbol"s.

For now, this patch doesn't affect any target other than LoongArch,
but might be useful for future ports that want to share more object
files between the compiler proper and the GCC driver than
${cpu_arch}-common.o.

Regression tested on loongarch64-linux-gnuf64 an x86_64-pc-linux-gnu, 
please review.

Yujie

[-- Attachment #2: 0001-libgccjit-allow-common-objects-in-EXTRA_GCC_OBJS-and.patch --]
[-- Type: text/x-patch, Size: 2103 bytes --]

From 5d9121fa052c556fd854596af35da8e5649e8f08 Mon Sep 17 00:00:00 2001
From: Yang Yujie <yangyujie@loongson.cn>
Date: Fri, 22 Apr 2022 14:36:37 +0800
Subject: [PATCH] libgccjit: allow common objects in $(EXTRA_GCC_OBJS) and
 $(EXTRA_OBJS)

The final link of libgccjit involves libbackend.a and
$(EXTRA_GCC_OBJS) as input, where libbackend.a contains object files
from the $(EXTRA_OBJS) list.

This assumes that no target-specific object file should be shared
between those two lists (or the linker would complain about redefined
symbols and abort).

With this patch, libgccjit can built properly for LoongArch
and other architectures that shares target-specific objects between
gcc and cc1 etc.

* gcc/jit/ChangeLog:

	* Make-lang.in: only link objects from $(EXTRA_GCC_OBJS)
	that's not in $(EXTRA_OBJS) into libgccjit.
---
 gcc/jit/Make-lang.in | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/gcc/jit/Make-lang.in b/gcc/jit/Make-lang.in
index 6e10abfd0ac..248ec45b729 100644
--- a/gcc/jit/Make-lang.in
+++ b/gcc/jit/Make-lang.in
@@ -157,18 +157,23 @@ LIBGCCJIT_EXTRA_OPTS = $(LIBGCCJIT_VERSION_SCRIPT_OPTION) \
 endif
 endif
 
+# Only link objects from $(EXTRA_GCC_OBJS) that's not already
+# included in libbackend.a ($(EXTRA_OBJS)).
+EXTRA_GCC_OBJS_EXCLUSIVE = $(foreach _obj1, $(EXTRA_GCC_OBJS), \
+	$(if $(filter $(_obj1), $(EXTRA_OBJS)),, $(_obj1)))
+
 # We avoid using $(BACKEND) from Makefile.in in order to avoid pulling
 # in main.o
 $(LIBGCCJIT_FILENAME): $(jit_OBJS) \
 	libbackend.a libcommon-target.a libcommon.a \
 	$(CPPLIB) $(LIBDECNUMBER) \
 	$(LIBDEPS) $(srcdir)/jit/libgccjit.map \
-	$(EXTRA_GCC_OBJS) $(jit.prev)
+	$(EXTRA_GCC_OBJS_EXCLUSIVE) $(jit.prev)
 	@$(call LINK_PROGRESS,$(INDEX.jit),start)
 	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ -shared \
 	     $(jit_OBJS) libbackend.a libcommon-target.a libcommon.a \
 	     $(CPPLIB) $(LIBDECNUMBER) $(EXTRA_GCC_LIBS) $(LIBS) $(BACKENDLIBS) \
-	     $(EXTRA_GCC_OBJS) \
+	     $(EXTRA_GCC_OBJS_EXCLUSIVE) \
 	     $(LIBGCCJIT_EXTRA_OPTS)
 	@$(call LINK_PROGRESS,$(INDEX.jit),end)
 
-- 
2.31.1



           reply	other threads:[~2022-04-27  1:27 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <d0d9c114-c9b5-48e7-5239-18e14918d468@loongson.cn>]

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=97c2395c-d25e-734d-cb74-0db8497f4777@loongson.cn \
    --to=yangyujie@loongson.cn \
    --cc=jit@gcc.gnu.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).