[1/n] modula-2: Fix building the plugin for Darwin [PR107612].

Message ID 20221230094132.15562-1-iain@sandoe.co.uk
State New
Headers
Series [1/n] modula-2: Fix building the plugin for Darwin [PR107612]. |

Commit Message

Iain Sandoe Dec. 30, 2022, 9:41 a.m. UTC
  From: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>

There are several modula-2 issues on Darwin, some blocking bootstrap on
one or more system versions.

This has been tested on powerpc/i688-darwin9 .. x86_64-darwin10,17,21 and
the prototype aarch64-darwin branch on darwin21.

OK for trunk?
thanks
Iain

this patch:

--- 8< ---

 * Makes the configured value for INCINTL available as a variable so that
it can be used in language makefile fragements.  It is then used in the m2
fragment to make the include path available to the plugin compile.

 * Updates the DSO suffix  to use .dylib for Darwin.

 * Adds '-Wl,-undefined,dynamic_lookup' to the link flags so that symbols can
   be resolved at runtime.

 * Removes the extraneous $(exeext) from the DSO names.

Since the linking is driven by CXX, we also need to supress the addition of
default libraries otherwise:
 (1) we will get a reference to an uninstalled libstdc++
 (2) the process opening the plugin would have two instances 0f libstdc++ -
     one statically linked into gm2 and one dynamically linked into the plugin.

gcc/ChangeLog:

	* Makefile.in: Make the configured libintl includes avaiable in INCINTL.
	(BUILD_CPPFLAGS): Use INCINTL.

gcc/m2/ChangeLog:

	* Make-lang.in (soext): Use .dylib for Darwin.
	(PLUGINLDFLAGS): Use dynmic lookup, set the plugin name, and append
	-nodefaultlibs to suppress the linking of libstdc++.
	Use INCINTL in compile lines for the plugin.

Co-Authored-By: Iain Sandoe <iain@sandoe.co.uk>
---
 gcc/Makefile.in     |  5 +++--
 gcc/m2/Make-lang.in | 34 +++++++++++++++++++++++-----------
 2 files changed, 26 insertions(+), 13 deletions(-)
  

Patch

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 995d77f96c4..4e5fb677cfe 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -729,6 +729,7 @@  htmldir = @htmldir@
 USE_NLS = @USE_NLS@
 
 # Internationalization library.
+INCINTL = @INCINTL@
 LIBINTL = @LIBINTL@
 LIBINTL_DEP = @LIBINTL_DEP@
 
@@ -820,7 +821,7 @@  BUILD_LINKERFLAGS = $(BUILD_CXXFLAGS)
 # Native linker and preprocessor flags.  For x-fragment overrides.
 BUILD_LDFLAGS=@BUILD_LDFLAGS@
 BUILD_CPPFLAGS= -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \
-		-I$(srcdir)/../include @INCINTL@ $(CPPINC) $(CPPFLAGS)
+		-I$(srcdir)/../include $(INCINTL) $(CPPINC) $(CPPFLAGS)
 
 # Actual name to use when installing a native compiler.
 GCC_INSTALL_NAME := $(shell echo gcc|sed '$(program_transform_name)')
@@ -1125,7 +1126,7 @@  BUILD_ERRORS = build/errors.o
 # currently being compiled, in both source trees, to be examined as well.
 # libintl.h will be found in ../intl if we are using the included libintl.
 INCLUDES = -I. -I$(@D) -I$(srcdir) -I$(srcdir)/$(@D) \
-	   -I$(srcdir)/../include @INCINTL@ \
+	   -I$(srcdir)/../include $(INCINTL) \
 	   $(CPPINC) $(CODYINC) $(GMPINC) $(DECNUMINC) $(BACKTRACEINC) \
 	   $(ISLINC)
 
diff --git a/gcc/m2/Make-lang.in b/gcc/m2/Make-lang.in
index 828eaad6285..1f615ec9907 100644
--- a/gcc/m2/Make-lang.in
+++ b/gcc/m2/Make-lang.in
@@ -31,6 +31,16 @@  GM2_1 = ./gm2 -B./m2/stage1 -g -fm2-g
 
 GM2_FOR_TARGET = $(STAGE_CC_WRAPPER) ./gm2 -B./ -B$(build_tooldir)/bin/ -L$(objdir)/../ld $(TFLAGS)
 
+# FIXME: Get from gcc-plugin.m4 instead of hardcoding.
+ifeq (,$(findstring darwin,$(host)))
+  soext=.so
+else
+  soext=.dylib
+  PLUGINLDFLAGS = -Wl,-undefined,dynamic_lookup
+  PLUGINLDFLAGS += -Wl,-install_name,m2rte$(soext)
+  PLUGINLDFLAGS += -nodefaultlibs
+endif
+
 TEXISRC = $(objdir)/m2/images/gnu.eps \
           $(srcdir)/doc/gm2.texi \
           m2/gm2-libs.texi \
@@ -113,9 +123,9 @@  po-generated:
 
 # Build hooks:
 
-m2.all.cross: gm2-cross$(exeext) plugin/m2rte$(exeext).so
+m2.all.cross: gm2-cross$(exeext) plugin/m2rte$(soext)
 
-m2.start.encap: gm2$(exeext) plugin/m2rte$(exeext).so
+m2.start.encap: gm2$(exeext) plugin/m2rte$(soext)
 m2.rest.encap:
 
 
@@ -367,14 +377,16 @@  m2.uninstall:
 
 m2.install-plugin: installdirs
 	$(mkinstalldirs) $(DESTDIR)$(plugin_resourcesdir)
-	$(INSTALL_PROGRAM) plugin/m2rte$(exeext).so $(DESTDIR)$(plugin_resourcesdir)/m2rte$(exeext).so
-	chmod a+x $(DESTDIR)$(plugin_resourcesdir)/m2rte$(exeext).so
+	$(INSTALL_PROGRAM) plugin/m2rte$(soext) $(DESTDIR)$(plugin_resourcesdir)/m2rte$(soext)
+	chmod a+x $(DESTDIR)$(plugin_resourcesdir)/m2rte$(soext)
+
+override PLUGINCFLAGS := $(filter-out -mdynamic-no-pic,$(PLUGINCFLAGS))
 
-plugin/m2rte$(exeext).so: $(srcdir)/m2/plugin/m2rte.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
+plugin/m2rte$(soext): $(srcdir)/m2/plugin/m2rte.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
         insn-attr-common.h insn-flags.h $(generated_files)
 	-test -d plugin || $(mkinstalldirs) plugin
-	$(PLUGINCC) $(PLUGINCFLAGS) -fno-rtti -I. -I$(srcdir) -I$(srcdir)/m2 -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/../include -I$(srcdir)/../libcpp/include -Wall $(GMPINC) -Wno-literal-suffix -fPIC -c -o plugin/m2rte.o $(srcdir)/m2/plugin/m2rte.cc
-	$(PLUGINCC) $(PLUGINCFLAGS) $(PLUGINLIBS) -fno-rtti plugin/m2rte.o -shared -o $@
+	$(PLUGINCC) $(PLUGINCFLAGS) -fno-rtti -I. -I$(srcdir) $(INCINTL) -I$(srcdir)/m2 -I$(srcdir)/m2/gm2-gcc -I$(srcdir)/../include -I$(srcdir)/../libcpp/include -Wall $(GMPINC) -Wno-literal-suffix -fPIC -c -o plugin/m2rte.o $(srcdir)/m2/plugin/m2rte.cc
+	$(PLUGINCC) $(PLUGINCFLAGS) $(PLUGINLDFLAGS) $(PLUGINLIBS) $(LIBINTL) -fno-rtti plugin/m2rte.o -shared -o $@
 
 
 # Clean hooks:
@@ -476,7 +488,7 @@  cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) $(m2.prev)
 
 m2/stage2/cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) m2/gm2-compiler/m2flex.o $(P) \
                             $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) $(GM2_LIBS) \
-                            m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so m2/gm2-libs-boot/M2LINK.o
+                            m2/gm2-gcc/rtegraph.o plugin/m2rte$(soext) m2/gm2-libs-boot/M2LINK.o
 	-test -d m2/stage2 || $(mkinstalldirs) m2/stage2
 	@$(call LINK_PROGRESS,$(INDEX.m2),start)
 	+$(LLINKER) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GM2_C_OBJS) m2/gm2-compiler/m2flex.o \
@@ -489,7 +501,7 @@  m2/stage2/cc1gm2$(exeext): m2/stage1/cc1gm2$(exeext) m2/gm2-compiler/m2flex.o $(
 m2/stage1/cc1gm2$(exeext): gm2$(exeext) m2/gm2-compiler-boot/m2flex.o \
                             $(P) $(GM2_C_OBJS) $(BACKEND) $(LIBDEPS) \
                             $(GM2_LIBS_BOOT) $(MC_LIBS) \
-                            m2/gm2-gcc/rtegraph.o plugin/m2rte$(exeext).so \
+                            m2/gm2-gcc/rtegraph.o plugin/m2rte$(soext) \
                             m2/gm2-libs-boot/M2LINK.o \
                             $(m2.prev)
 	-test -d m2/stage1 || $(mkinstalldirs) m2/stage1
@@ -526,7 +538,7 @@  m2/gm2-gcc/m2configure.o: $(srcdir)/m2/gm2-gcc/m2configure.cc \
                 -c $(srcdir)/m2/gm2-gcc/m2configure.cc $(OUTPUT_OPTION)
 
 m2/gm2-lang.o: $(srcdir)/m2/gm2-lang.cc gt-m2-gm2-lang.h $(GCC_HEADER_DEPENDENCIES_FOR_M2)
-	$(COMPILER) -c -g -I$(GM2GCC) $(ALL_COMPILERFLAGS) \
+	$(COMPILER) -c -g $(GM2GCC) $(ALL_COMPILERFLAGS) \
             $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
 m2/stor-layout.o: $(srcdir)/stor-layout.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)
@@ -540,7 +552,7 @@  m2/m2pp.o : $(srcdir)/m2/m2pp.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)
 m2/gm2-gcc/rtegraph.o: $(srcdir)/m2/gm2-gcc/rtegraph.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2) \
                        gt-m2-rtegraph.h
 	-test -d m2/gm2-gcc || $(mkinstalldirs) m2/gm2-gcc
-	$(COMPILER) -c -g -I$(GM2GCC) $(ALL_COMPILERFLAGS) \
+	$(COMPILER) -c -g $(GM2GCC) $(ALL_COMPILERFLAGS) \
             $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)
 
 c-family/m2pp.o : $(srcdir)/m2/m2pp.cc $(GCC_HEADER_DEPENDENCIES_FOR_M2)