diff mbox series

[Darwin] Move fixed _Unwind_find_Enclosing_func to a crt.

Message ID D61F6D63-F9E1-42C8-8F29-AE44CC314ABD@sandoe.co.uk
State New
Headers show
Series [Darwin] Move fixed _Unwind_find_Enclosing_func to a crt. | expand

Commit Message

Iain Sandoe Aug. 15, 2018, 6:50 p.m. UTC
Hi,

This is a pre-cursor to other tidy-ups aimed at being able to dispense with the “ext” library that we introduced (a loooong time ago) to deal with the differences between Darwin’s installed libgcc_s and the current compiler.

Since the installed version of _Unwind_find_Enclosing_func was broken, we built a small shim function to allow Java to work on Darwin10.

We have been carrying this around in the darwin-specific unwinder code ever since.

This patch splits the patch function out into a shim crt that is included only when needed (for x86 and ppc via Rosetta on Darwin10).

There is no need to treat Darwin12+ differently in this and that allows us to simplify the header there.

OK for trunk?
Iain

2018-08-15  Iain Sandoe <iain@sandoe.co.uk>

gcc/
	* config/darwin10.h (LINK_GCC_C_SEQUENCE_SPEC): Adjust to use the
	Darwin10-specific unwinder-shim.
	* config/darwin12.h (LINK_GCC_C_SEQUENCE_SPEC): Remove.
	* config/rs6000/darwin.h (DARWIN_CRT1_SPEC, DARWIN_DYLIB1_SPEC): 
	New to cater for Darwin10 Rosetta.

libgcc/
	* config/unwind-dw2-fde-darwin.c  (_darwin10_Unwind_FindEnclosingFunction):
	move from here ...
	* config/darwin10-unwind-find-enc-func.c: … to here.
	* config/t-darwin: Build Darwin10 unwinder shim crt.
	* libgcc/config.host: Add the Darwin10 unwinder shim.

---
 gcc/config/darwin10.h                         | 10 ++++++----
 gcc/config/darwin12.h                         |  8 --------
 gcc/config/rs6000/darwin.h                    | 13 +++++++++++++
 libgcc/config.host                            |  2 +-
 libgcc/config/darwin10-unwind-find-enc-func.c | 13 +++++++++++++
 libgcc/config/t-darwin                        |  4 ++++
 libgcc/config/unwind-dw2-fde-darwin.c         | 13 -------------
 7 files changed, 37 insertions(+), 26 deletions(-)
 create mode 100644 libgcc/config/darwin10-unwind-find-enc-func.c

Comments

Jeff Law Aug. 17, 2018, 4:52 a.m. UTC | #1
On 08/15/2018 12:50 PM, Iain Sandoe wrote:
> Hi,
> 
> This is a pre-cursor to other tidy-ups aimed at being able to dispense with the “ext” library that we introduced (a loooong time ago) to deal with the differences between Darwin’s installed libgcc_s and the current compiler.
> 
> Since the installed version of _Unwind_find_Enclosing_func was broken, we built a small shim function to allow Java to work on Darwin10.
> 
> We have been carrying this around in the darwin-specific unwinder code ever since.
> 
> This patch splits the patch function out into a shim crt that is included only when needed (for x86 and ppc via Rosetta on Darwin10).
> 
> There is no need to treat Darwin12+ differently in this and that allows us to simplify the header there.
> 
> OK for trunk?
> Iain
> 
> 2018-08-15  Iain Sandoe <iain@sandoe.co.uk>
> 
> gcc/
> 	* config/darwin10.h (LINK_GCC_C_SEQUENCE_SPEC): Adjust to use the
> 	Darwin10-specific unwinder-shim.
> 	* config/darwin12.h (LINK_GCC_C_SEQUENCE_SPEC): Remove.
> 	* config/rs6000/darwin.h (DARWIN_CRT1_SPEC, DARWIN_DYLIB1_SPEC): 
> 	New to cater for Darwin10 Rosetta.
> 
> libgcc/
> 	* config/unwind-dw2-fde-darwin.c  (_darwin10_Unwind_FindEnclosingFunction):
> 	move from here ...
> 	* config/darwin10-unwind-find-enc-func.c: … to here.
> 	* config/t-darwin: Build Darwin10 unwinder shim crt.
> 	* libgcc/config.host: Add the Darwin10 unwinder shim.
Given you've probably got a better understanding of Darwin's needs than
anyone here, this seems quite reasonable.  OK for the trunk unless
someone objects in the next 24hrs.

jeff
diff mbox series

Patch

diff --git a/gcc/config/darwin10.h b/gcc/config/darwin10.h
index d61eb40b8f..df694299ad 100644
--- a/gcc/config/darwin10.h
+++ b/gcc/config/darwin10.h
@@ -25,10 +25,12 @@  along with GCC; see the file COPYING3.  If not see
 #undef  LINK_GCC_C_SEQUENCE_SPEC
 #define LINK_GCC_C_SEQUENCE_SPEC \
 "%:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) \
-   %{!static:%{!static-libgcc: \
-      %:version-compare(>= 10.6 mmacosx-version-min= -lSystem) } } \
-   %{fno-pic|fno-PIC|fno-pie|fno-PIE|fapple-kext|mkernel|static|mdynamic-no-pic: \
-      %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } %G %{!nolibc:%L}"
+ %{!static:%{!static-libgcc: \
+    %:version-compare(>= 10.6 mmacosx-version-min= -lSystem) } } \
+ %{fno-pic|fno-PIC|fno-pie|fno-PIE|fapple-kext|mkernel|static|mdynamic-no-pic: \
+   %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } \
+ %{!nostdlib:%:version-compare(>< 10.6 10.7 mmacosx-version-min= -ld10-uwfef.o)} \
+  %G %{!nolibc:%L}"
 
 #undef DEF_MIN_OSX_VERSION
 #define DEF_MIN_OSX_VERSION "10.6"
diff --git a/gcc/config/darwin12.h b/gcc/config/darwin12.h
index e1e1eb085a..adc9a78d37 100644
--- a/gcc/config/darwin12.h
+++ b/gcc/config/darwin12.h
@@ -18,14 +18,6 @@  You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
-#undef  LINK_GCC_C_SEQUENCE_SPEC
-#define LINK_GCC_C_SEQUENCE_SPEC \
-"%:version-compare(>= 10.6 mmacosx-version-min= -no_compact_unwind) \
-   %{!static:%{!static-libgcc: \
-      %:version-compare(>= 10.6 mmacosx-version-min= -lSystem) } } \
-   %{fno-pic|fno-PIC|fno-pie|fno-PIE|fapple-kext|mkernel|static|mdynamic-no-pic: \
-      %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } %G %{!nolibc:%L}"
-
 #undef DEF_MIN_OSX_VERSION
 #define DEF_MIN_OSX_VERSION "10.8"
 
diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h
index cea1aa94b0..6b0f18e118 100644
--- a/gcc/config/rs6000/darwin.h
+++ b/gcc/config/rs6000/darwin.h
@@ -119,6 +119,13 @@  extern int darwin_emit_branch_islands;
    mcpu=G5:ppc970;				\
    :ppc}}"
 
+/* We need to jam the crt to 10.5 for 10.6 (Rosetta) use.  */
+#undef DARWIN_CRT1_SPEC
+#define DARWIN_CRT1_SPEC						\
+  "%:version-compare(!> 10.5 mmacosx-version-min= -lcrt1.o)		\
+   %:version-compare(>< 10.5 10.7 mmacosx-version-min= -lcrt1.10.5.o)	\
+   %{fgnu-tm: -lcrttms.o}"
+
 /* crt2.o is at least partially required for 10.3.x and earlier.  */
 #define DARWIN_CRT2_SPEC \
   "%{!m64:%:version-compare(!> 10.4 mmacosx-version-min= crt2.o%s)}"
@@ -130,6 +137,12 @@  extern int darwin_emit_branch_islands;
   { "darwin_crt2", DARWIN_CRT2_SPEC },		\
   { "darwin_subarch", DARWIN_SUBARCH_SPEC },
 
+/* We need to jam the dylib crt to 10.5 for 10.6 (Rosetta) use.  */
+#undef DARWIN_DYLIB1_SPEC
+#define DARWIN_DYLIB1_SPEC						\
+  "%:version-compare(!> 10.5 mmacosx-version-min= -ldylib1.o)		\
+   %:version-compare(>< 10.5 10.7 mmacosx-version-min= -ldylib1.10.5.o)"
+
 /* Output a .machine directive.  */
 #undef TARGET_ASM_FILE_START
 #define TARGET_ASM_FILE_START rs6000_darwin_file_start
diff --git a/libgcc/config.host b/libgcc/config.host
index 18cabaf24f..74024e50ef 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -205,7 +205,7 @@  case ${host} in
 *-*-darwin*)
   asm_hidden_op=.private_extern
   tmake_file="$tmake_file t-darwin ${cpu_type}/t-darwin t-libgcc-pic t-slibgcc-darwin"
-  extra_parts="crt3.o crttms.o crttme.o"
+  extra_parts="crt3.o d10-uwfef.o crttms.o crttme.o"
   ;;
 *-*-dragonfly*)
   tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip"
diff --git a/libgcc/config/darwin10-unwind-find-enc-func.c b/libgcc/config/darwin10-unwind-find-enc-func.c
new file mode 100644
index 0000000000..67c43757e5
--- /dev/null
+++ b/libgcc/config/darwin10-unwind-find-enc-func.c
@@ -0,0 +1,13 @@ 
+#include "tconfig.h"
+#include "tsystem.h"
+#include "unwind-dw2-fde.h"
+
+void *
+_darwin10_Unwind_FindEnclosingFunction (void *pc)
+{
+  struct dwarf_eh_bases bases;
+  const struct dwarf_fde *fde = _Unwind_Find_FDE (pc-1, &bases);
+  if (fde)
+    return bases.func;
+  return NULL;
+}
diff --git a/libgcc/config/t-darwin b/libgcc/config/t-darwin
index 13ca6ed99d..8340ea2bfe 100644
--- a/libgcc/config/t-darwin
+++ b/libgcc/config/t-darwin
@@ -20,3 +20,7 @@  HOST_LIBGCC2_CFLAGS += -pipe
 # Use unwind-dw2-fde-darwin
 LIB2ADDEH = $(srcdir)/unwind-dw2.c $(srcdir)/config/unwind-dw2-fde-darwin.c \
   $(srcdir)/unwind-sjlj.c $(srcdir)/unwind-c.c
+
+# Patch to __Unwind_Find_Enclosing_Function for Darwin10.
+d10-uwfef.o: $(srcdir)/config/darwin10-unwind-find-enc-func.c
+	$(crt_compile) $(DARWIN_EXTRA_CRT_BUILD_CFLAGS) -mmacosx-version-min=10.6 -c $<
diff --git a/libgcc/config/unwind-dw2-fde-darwin.c b/libgcc/config/unwind-dw2-fde-darwin.c
index 6e2d0d6d8b..c919de9abe 100644
--- a/libgcc/config/unwind-dw2-fde-darwin.c
+++ b/libgcc/config/unwind-dw2-fde-darwin.c
@@ -273,16 +273,3 @@  _Unwind_Find_FDE (void *pc, struct dwarf_eh_bases *bases)
 					  the_obj_info);
   return ret;
 }
-
-void *
-_darwin10_Unwind_FindEnclosingFunction (void *pc ATTRIBUTE_UNUSED)
-{
-#if __MACH__ && (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1060)
-  struct dwarf_eh_bases bases;
-  const struct dwarf_fde *fde = _Unwind_Find_FDE (pc-1, &bases);
-  if (fde)
-    return bases.func;
-#endif
-  return NULL;
-}
-