Commit 8e3e233b by Devang Patel Committed by Devang Patel

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
parent 580b3958
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> 2004-08-16 Joseph S. Myers <jsm@polyomino.org.uk>
* c-decl.c (grokdeclarator): Allow for function definition where * c-decl.c (grokdeclarator): Allow for function definition where
......
...@@ -4078,6 +4078,7 @@ handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args), ...@@ -4078,6 +4078,7 @@ handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args),
|| (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node))) || (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node)))
{ {
TREE_USED (node) = 1; TREE_USED (node) = 1;
DECL_PRESERVE_P (node) = 1;
} }
else else
{ {
......
...@@ -82,6 +82,7 @@ extern void darwin_pragma_unused (struct cpp_reader *); ...@@ -82,6 +82,7 @@ extern void darwin_pragma_unused (struct cpp_reader *);
extern void darwin_file_end (void); extern void darwin_file_end (void);
extern void darwin_make_decl_one_only (tree decl); 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. */ /* Expanded by EXTRA_SECTION_FUNCTIONS into varasm.o. */
extern void const_section (void); extern void const_section (void);
......
...@@ -914,6 +914,14 @@ darwin_make_decl_one_only (tree decl) ...@@ -914,6 +914,14 @@ darwin_make_decl_one_only (tree decl)
} }
void 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, machopic_select_section (tree exp, int reloc,
unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
{ {
......
...@@ -799,6 +799,9 @@ objc_section_init (void) \ ...@@ -799,6 +799,9 @@ objc_section_init (void) \
#define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \ #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM) \
sprintf (LABEL, "*%s%ld", PREFIX, (long)(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 /* Since we have a separate readonly data section, define this so that
jump tables end up in text rather than data. */ jump tables end up in text rather than data. */
......
...@@ -6804,6 +6804,12 @@ pseudo-op to declare a library function name external. The name of the ...@@ -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}. library function is given by @var{symref}, which is a @code{symbol_ref}.
@end deftypefn @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}) @defmac ASM_OUTPUT_LABELREF (@var{stream}, @var{name})
A C statement (sans semicolon) to output to the stdio stream A C statement (sans semicolon) to output to the stdio stream
@var{stream} a reference in assembler syntax to a label named @var{stream} a reference in assembler syntax to a label named
......
...@@ -142,7 +142,7 @@ hook_void_tree (tree a ATTRIBUTE_UNUSED) ...@@ -142,7 +142,7 @@ hook_void_tree (tree a ATTRIBUTE_UNUSED)
} }
void void
hook_void_charptr (char *a ATTRIBUTE_UNUSED) hook_void_constcharptr (const char *a ATTRIBUTE_UNUSED)
{ {
} }
......
...@@ -37,7 +37,7 @@ extern bool hook_bool_constcharptr_size_t_false (const char *, size_t); ...@@ -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_void (void);
extern void hook_void_int (int); 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_FILEptr_constcharptr (FILE *, const char *);
extern void hook_void_tree (tree); extern void hook_void_tree (tree);
extern void hook_void_tree_treeptr (tree, tree *); extern void hook_void_tree_treeptr (tree, tree *);
......
...@@ -353,6 +353,9 @@ print_node (FILE *file, const char *prefix, tree node, int indent) ...@@ -353,6 +353,9 @@ print_node (FILE *file, const char *prefix, tree node, int indent)
if (DECL_DEFER_OUTPUT (node)) if (DECL_DEFER_OUTPUT (node))
fputs (" defer-output", file); fputs (" defer-output", file);
if (DECL_PRESERVE_P (node))
fputs (" preserve", file);
if (DECL_LANG_FLAG_0 (node)) if (DECL_LANG_FLAG_0 (node))
fputs (" decl_0", file); fputs (" decl_0", file);
if (DECL_LANG_FLAG_1 (node)) if (DECL_LANG_FLAG_1 (node))
......
...@@ -183,6 +183,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -183,6 +183,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define TARGET_ASM_EXTERNAL_LIBCALL default_external_libcall #define TARGET_ASM_EXTERNAL_LIBCALL default_external_libcall
#endif #endif
#ifndef TARGET_ASM_MARK_DECL_PRESERVED
#define TARGET_ASM_MARK_DECL_PRESERVED hook_void_constcharptr
#endif
#define TARGET_ASM_ALIGNED_INT_OP \ #define TARGET_ASM_ALIGNED_INT_OP \
{TARGET_ASM_ALIGNED_HI_OP, \ {TARGET_ASM_ALIGNED_HI_OP, \
TARGET_ASM_ALIGNED_SI_OP, \ TARGET_ASM_ALIGNED_SI_OP, \
...@@ -223,7 +227,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -223,7 +227,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
TARGET_ASM_CAN_OUTPUT_MI_THUNK, \ TARGET_ASM_CAN_OUTPUT_MI_THUNK, \
TARGET_ASM_FILE_START, \ TARGET_ASM_FILE_START, \
TARGET_ASM_FILE_END, \ 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 /* Scheduler hooks. All of these default to null pointers, which
haifa-sched.c looks for and handles. */ haifa-sched.c looks for and handles. */
......
...@@ -172,6 +172,11 @@ struct gcc_target ...@@ -172,6 +172,11 @@ struct gcc_target
/* Output an assembler pseudo-op to declare a library function name /* Output an assembler pseudo-op to declare a library function name
external. */ external. */
void (*external_libcall) (rtx); 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; } asm_out;
/* Functions relating to instruction scheduling. */ /* 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> 2004-08-16 Joseph S. Myers <jsm@polyomino.org.uk>
* gcc.dg/funcdef-attr-1.c: New test. * gcc.dg/funcdef-attr-1.c: New test.
......
/* 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" } } */
...@@ -2165,6 +2165,11 @@ struct tree_binfo GTY (()) ...@@ -2165,6 +2165,11 @@ struct tree_binfo GTY (())
#define DECL_POSSIBLY_INLINED(DECL) \ #define DECL_POSSIBLY_INLINED(DECL) \
FUNCTION_DECL_CHECK (DECL)->decl.possibly_inlined 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. */ /* Enumerate visibility settings. */
#ifndef SYMBOL_VISIBILITY_DEFINED #ifndef SYMBOL_VISIBILITY_DEFINED
#define SYMBOL_VISIBILITY_DEFINED #define SYMBOL_VISIBILITY_DEFINED
...@@ -2232,7 +2237,8 @@ struct tree_decl GTY(()) ...@@ -2232,7 +2237,8 @@ struct tree_decl GTY(())
unsigned lang_flag_7 : 1; unsigned lang_flag_7 : 1;
unsigned possibly_inlined : 1; unsigned possibly_inlined : 1;
/* 15 unused bits. */ unsigned preserve_flag: 1;
/* 13 unused bits. */
union tree_decl_u1 { union tree_decl_u1 {
/* In a FUNCTION_DECL for which DECL_BUILT_IN holds, this is /* In a FUNCTION_DECL for which DECL_BUILT_IN holds, this is
......
...@@ -1222,6 +1222,9 @@ assemble_start_function (tree decl, const char *fnname) ...@@ -1222,6 +1222,9 @@ assemble_start_function (tree decl, const char *fnname)
maybe_assemble_visibility (decl); 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. */ /* Do any machine/system dependent processing of the function name. */
#ifdef ASM_DECLARE_FUNCTION_NAME #ifdef ASM_DECLARE_FUNCTION_NAME
ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl); ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
...@@ -1562,6 +1565,9 @@ assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED, ...@@ -1562,6 +1565,9 @@ assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
if (TREE_PUBLIC (decl)) if (TREE_PUBLIC (decl))
maybe_assemble_visibility (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. */ /* Output any data that we will need to use the address of. */
if (DECL_INITIAL (decl) == error_mark_node) if (DECL_INITIAL (decl) == error_mark_node)
reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0; reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment