public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
To: Iain Buclaw <ibuclaw@gdcproject.org>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] d: Move DSO registry support code from compiler to drtstuff in library (PR100062)
Date: Mon, 11 Jul 2022 10:58:39 +0200	[thread overview]
Message-ID: <yddsfn89gao.fsf@CeBiTec.Uni-Bielefeld.DE> (raw)
In-Reply-To: <20220708130729.3690093-1-ibuclaw@gdcproject.org> (Iain Buclaw's message of "Fri, 8 Jul 2022 15:07:29 +0200")

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

Hi Iain,

> Currently the DSO support for D runtime is generated by the compiler in
> every object, when really it is only required once per shared object.
>
> This patch moves that support logic from the compiler itself to the
> library as part of the drtstuff code.  The object files drtbegin.o and
> drtend.o are now always linked in.
>
> Bootstrapped and tested on x86_64-linux-gnu/-m32/-mx32, with no
> observable regressions.
>
> @Rainer, as you provided the original, would be good to validate this is
> fine for Solaris too.

I did, with mixed success: initially, the patch broke bootstrap on both
i386-pc-solaris2.11 and sparc-sun-solaris2.11 linking libgdruntime.so:

Text relocation remains                        referenced
    against symbol                  offset      in file
__start_minfo                       0x2         gcc/drtbegin.o
_D8drtstuff7dsoSlotPv               0x7         gcc/drtbegin.o
_D8drtstuff7dsoDataS3gcc8sections6common15CompilerDSOData 0x1e          gcc/drtbegin.o
_D8drtstuff7dsoDataS3gcc8sections6common15CompilerDSOData 0x28          gcc/drtbegin.o
__stop_minfo                        0x2c        gcc/drtbegin.o
_D8drtstuff7dsoDataS3gcc8sections6common15CompilerDSOData 0x34          gcc/drtbegin.o
_D8drtstuff7dsoDataS3gcc8sections6common15CompilerDSOData 0x39          gcc/drtbegin.o
_D8drtstuff7dsoDataS3gcc8sections6common15CompilerDSOData 0x7           gcc/drtbegin.o
_d_dso_registry                     0x3e        gcc/drtbegin.o
_d_dso_registry                     0xc         gcc/drtbegin.o
ld: fatal: relocations remain against allocatable but non-writable sections
collect2: error: ld returned 1 exit status
make[5]: *** [Makefile:1943: libgdruntime.la] Error 1

Solaris ld defaults to -z text, and gcc is still non-pic/pie by
default.  The attached patch fixes the issue by building
drtbegin.o/drtend.o as libtool objects.

There are a couple of caveats, though:

* It directs gdc to libdruntime/gcc/.libs instead of libdruntime/gcc.
  I've no idea what happens when configuring with --disable-shared,
  building for targets without PIC support, or on Windows where that
  directory is called _libs instead (I've found no variable to use
  here).

  OTOH, testsuite_flags.in already hardcodes .libs, so this is a
  preexisting problem.

* I haven't checked if the PIC drt*.o files are actually installed,
  otherwise gdc wouldn't be able to create shared objects on Solaris.

* This comment is misleading now that those files are used unconditionally:

# Provide __start_minfo, __stop_minfo if linker doesn't.
DRTSTUFF = gcc/drtbegin.o gcc/drtend.o

At least with this incremental patch, I've been able to successfully
bootstrap and test trunk on i386-pc-solaris2.11 (Solaris 11.3 which
lacks ld support for __start_<section>/__stop_<section) and 11.4 which
has it) and sparc-sun-solaris2.11 (Solaris 11.4 only).

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dsoreg-pic.patch --]
[-- Type: text/x-patch, Size: 2743 bytes --]

diff -rup dist/libphobos/libdruntime/Makefile.am local/libphobos/libdruntime/Makefile.am
--- dist/libphobos/libdruntime/Makefile.am	2022-07-11 09:40:43.798158000 +0200
+++ local/libphobos/libdruntime/Makefile.am	2022-07-10 22:04:18.941416000 +0200
@@ -104,16 +104,16 @@ if DRUNTIME_CPU_S390
 endif
 
 # Provide __start_minfo, __stop_minfo if linker doesn't.
-DRTSTUFF = gcc/drtbegin.o gcc/drtend.o
+DRTSTUFF = gcc/drtbegin.lo gcc/drtend.lo
 
 toolexeclib_DATA = $(DRTSTUFF)
 
-gcc/drtbegin.o: gcc/drtstuff.d
-	$(GDC) -fno-druntime -fversion=DRT_BEGIN $(GDCFLAGS) $(MULTIFLAGS) \
+gcc/drtbegin.lo: gcc/drtstuff.d
+	$(LTDCOMPILE) -fno-druntime -fversion=DRT_BEGIN $(GDCFLAGS) $(MULTIFLAGS) \
 		$(D_EXTRA_DFLAGS) -c -o $@ $<
 
-gcc/drtend.o: gcc/drtstuff.d
-	$(GDC) -fno-druntime -fversion=DRT_END $(GDCFLAGS) $(MULTIFLAGS) \
+gcc/drtend.lo: gcc/drtstuff.d
+	$(LTDCOMPILE) -fno-druntime -fversion=DRT_END $(GDCFLAGS) $(MULTIFLAGS) \
 		$(D_EXTRA_DFLAGS) -c -o $@ $<
 
 # Generated by configure
@@ -128,7 +128,7 @@ ALL_DRUNTIME_SOURCES = $(DRUNTIME_DSOURC
 toolexeclib_LTLIBRARIES = libgdruntime.la
 libgdruntime_la_SOURCES = $(ALL_DRUNTIME_SOURCES)
 libgdruntime_la_LIBTOOLFLAGS =
-libgdruntime_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../src,-Bgcc \
+libgdruntime_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../src,-Bgcc/.libs \
     -version-info $(libtool_VERSION)
 libgdruntime_la_LIBADD = $(LIBATOMIC) $(LIBBACKTRACE)
 libgdruntime_la_DEPENDENCIES = $(DRTSTUFF)
diff -rup dist/libphobos/src/Makefile.am local/libphobos/src/Makefile.am
--- dist/libphobos/src/Makefile.am	2022-04-22 10:35:48.188886065 +0200
+++ local/libphobos/src/Makefile.am	2022-07-10 22:04:32.081171000 +0200
@@ -44,7 +44,7 @@ toolexeclib_DATA = libgphobos.spec
 toolexeclib_LTLIBRARIES = libgphobos.la
 libgphobos_la_SOURCES = $(ALL_PHOBOS_SOURCES)
 libgphobos_la_LIBTOOLFLAGS =
-libgphobos_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../libdruntime/gcc \
+libgphobos_la_LDFLAGS = -Wc,-nophoboslib,-dstartfiles,-B../libdruntime/gcc/.libs \
     -version-info $(libtool_VERSION)
 if ENABLE_LIBDRUNTIME_ONLY
 libgphobos_la_LIBADD = ../libdruntime/libgdruntime_convenience.la
diff -rup dist/libphobos/testsuite/testsuite_flags.in local/libphobos/testsuite/testsuite_flags.in
--- dist/libphobos/testsuite/testsuite_flags.in	2022-02-16 17:39:54.216833983 +0100
+++ local/libphobos/testsuite/testsuite_flags.in	2022-07-10 19:24:55.746013000 +0200
@@ -47,7 +47,7 @@ case ${query} in
       ;;
     --gdcldflags)
       GDCLDFLAGS="-B${BUILD_DIR}/src
-                  -B${BUILD_DIR}/libdruntime/gcc
+                  -B${BUILD_DIR}/libdruntime/gcc/.libs
                   -B${BUILD_DIR}/src/.libs
                   -L${BUILD_DIR}/src/.libs"
       echo ${GDCLDFLAGS}

      reply	other threads:[~2022-07-11  8:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-08 13:07 Iain Buclaw
2022-07-11  8:58 ` Rainer Orth [this message]

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=yddsfn89gao.fsf@CeBiTec.Uni-Bielefeld.DE \
    --to=ro@cebitec.uni-bielefeld.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ibuclaw@gdcproject.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).