1 diff -Naurp gcc/config/avr/avr.c gcc/config/avr/avr.c
2 --- gcc/config/avr/avr.c 2011-06-09 15:41:06.000000000 -0500
3 +++ gcc/config/avr/avr.c 2011-06-09 15:46:03.000000000 -0500
4 @@ -81,6 +81,12 @@ static rtx avr_function_value (const_tre
5 static void avr_insert_attributes (tree, tree *);
6 static void avr_asm_init_sections (void);
7 static unsigned int avr_section_type_flags (tree, const char *, int);
8 +static void avr_asm_named_section (const char *name, unsigned int flags, tree decl);
9 +/* Track if code will use .bss and/or .data */
10 +static int avr_need_clear_bss_p = 0;
11 +static int avr_need_copy_data_p = 0;
12 +static void avr_output_data_section_asm_op (const void*);
13 +static void avr_output_bss_section_asm_op (const void*);
15 static void avr_reorg (void);
16 static void avr_asm_out_ctor (rtx, int);
17 @@ -6102,6 +6108,54 @@ avr_output_progmem_section_asm_op (const
18 fprintf (asm_out_file, "\t.p2align 1\n");
21 +/* ASM_OUTPUT_COMMON */
22 +/* Track need of __do_clear_bss */
25 +avr_asm_output_common (FILE *stream, const char *name,
26 + unsigned HOST_WIDE_INT size,
27 + unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
29 + avr_need_clear_bss_p = 1;
30 + fputs ("\t.comm ", stream);
31 + assemble_name (stream, name);
32 + fprintf (stream, ",%lu,1\n", (unsigned long) size);
35 +/* ASM_OUTPUT_LOCAL */
36 +/* Track need of __do_clear_bss */
39 +avr_asm_output_local (FILE *stream, const char *name,
40 + unsigned HOST_WIDE_INT size,
41 + unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
43 + avr_need_clear_bss_p = 1;
44 + fputs ("\t.lcomm ", stream);
45 + assemble_name (stream, name);
46 + fprintf (stream, ",%d\n", (int) size);
49 +/* Unnamed section callback to track need of __do_copy_data */
52 +avr_output_data_section_asm_op (const void *data)
54 + avr_need_copy_data_p = 1;
55 + /* Dispatch to default */
56 + output_section_asm_op (data);
59 +/* Unnamed section callback to track need of __do_clear_bss */
62 +avr_output_bss_section_asm_op (const void *data)
64 + avr_need_clear_bss_p = 1;
65 + /* Dispatch to default */
66 + output_section_asm_op (data);
69 /* Implement TARGET_ASM_INIT_SECTIONS. */
72 @@ -6111,6 +6165,27 @@ avr_asm_init_sections (void)
73 avr_output_progmem_section_asm_op,
75 readonly_data_section = data_section;
77 + data_section->unnamed.callback = avr_output_data_section_asm_op;
78 + bss_section->unnamed.callback = avr_output_bss_section_asm_op;
81 +/* TARGET_ASM_NAMED_SECTION */
82 +/* Track need of __do_clear_bss, __do_copy_data for named sections */
85 +avr_asm_named_section (const char *name, unsigned int flags, tree decl)
87 + if (!avr_need_copy_data_p)
88 + avr_need_copy_data_p =
89 + (0 == strncmp (name, ".data", 5)
90 + || 0 == strncmp (name, ".rodata", 7)
91 + || 0 == strncmp (name, ".gnu.linkonce.", 14));
93 + if (!avr_need_clear_bss_p)
94 + avr_need_clear_bss_p = (0 == strncmp (name, ".bss", 4));
96 + default_elf_asm_named_section (name, flags, decl);
100 @@ -6152,12 +6227,6 @@ avr_file_start (void)
101 AVR_TINY ? fputs ("__tmp_reg__ = 16\n"
102 "__zero_reg__ = 17\n", asm_out_file) : fputs ("__tmp_reg__ = 0\n"
103 "__zero_reg__ = 1\n", asm_out_file);
105 - /* FIXME: output these only if there is anything in the .data / .bss
106 - sections - some code size could be saved by not linking in the
107 - initialization code from libgcc if one or both sections are empty. */
108 - fputs ("\t.global __do_copy_data\n", asm_out_file);
109 - fputs ("\t.global __do_clear_bss\n", asm_out_file);
112 /* Outputs to the stdio stream FILE some
113 @@ -6166,6 +6235,16 @@ avr_file_start (void)
117 + /* Output these only if there is anything in the
118 + .data* / .rodata* / .gnu.linkonce.* resp. .bss*
119 + input section(s) - some code size can be saved by not
120 + linking in the initialization code from libgcc if resp.
121 + sections are empty. */
122 + if (avr_need_copy_data_p)
123 + fputs (".global __do_copy_data\n", asm_out_file);
125 + if (avr_need_clear_bss_p)
126 + fputs (".global __do_clear_bss\n", asm_out_file);
129 /* Choose the order in which to allocate hard registers for
130 diff -Naurp gcc/config/avr/avr.h gcc/config/avr/avr.h
131 --- gcc/config/avr/avr.h 2011-06-09 14:30:33.000000000 -0500
132 +++ gcc/config/avr/avr.h 2011-06-09 15:46:03.000000000 -0500
133 @@ -562,7 +562,7 @@ do { \
134 #define ASM_APP_OFF "/* #NOAPP */\n"
136 /* Switch into a generic section. */
137 -#define TARGET_ASM_NAMED_SECTION default_elf_asm_named_section
138 +#define TARGET_ASM_NAMED_SECTION avr_asm_named_section
139 #define TARGET_ASM_INIT_SECTIONS avr_asm_init_sections
141 #define ASM_OUTPUT_ASCII(FILE, P, SIZE) gas_output_ascii (FILE,P,SIZE)
142 @@ -570,21 +570,13 @@ do { \
143 #define IS_ASM_LOGICAL_LINE_SEPARATOR(C, STR) ((C) == '\n' || ((C) == '$'))
145 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED) \
147 - fputs ("\t.comm ", (STREAM)); \
148 - assemble_name ((STREAM), (NAME)); \
149 - fprintf ((STREAM), ",%lu,1\n", (unsigned long)(SIZE)); \
151 + avr_asm_output_common (STREAM, NAME, SIZE, ROUNDED)
153 #define ASM_OUTPUT_BSS(FILE, DECL, NAME, SIZE, ROUNDED) \
154 asm_output_bss ((FILE), (DECL), (NAME), (SIZE), (ROUNDED))
156 #define ASM_OUTPUT_LOCAL(STREAM, NAME, SIZE, ROUNDED) \
158 - fputs ("\t.lcomm ", (STREAM)); \
159 - assemble_name ((STREAM), (NAME)); \
160 - fprintf ((STREAM), ",%d\n", (int)(SIZE)); \
162 + avr_asm_output_local (STREAM, NAME, SIZE, ROUNDED)
166 diff -Naurp gcc/config/avr/avr-protos.h gcc/config/avr/avr-protos.h
167 --- gcc/config/avr/avr-protos.h 2011-06-09 14:30:33.000000000 -0500
168 +++ gcc/config/avr/avr-protos.h 2011-06-09 15:46:03.000000000 -0500
169 @@ -35,6 +35,9 @@ extern int avr_simple_epilogue (void);
170 extern void gas_output_limited_string (FILE *file, const char *str);
171 extern void gas_output_ascii (FILE *file, const char *str, size_t length);
172 extern int avr_hard_regno_rename_ok (unsigned int, unsigned int);
173 +extern void avr_asm_output_common (FILE *stream, const char *name, unsigned HOST_WIDE_INT size, unsigned HOST_WIDE_INT rounded);
174 +extern void avr_asm_output_local (FILE *stream, const char *name, unsigned HOST_WIDE_INT size, unsigned HOST_WIDE_INT rounded);
176 extern rtx avr_return_addr_rtx (int count, const_rtx tem);