* c-common.c (handle_used_attribute): Set DECL_PRESERVE_P.
* print-tree.c (print_node): Print DECL_PRESERVE_P.
* target-def.h (TARGET_ASM_MARK_DECL_PRESERVED): New #define.
(TARGET_ASM_OUT): New member, TARGET_ASM_MARK_DECL_PRESERVED
* target.h (struct gcc_target): New member, mark_decl_preserved.
* hooks.c (hook_void_charptr): Rename to ...
(hook_void_constcharptr): ... new name.
* hooks.h (hook_void_charptr): Rename to ..
(hook_void_constcharptr): ... new name.
* tree.h (DECL_PRESERVE_P): New #define.
(struct tree_decl): New member, preserve_flag.
* varasm.c (assemble_start_function): Mark decl preserved.
(assemble_variable): Same.
* darwin.c (darwin_mark_decl_preserved): New function.
* darwin.h (TARGET_ASM_MARK_DECL_preserved): New #define.
* darwin-protos.h (darwin_mark_decl_preserved): New decl.
* doc/tm.texi (TARGET_ASM_MARK_DECL_PRESERVED): Document.
testsuite:
* gcc.dg/darwin-
20040809-1.c: New test.
From-SVN: r86076
+2004-08-16 Devang Patel <dpatel@apple.com>
+
+ * c-common.c (handle_used_attribute): Set DECL_PRESERVE_P.
+ * print-tree.c (print_node): Print DECL_PRESERVE_P.
+ * target-def.h (TARGET_ASM_MARK_DECL_PRESERVED): New #define.
+ (TARGET_ASM_OUT): New member, TARGET_ASM_MARK_DECL_PRESERVED
+ * target.h (struct gcc_target): New member, mark_decl_preserved.
+ * hooks.c (hook_void_charptr): Rename to ...
+ (hook_void_constcharptr): ... new name.
+ * hooks.h (hook_void_charptr): Rename to ..
+ (hook_void_constcharptr): ... new name.
+ * tree.h (DECL_PRESERVE_P): New #define.
+ (struct tree_decl): New member, preserve_flag.
+ * varasm.c (assemble_start_function): Mark decl preserved.
+ (assemble_variable): Same.
+ * darwin.c (darwin_mark_decl_preserved): New function.
+ * darwin.h (TARGET_ASM_MARK_DECL_preserved): New #define.
+ * darwin-protos.h (darwin_mark_decl_preserved): New decl.
+ * doc/tm.texi (TARGET_ASM_MARK_DECL_PRESERVED): Document.
+
2004-08-16 Joseph S. Myers <jsm@polyomino.org.uk>
* c-decl.c (grokdeclarator): Allow for function definition where
|| (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node)))
{
TREE_USED (node) = 1;
+ DECL_PRESERVE_P (node) = 1;
}
else
{
extern void darwin_file_end (void);
extern void darwin_make_decl_one_only (tree decl);
+extern void darwin_mark_decl_preserved (const char *);
/* Expanded by EXTRA_SECTION_FUNCTIONS into varasm.o. */
extern void const_section (void);
DECL_SECTION_NAME (decl) = build_string (strlen (sec), sec);
}
+void
+darwin_mark_decl_preserved (const char *name)
+{
+ fprintf (asm_out_file, ".no_dead_strip ");
+ assemble_name (asm_out_file, name);
+ fputc ('\n', asm_out_file);
+}
+
void
machopic_select_section (tree exp, int reloc,
unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
#define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
sprintf (LABEL, "*%s%ld", PREFIX, (long)(NUM))
+#undef TARGET_ASM_MARK_DECL_PRESERVED
+#define TARGET_ASM_MARK_DECL_PRESERVED darwin_mark_decl_preserved
+
/* Since we have a separate readonly data section, define this so that
jump tables end up in text rather than data. */
library function is given by @var{symref}, which is a @code{symbol_ref}.
@end deftypefn
+@deftypefn {Target Hook} void TARGET_ASM_MARK_DECL_PRESERVED (tree @var{decl})
+This target hook is a function to output to @var{asm_out_file} an assembler
+directive to annotate used symbol. Darwin target use .no_dead_code_strip
+directive.
+@end deftypefn
+
@defmac ASM_OUTPUT_LABELREF (@var{stream}, @var{name})
A C statement (sans semicolon) to output to the stdio stream
@var{stream} a reference in assembler syntax to a label named
}
void
-hook_void_charptr (char *a ATTRIBUTE_UNUSED)
+hook_void_constcharptr (const char *a ATTRIBUTE_UNUSED)
{
}
extern void hook_void_void (void);
extern void hook_void_int (int);
-extern void hook_void_charptr (char *);
+extern void hook_void_constcharptr (const char *);
extern void hook_void_FILEptr_constcharptr (FILE *, const char *);
extern void hook_void_tree (tree);
extern void hook_void_tree_treeptr (tree, tree *);
if (DECL_DEFER_OUTPUT (node))
fputs (" defer-output", file);
+ if (DECL_PRESERVE_P (node))
+ fputs (" preserve", file);
+
if (DECL_LANG_FLAG_0 (node))
fputs (" decl_0", file);
if (DECL_LANG_FLAG_1 (node))
#define TARGET_ASM_EXTERNAL_LIBCALL default_external_libcall
#endif
+#ifndef TARGET_ASM_MARK_DECL_PRESERVED
+#define TARGET_ASM_MARK_DECL_PRESERVED hook_void_constcharptr
+#endif
+
#define TARGET_ASM_ALIGNED_INT_OP \
{TARGET_ASM_ALIGNED_HI_OP, \
TARGET_ASM_ALIGNED_SI_OP, \
TARGET_ASM_CAN_OUTPUT_MI_THUNK, \
TARGET_ASM_FILE_START, \
TARGET_ASM_FILE_END, \
- TARGET_ASM_EXTERNAL_LIBCALL}
+ TARGET_ASM_EXTERNAL_LIBCALL, \
+ TARGET_ASM_MARK_DECL_PRESERVED}
/* Scheduler hooks. All of these default to null pointers, which
haifa-sched.c looks for and handles. */
/* Output an assembler pseudo-op to declare a library function name
external. */
void (*external_libcall) (rtx);
+
+ /* Output an assembler directive to mark decl live. This instructs
+ linker to not dead code strip this symbol. */
+ void (*mark_decl_preserved) (const char *);
+
} asm_out;
/* Functions relating to instruction scheduling. */
+2004-08-16 Devang Patel <dpatel@apple.com>
+
+ * gcc.dg/darwin-20040809-1.c: New test.
+
2004-08-16 Joseph S. Myers <jsm@polyomino.org.uk>
* gcc.dg/funcdef-attr-1.c: New test.
--- /dev/null
+/* Test dead code strip support. */
+/* Contributed by Devang Patel <dpatel@apple.com> */
+
+/* { dg-do compile } */
+
+const char my_version_string[] __attribute__((__used__))
+ = "Do not remove this string\n";
+
+ static int
+ __attribute__((__used__))
+ static_debug_routine()
+{
+ int i;
+ i = 42;
+}
+
+int
+main ()
+{
+ return 0;
+}
+
+/* { dg-final { scan-assembler ".no_dead_strip _my_version_string" } } */
+/* { dg-final { scan-assembler ".no_dead_strip _static_debug_routine" } } */
#define DECL_POSSIBLY_INLINED(DECL) \
FUNCTION_DECL_CHECK (DECL)->decl.possibly_inlined
+/* Nonzero for a decl that is decorated using attribute used.
+ This indicates compiler tools that this decl needs to be preserved. */
+#define DECL_PRESERVE_P(DECL) \
+ DECL_CHECK (DECL)->decl.preserve_flag
+
/* Enumerate visibility settings. */
#ifndef SYMBOL_VISIBILITY_DEFINED
#define SYMBOL_VISIBILITY_DEFINED
unsigned lang_flag_7 : 1;
unsigned possibly_inlined : 1;
- /* 15 unused bits. */
+ unsigned preserve_flag: 1;
+ /* 13 unused bits. */
union tree_decl_u1 {
/* In a FUNCTION_DECL for which DECL_BUILT_IN holds, this is
maybe_assemble_visibility (decl);
}
+ if (DECL_PRESERVE_P (decl))
+ targetm.asm_out.mark_decl_preserved (fnname);
+
/* Do any machine/system dependent processing of the function name. */
#ifdef ASM_DECLARE_FUNCTION_NAME
ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
if (TREE_PUBLIC (decl))
maybe_assemble_visibility (decl);
+ if (DECL_PRESERVE_P (decl))
+ targetm.asm_out.mark_decl_preserved (name);
+
/* Output any data that we will need to use the address of. */
if (DECL_INITIAL (decl) == error_mark_node)
reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;