aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2006-10-16 19:53:29 +0000
committerMike Stump <mrs@gcc.gnu.org>2006-10-16 19:53:29 +0000
commitf475fd3c9e74adce232dbc3e82333d2c574a2ef8 (patch)
treeda708a8ea1a1ba16e416d1932eea2803f1bfd735
parentcc5c274102f86b028c67b4e2adbd95fbb214a87b (diff)
downloadgcc-f475fd3c9e74adce232dbc3e82333d2c574a2ef8.zip
gcc-f475fd3c9e74adce232dbc3e82333d2c574a2ef8.tar.gz
gcc-f475fd3c9e74adce232dbc3e82333d2c574a2ef8.tar.bz2
darwin.h (SUBTARGET_OVERRIDE_OPTIONS): Add -mkernel support.
* config/rs6000/darwin.h (SUBTARGET_OVERRIDE_OPTIONS): Add -mkernel support. (C_COMMON_OVERRIDE_OPTIONS): Add -mkernel support. Add SUBTARGET_C_COMMON_OVERRIDE_OPTIONS callout. (CC1_SPEC): Don't turn on -fPIC when -mkernel is given. (OS_MISSING_ALTIVEC): Add. * config/i386/i386.c (override_options): Add SUBSUBTARGET_OVERRIDE_OPTIONS callout. * config/i386/darwin.h (CC1_SPEC): Don't turn on -fPIC when -mkernel, -static or -mdynamic-no-pic is given. (C_COMMON_OVERRIDE_OPTIONS): Add. * config/darwin.opt (fapple-kext): Add. (mkernel): Add. * config/darwin.h (TARGET_OPTION_TRANSLATE_TABLE): Add -fapple-kext, -findirect-virtual-calls, -fterminated-vtables and -mkernel support. (SUBSUBTARGET_OVERRIDE_OPTIONS): Add. (SUBTARGET_C_COMMON_OVERRIDE_OPTIONS): Add. (CPP_SPEC): Move defines for __DYNAMIC__ and __STATIC__ from here... (SUBTARGET_ATTRIBUTE_TABLE): Add apple_kext_compatibility. (TARGET_CXX_CDTOR_RETURNS_THIS): Add. (flag_mkernel): Add. (flag_apple_kext): Add. (TARGET_KEXTABI): Add. * config/darwin.c (darwin_handle_kext_attribute): Add. (DARWIN_VTABLE_P): Add. (darwin_binds_local_p): Add partial support for rebinding vtables in kexts. (darwin_kextabi_p): Add. (darwin_override_options): Add. * config/darwin-protos.h (darwin_handle_kext_attribute): Add. (darwin_kextabi_p): Add. (darwin_override_options): Add. * config/darwin-c.c (darwin_cpp_builtins): ... move defines for __DYNAMIC__ and __STATIC__ here. From-SVN: r117793
-rw-r--r--gcc/ChangeLog38
-rw-r--r--gcc/config/darwin-c.c5
-rw-r--r--gcc/config/darwin-protos.h3
-rw-r--r--gcc/config/darwin.c74
-rw-r--r--gcc/config/darwin.h35
-rw-r--r--gcc/config/darwin.opt8
-rw-r--r--gcc/config/i386/darwin.h7
-rw-r--r--gcc/config/i386/i386.c4
-rw-r--r--gcc/config/rs6000/darwin.h18
9 files changed, 184 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a03556d..877d893 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,41 @@
+2006-10-16 Mike Stump <mrs@apple.com>
+
+ * config/rs6000/darwin.h (SUBTARGET_OVERRIDE_OPTIONS): Add
+ -mkernel support.
+ (C_COMMON_OVERRIDE_OPTIONS): Add -mkernel support. Add
+ SUBTARGET_C_COMMON_OVERRIDE_OPTIONS callout.
+ (CC1_SPEC): Don't turn on -fPIC when -mkernel is given.
+ (OS_MISSING_ALTIVEC): Add.
+ * config/i386/i386.c (override_options): Add
+ SUBSUBTARGET_OVERRIDE_OPTIONS callout.
+ * config/i386/darwin.h (CC1_SPEC): Don't turn on -fPIC when
+ -mkernel, -static or -mdynamic-no-pic is given.
+ (C_COMMON_OVERRIDE_OPTIONS): Add.
+ * config/darwin.opt (fapple-kext): Add.
+ (mkernel): Add.
+ * config/darwin.h (TARGET_OPTION_TRANSLATE_TABLE): Add
+ -fapple-kext, -findirect-virtual-calls, -fterminated-vtables and
+ -mkernel support.
+ (SUBSUBTARGET_OVERRIDE_OPTIONS): Add.
+ (SUBTARGET_C_COMMON_OVERRIDE_OPTIONS): Add.
+ (CPP_SPEC): Move defines for __DYNAMIC__ and __STATIC__ from here...
+ (SUBTARGET_ATTRIBUTE_TABLE): Add apple_kext_compatibility.
+ (TARGET_CXX_CDTOR_RETURNS_THIS): Add.
+ (flag_mkernel): Add.
+ (flag_apple_kext): Add.
+ (TARGET_KEXTABI): Add.
+ * config/darwin.c (darwin_handle_kext_attribute): Add.
+ (DARWIN_VTABLE_P): Add.
+ (darwin_binds_local_p): Add partial support for rebinding vtables
+ in kexts.
+ (darwin_kextabi_p): Add.
+ (darwin_override_options): Add.
+ * config/darwin-protos.h (darwin_handle_kext_attribute): Add.
+ (darwin_kextabi_p): Add.
+ (darwin_override_options): Add.
+ * config/darwin-c.c (darwin_cpp_builtins): ... move defines for
+ __DYNAMIC__ and __STATIC__ here.
+
2006-10-16 Brooks Moses <bmoses@stanford.edu>
* doc/sourcebuild.texi, doc/makefile.texi, doc/install.texi:
diff --git a/gcc/config/darwin-c.c b/gcc/config/darwin-c.c
index 88ce9ef..51dbf5c 100644
--- a/gcc/config/darwin-c.c
+++ b/gcc/config/darwin-c.c
@@ -619,4 +619,9 @@ darwin_cpp_builtins (cpp_reader *pfile)
if (darwin_macosx_version_min)
builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__",
version_as_macro(), false);
+
+ if (flag_pic || MACHO_DYNAMIC_NO_PIC_P)
+ builtin_define ("__DYNAMIC__");
+ else
+ builtin_define ("__STATIC__");
}
diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h
index 14da36d..b28317b 100644
--- a/gcc/config/darwin-protos.h
+++ b/gcc/config/darwin-protos.h
@@ -73,6 +73,7 @@ extern void darwin_file_end (void);
extern void darwin_mark_decl_preserved (const char *);
+extern tree darwin_handle_kext_attribute (tree *, tree, tree, int, bool *);
extern tree darwin_handle_weak_import_attribute (tree *node, tree name,
tree args, int flags,
bool * no_add_attrs);
@@ -86,3 +87,5 @@ extern void darwin_asm_output_dwarf_offset (FILE *, int, const char *,
extern bool darwin_binds_local_p (tree);
extern void darwin_cpp_builtins (struct cpp_reader *);
extern void darwin_asm_output_anchor (rtx symbol);
+extern bool darwin_kextabi_p (void);
+extern void darwin_override_options (void);
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 124d4af..587a327 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -1303,6 +1303,42 @@ darwin_unique_section (tree decl ATTRIBUTE_UNUSED, int reloc ATTRIBUTE_UNUSED)
/* Darwin does not use unique sections. */
}
+/* Handle __attribute__ ((apple_kext_compatibility)).
+ This only applies to darwin kexts for 2.95 compatibility -- it shrinks the
+ vtable for classes with this attribute (and their descendants) by not
+ outputting the new 3.0 nondeleting destructor. This means that such
+ objects CANNOT be allocated on the stack or as globals UNLESS they have
+ a completely empty `operator delete'.
+ Luckily, this fits in with the Darwin kext model.
+
+ This attribute also disables gcc3's potential overlaying of derived
+ class data members on the padding at the end of the base class. */
+
+tree
+darwin_handle_kext_attribute (tree *node, tree name,
+ tree args ATTRIBUTE_UNUSED,
+ int flags ATTRIBUTE_UNUSED,
+ bool *no_add_attrs)
+{
+ /* APPLE KEXT stuff -- only applies with pure static C++ code. */
+ if (! TARGET_KEXTABI)
+ {
+ warning (0, "%<%s%> 2.95 vtable-compatability attribute applies "
+ "only when compiling a kext", IDENTIFIER_POINTER (name));
+
+ *no_add_attrs = true;
+ }
+ else if (TREE_CODE (*node) != RECORD_TYPE)
+ {
+ warning (0, "%<%s%> 2.95 vtable-compatability attribute applies "
+ "only to C++ classes", IDENTIFIER_POINTER (name));
+
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
+
/* Handle a "weak_import" attribute; arguments as in
struct attribute_spec.handler. */
@@ -1529,13 +1565,17 @@ darwin_file_end (void)
fprintf (asm_out_file, "\t.subsections_via_symbols\n");
}
+/* TODO: Add a language hook for identifying if a decl is a vtable. */
+#define DARWIN_VTABLE_P(DECL) 0
+
/* Cross-module name binding. Darwin does not support overriding
- functions at dynamic-link time. */
+ functions at dynamic-link time, except for vtables in kexts. */
bool
darwin_binds_local_p (tree decl)
{
- return default_binds_local_p_1 (decl, 0);
+ return default_binds_local_p_1 (decl,
+ TARGET_KEXTABI && DARWIN_VTABLE_P (decl));
}
#if 0
@@ -1565,4 +1605,34 @@ darwin_set_default_type_attributes (tree type)
TYPE_ATTRIBUTES (type));
}
+/* True, iff we're generating code for loadable kernel extentions. */
+
+bool
+darwin_kextabi_p (void) {
+ return flag_apple_kext;
+}
+
+void
+darwin_override_options (void)
+{
+ if (flag_apple_kext && strcmp (lang_hooks.name, "GNU C++") != 0)
+ {
+ warning (0, "command line option %<-fapple-kext%> is only valid for C++");
+ flag_apple_kext = 0;
+ }
+ if (flag_mkernel || flag_apple_kext)
+ {
+ /* -mkernel implies -fapple-kext for C++ */
+ if (strcmp (lang_hooks.name, "GNU C++") == 0)
+ flag_apple_kext = 1;
+
+ flag_no_common = 1;
+
+ /* No EH in kexts. */
+ flag_exceptions = 0;
+ /* No -fnon-call-exceptions data in kexts. */
+ flag_non_call_exceptions = 0;
+ }
+}
+
#include "gt-darwin.h"
diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h
index 050eec9..21f909d 100644
--- a/gcc/config/darwin.h
+++ b/gcc/config/darwin.h
@@ -127,14 +127,18 @@ extern GTY(()) int darwin_ms_struct;
{ "-segs_read_write_addr", "-Zsegs_read_write_addr" }, \
{ "-seg_addr_table", "-Zseg_addr_table" }, \
{ "-seg_addr_table_filename", "-Zfn_seg_addr_table_filename" }, \
+ { "-fapple-kext", "-fapple-kext -static -Wa,-static" }, \
{ "-filelist", "-Xlinker -filelist -Xlinker" }, \
- { "-framework", "-Xlinker -framework -Xlinker" }, \
+ { "-findirect-virtual-calls", "-fapple-kext" }, \
{ "-flat_namespace", "-Zflat_namespace" }, \
{ "-force_cpusubtype_ALL", "-Zforce_cpusubtype_ALL" }, \
{ "-force_flat_namespace", "-Zforce_flat_namespace" }, \
+ { "-framework", "-Xlinker -framework -Xlinker" }, \
+ { "-fterminated-vtables", "-fapple-kext" }, \
{ "-image_base", "-Zimage_base" }, \
{ "-init", "-Zinit" }, \
{ "-install_name", "-Zinstall_name" }, \
+ { "-mkernel", "-mkernel -static -Wa,-static" }, \
{ "-multiply_defined_unused", "-Zmultiplydefinedunused" }, \
{ "-multiply_defined", "-Zmultiply_defined" }, \
{ "-multi_module", "-Zmulti_module" }, \
@@ -143,6 +147,11 @@ extern GTY(()) int darwin_ms_struct;
{ "-unexported_symbols_list", "-Zunexported_symbols_list" }, \
SUBTARGET_OPTION_TRANSLATE_TABLE
+#define SUBSUBTARGET_OVERRIDE_OPTIONS \
+ do { \
+ darwin_override_options (); \
+ } while (0)
+
/* These compiler options take n arguments. */
#undef WORD_SWITCH_TAKES_ARG
@@ -188,11 +197,24 @@ extern GTY(()) int darwin_ms_struct;
!strcmp (STR, "dylinker_install_name") ? 1 : \
0)
+#define SUBTARGET_C_COMMON_OVERRIDE_OPTIONS do { \
+ if (flag_mkernel || flag_apple_kext) \
+ { \
+ if (flag_use_cxa_atexit == 2) \
+ flag_use_cxa_atexit = 0; \
+ /* kexts should always be built without the coalesced sections \
+ because the kernel loader doesn't grok such sections. */ \
+ flag_weak = 0; \
+ /* No RTTI in kexts. */ \
+ flag_rtti = 0; \
+ } \
+ } while (0)
+
/* Machine dependent cpp options. Don't add more options here, add
them to darwin_cpp_builtins in darwin-c.c. */
#undef CPP_SPEC
-#define CPP_SPEC "%{static:%{!dynamic:-D__STATIC__}}%{!static:-D__DYNAMIC__}"
+#define CPP_SPEC ""
/* This is mostly a clone of the standard LINK_COMMAND_SPEC, plus
precomp, libtool, and fat build additions. Also we
@@ -693,6 +715,8 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
/* Extra attributes for Darwin. */
#define SUBTARGET_ATTRIBUTE_TABLE \
/* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ \
+ { "apple_kext_compatibility", 0, 0, false, true, false, \
+ darwin_handle_kext_attribute }, \
{ "weak_import", 0, 0, true, false, false, \
darwin_handle_weak_import_attribute }
@@ -926,4 +950,11 @@ __enable_execute_stack (void *addr) \
(void) mprotect (page, end - page, 7); \
}
+/* For Apple KEXTs, we make the constructors return this to match gcc
+ 2.95. */
+#define TARGET_CXX_CDTOR_RETURNS_THIS (darwin_kextabi_p)
+extern int flag_mkernel;
+extern int flag_apple_kext;
+#define TARGET_KEXTABI flag_apple_kext
+
#endif /* CONFIG_DARWIN_H */
diff --git a/gcc/config/darwin.opt b/gcc/config/darwin.opt
index 90a094b..9fee719 100644
--- a/gcc/config/darwin.opt
+++ b/gcc/config/darwin.opt
@@ -30,3 +30,11 @@ The earliest MacOS X version on which this program will run
mone-byte-bool
Target RejectNegative Report Var(darwin_one_byte_bool)
Set sizeof(bool) to 1
+
+fapple-kext
+Target Report Var(flag_apple_kext)
+Generate code for darwin loadable kernel extentions
+
+mkernel
+Target Report Var(flag_mkernel)
+Generate code for the kernel or loadable kernel extentions
diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
index 61cdeb0..55b55ab 100644
--- a/gcc/config/i386/darwin.h
+++ b/gcc/config/i386/darwin.h
@@ -70,7 +70,7 @@ Boston, MA 02110-1301, USA. */
the kernel or some such. */
#undef CC1_SPEC
-#define CC1_SPEC "%{!static:-fPIC}\
+#define CC1_SPEC "%{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
%{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }}"
#undef ASM_SPEC
@@ -182,6 +182,11 @@ extern void darwin_x86_file_end (void);
else fprintf (FILE, "\tcall mcount\n"); \
} while (0)
+#define C_COMMON_OVERRIDE_OPTIONS \
+ do { \
+ SUBTARGET_C_COMMON_OVERRIDE_OPTIONS; \
+ } while (0)
+
/* Darwin on x86_64 uses dwarf-2 by default. */
#undef PREFERRED_DEBUGGING_TYPE
#define PREFERRED_DEBUGGING_TYPE (TARGET_64BIT ? DWARF2_DEBUG : DBX_DEBUG)
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 287163e..e4f711e 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -1537,6 +1537,10 @@ override_options (void)
SUBTARGET_OVERRIDE_OPTIONS;
#endif
+#ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
+ SUBSUBTARGET_OVERRIDE_OPTIONS;
+#endif
+
/* -fPIC is the default for x86_64. */
if (TARGET_MACHO && TARGET_64BIT)
flag_pic = 2;
diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h
index 763cf56..374f001 100644
--- a/gcc/config/rs6000/darwin.h
+++ b/gcc/config/rs6000/darwin.h
@@ -91,6 +91,11 @@ do { \
target_flags |= MASK_POWERPC64; \
warning (0, "-m64 requires PowerPC64 architecture, enabling"); \
} \
+ if (flag_mkernel) \
+ { \
+ rs6000_default_long_calls = 1; \
+ target_flags |= MASK_SOFT_FLOAT; \
+ } \
} while(0)
#define C_COMMON_OVERRIDE_OPTIONS do { \
@@ -100,6 +105,9 @@ do { \
|| strverscmp (darwin_macosx_version_min, "10.4.6") < 0) \
&& flag_use_cxa_get_exception_ptr == 2) \
flag_use_cxa_get_exception_ptr = 0; \
+ if (flag_mkernel) \
+ flag_no_builtin = 1; \
+ SUBTARGET_C_COMMON_OVERRIDE_OPTIONS; \
} while (0)
/* Darwin has 128-bit long double support in libc in 10.4 and later.
@@ -114,9 +122,9 @@ do { \
the kernel or some such. */
#define CC1_SPEC "\
-%{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \
-%{static: %{Zdynamic: %e conflicting code gen style switches are used}}\
-%{!static:%{!mdynamic-no-pic:-fPIC}}"
+ %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \
+ %{static: %{Zdynamic: %e conflicting code gen style switches are used}}\
+ %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}}"
#define DARWIN_SUBARCH_SPEC " \
%{m64: ppc64} \
@@ -440,3 +448,7 @@ do { \
(TARGET_64BIT \
|| (darwin_macosx_version_min \
&& strverscmp (darwin_macosx_version_min, "10.3") >= 0))
+
+/* When generating kernel code or kexts, we don't use Altivec by
+ default, as kernel code doesn't save/restore those registers. */
+#define OS_MISSING_ALTIVEC (flag_mkernel || flag_apple_kext)