Hi, Chris
Chris Liechti wrote:
i may have a clean solution now.
uninitialized variables are reserved in assembler using .comm. the
linker(?) then puts these in the .bss section but gcc does not know that
so it did not output the reference to _do_clear_bss. i've now added the
reference to the function also for variables that are put into .comm
the original code from you also works if -fno-common is used. in that
case is gcc directly emitting these variables to .bss, where the
reference to the function was correctly placed.
anyways, doing the same for .bss and .comm seems reasonable to me.
I got last sources from cvs today. Your solution works fine, but there
is a problem in my code. If --gc-sections with --fdata-sections removes
all variables from .data or .bss section, .global __do_clear_bss or
__do_copy_data remains in source file and causes __do_clear_bss or
__do_copy_data functions to be linked to output file with segmend size =
0, and it causes 64K block to be zeroed or copied. The only solution I
see is to check segment size to 0 before cycle, so I removed .global
__do_xxx from sections definitions and added it to _reset_vector__, so
copy/clear cycles linked always together with library _reset_vector__.
If user project have no .bss or .data variables, user can define empty
copy|clear function:
__attribute__((__naked__, __section__(".init4"))) void __do_clear_bss()
{
}
patch attached.
Sergey.
diff -ur gcc-3.2.3.orig/gcc/config/msp430/libgcc.S
gcc-3.2.3/gcc/config/msp430/libgcc.S
--- gcc-3.2.3.orig/gcc/config/msp430/libgcc.S 2008-05-30 18:00:51.578125000
+0300
+++ gcc-3.2.3/gcc/config/msp430/libgcc.S 2008-05-30 18:05:22.453125000
+0300
@@ -568,6 +568,8 @@
; .global __init_stack
.global __low_level_init
+ .global __do_copy_data
+ .global __do_clear_bss
.global __jump_to_main
.endfunc
@@ -582,7 +584,6 @@
.global __init_stack
.weak __init_stack
- .extern __stack
.func __init_stack
@@ -620,21 +621,21 @@
.global __do_copy_data
.weak __do_copy_data
- .extern __data_load_start
- .extern __data_start
- .extern __data_size
.func __do_copy_data
__do_copy_data:
mov #__data_size, r15
+ tst r15
+ jz .L__copy_data_end
.L__copy_data_loop:
decd r15
mov.w __data_load_start(r15), __data_start(r15) ; data section is
word-aligned, so word transfer is acceptable
jne .L__copy_data_loop
+.L__copy_data_end:
.endfunc
-#endif /* defined(L__do_copy_data) */
+#endif /* defined(L_copy_data) */
#if defined(L_clear_bss)
/*****************************************************************
@@ -645,17 +646,18 @@
.global __do_clear_bss
.weak __do_clear_bss
- .extern __bss_start
- .extern __bss_size
.func __do_clear_bss
__do_clear_bss:
mov #__bss_size, r15
+ tst r15
+ jz .L__clear_bss_end
.L__clear_bss_loop:
dec r15
clr.b __bss_start(r15)
jne .L__clear_bss_loop
+.L__clear_bss_end:
.endfunc
#endif /* defined(L_clear_bss) */
@@ -668,12 +670,10 @@
.section .init6, "ax", @progbits
.global __do_global_ctors
.weak __do_global_ctors
- .extern __ctors_start
- .extern __ctors_end
.func __do_global_ctors
+ .global __init_stack ; stack has to be set before constructors
calling
- mov #__stack, r1 ; can be removed, if stack initialization in
.init2 uncommented
__do_global_ctors:
mov #__ctors_start, r11
@@ -695,7 +695,6 @@
.global __jump_to_main
.weak __jump_to_main
- .extern _main
.func __jump_to_main
@@ -728,8 +727,6 @@
.section .fini6,"ax",@progbits
.global __do_global_dtors
.weak __do_global_dtors
- .extern __dtors_start
- .extern __dtors_end
.func _dtors
diff -ur gcc-3.2.3.orig/gcc/config/msp430/msp430.h
gcc-3.2.3/gcc/config/msp430/msp430.h
--- gcc-3.2.3.orig/gcc/config/msp430/msp430.h 2008-05-30 18:00:51.578125000
+0300
+++ gcc-3.2.3/gcc/config/msp430/msp430.h 2008-05-30 17:56:59.890625000
+0300
@@ -1752,7 +1752,7 @@
operation that should precede instructions and read-only data.
Normally `"\t.text"' is right. */
-#define DATA_SECTION_ASM_OP "\t.global\t__do_copy_data\n\t.data"
+#define DATA_SECTION_ASM_OP "\t.data"
/* A C expression whose value is a string containing the assembler
operation to identify the following data as writable initialized
data. Normally `"\t.data"' is right. */
@@ -2086,7 +2086,6 @@
if (IN_NAMED_SECTION (DECL)) \
{ \
/* case where -fdata-sections is specified */ \
- fputs ("\t.global\t__do_clear_bss\n", (FILE)); \
named_section (DECL, NULL, 0); \
ASM_GLOBALIZE_LABEL (FILE, NAME); \
ASM_OUTPUT_ALIGN (FILE, floor_log2 (ALIGN / BITS_PER_UNIT)); \
@@ -2097,7 +2096,7 @@
else \
{ \
/* default case */ \
- fputs ("\t.global\t__do_clear_bss\n\t.comm ", (FILE)); \
+ fputs ("\t.comm ", (FILE)); \
assemble_name ((FILE), (NAME)); \
fprintf ((FILE), ",%d%s", (SIZE), (SIZE)>1?",2\n":"\n"); \
} \
@@ -2114,10 +2113,7 @@
if(*p == '*' || *p == '@' ) p++; \
if(*p >= '0' && *p <= '9' ) break; \
if (IN_NAMED_SECTION (DECL)) \
- { \
- fputs ("\t.global\t__do_clear_bss\n", (FILE)); \
- named_section (DECL, NULL, 0); \
- } \
+ named_section (DECL, NULL, 0); \
else \
bss_section (); \
\
@@ -2138,10 +2134,7 @@
if(*p == '*' || *p == '@' ) p++; \
if(*p >= '0' && *p <= '9' ) break; \
if ((DECL) != NULL && IN_NAMED_SECTION (DECL)) \
- { \
- fputs ("\t.global\t__do_clear_bss\n", (FILE)); \
- named_section (DECL, NULL, 0); \
- } \
+ named_section (DECL, NULL, 0); \
else \
bss_section (); \
\
@@ -2151,7 +2144,7 @@
} \
while (0)
-#define BSS_SECTION_ASM_OP "\t.global\t__do_clear_bss\n\t.section\t.bss"
+#define BSS_SECTION_ASM_OP "\t.section\t.bss"
/* If defined, a C expression whose value is a string containing the
assembler operation to identify the following data as
uninitialized global data. If not defined, and neither