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


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 via email to