From: Devang Patel Date: Mon, 16 Aug 2004 20:54:43 +0000 (-0700) Subject: c-common.c (handle_used_attribute): Set DECL_PRESERVE_P. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8e3e233be0d6e50fcfc1da2c81ad5eb51d974baa;p=gcc.git c-common.c (handle_used_attribute): Set DECL_PRESERVE_P. * 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 991177702ab..30928e1f89a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,23 @@ +2004-08-16 Devang Patel + + * 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 * c-decl.c (grokdeclarator): Allow for function definition where diff --git a/gcc/c-common.c b/gcc/c-common.c index f66341d883a..4c7eb21e049 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -4078,6 +4078,7 @@ handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args), || (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node))) { TREE_USED (node) = 1; + DECL_PRESERVE_P (node) = 1; } else { diff --git a/gcc/config/darwin-protos.h b/gcc/config/darwin-protos.h index d2d90049264..a5ae08e2499 100644 --- a/gcc/config/darwin-protos.h +++ b/gcc/config/darwin-protos.h @@ -82,6 +82,7 @@ extern void darwin_pragma_unused (struct cpp_reader *); 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); diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 9f47dc4607c..14101f6c72e 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -913,6 +913,14 @@ darwin_make_decl_one_only (tree decl) 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) diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 488081bd3f4..311c1611459 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -799,6 +799,9 @@ objc_section_init (void) \ #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. */ diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index f43e0358d2a..03e0c4a17b2 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -6804,6 +6804,12 @@ pseudo-op to declare a library function name external. The name of the 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 diff --git a/gcc/hooks.c b/gcc/hooks.c index 1fafe1f12f8..111b9dcb253 100644 --- a/gcc/hooks.c +++ b/gcc/hooks.c @@ -142,7 +142,7 @@ hook_void_tree (tree a ATTRIBUTE_UNUSED) } void -hook_void_charptr (char *a ATTRIBUTE_UNUSED) +hook_void_constcharptr (const char *a ATTRIBUTE_UNUSED) { } diff --git a/gcc/hooks.h b/gcc/hooks.h index fea78c79e87..6b5fda8f9f2 100644 --- a/gcc/hooks.h +++ b/gcc/hooks.h @@ -37,7 +37,7 @@ extern bool hook_bool_constcharptr_size_t_false (const char *, size_t); 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 *); diff --git a/gcc/print-tree.c b/gcc/print-tree.c index 3944842635d..829e2c9f302 100644 --- a/gcc/print-tree.c +++ b/gcc/print-tree.c @@ -353,6 +353,9 @@ print_node (FILE *file, const char *prefix, tree node, int indent) 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)) diff --git a/gcc/target-def.h b/gcc/target-def.h index 7180a3e1f67..15dc0c94020 100644 --- a/gcc/target-def.h +++ b/gcc/target-def.h @@ -183,6 +183,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #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, \ @@ -223,7 +227,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 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. */ diff --git a/gcc/target.h b/gcc/target.h index ad37161bc48..1611f2a61dc 100644 --- a/gcc/target.h +++ b/gcc/target.h @@ -172,6 +172,11 @@ struct gcc_target /* 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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 80561d3ad0d..319fe1da9ec 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-08-16 Devang Patel + + * gcc.dg/darwin-20040809-1.c: New test. + 2004-08-16 Joseph S. Myers * gcc.dg/funcdef-attr-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/darwin-20040812-1.c b/gcc/testsuite/gcc.dg/darwin-20040812-1.c new file mode 100644 index 00000000000..9b2b79429c6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/darwin-20040812-1.c @@ -0,0 +1,24 @@ +/* Test dead code strip support. */ +/* Contributed by Devang Patel */ + +/* { 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" } } */ diff --git a/gcc/tree.h b/gcc/tree.h index a0cc1361133..ff03d9c7aa6 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -2165,6 +2165,11 @@ struct tree_binfo GTY (()) #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 @@ -2232,7 +2237,8 @@ struct tree_decl GTY(()) 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 diff --git a/gcc/varasm.c b/gcc/varasm.c index afbde92f11e..5dbcb228038 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -1222,6 +1222,9 @@ assemble_start_function (tree decl, const char *fnname) 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); @@ -1562,6 +1565,9 @@ assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED, 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;