More code to support new libgloss features. This one lets the linker
leave out the call to exit() in crt0 (and thus all the exit() code
also) if main() doesn't exit. Committed.
* config/msp430/msp430.h (LIB_SPEC): Add -lcrt
* config/msp430/msp430.md (msp430_refsym_need_exit): New.
* config/msp430/msp430.c (msp430_expand_epilogue): Call it
whenever main() has an epilogue.
Index: config/msp430/msp430.md
===================================================================
--- config/msp430/msp430.md (revision 207333)
+++ config/msp430/msp430.md (working copy)
@@ -42,12 +42,14 @@
UNS_DINT
UNS_EINT
UNS_PUSH_INTR
UNS_POP_INTR
UNS_BIC_SR
UNS_BIS_SR
+
+ UNS_REFSYM_NEED_EXIT
])
(include "predicates.md")
(include "constraints.md")
(define_mode_iterator QHI [QI HI PSI])
@@ -935,12 +937,20 @@
(define_insn "epilogue_start_marker"
[(unspec_volatile [(const_int 0)] UNS_EPILOGUE_START_MARKER)]
""
"; start of epilogue"
)
+;; This makes the linker add a call to exit() after the call to main()
+;; in crt0
+(define_insn "msp430_refsym_need_exit"
+ [(unspec_volatile [(const_int 0)] UNS_REFSYM_NEED_EXIT)]
+ ""
+ ".refsym\t__crt0_call_exit"
+ )
+
;;------------------------------------------------------------
;; Jumps
(define_expand "call"
[(call:HI (match_operand 0 "")
(match_operand 1 ""))]
Index: config/msp430/msp430.c
===================================================================
--- config/msp430/msp430.c (revision 207333)
+++ config/msp430/msp430.c (working copy)
@@ -1426,12 +1426,15 @@ msp430_expand_epilogue (int is_eh)
break;
}
}
emit_insn (gen_epilogue_start_marker ());
+ if (cfun->decl && strcmp (IDENTIFIER_POINTER (DECL_NAME (cfun->decl)),
"main") == 0)
+ emit_insn (gen_msp430_refsym_need_exit ());
+
if (is_wakeup_func ())
/* Clear the SCG1, SCG0, OSCOFF and CPUOFF bits in the saved copy of the
status register current residing on the stack. When this function
executes its RETI instruction the SR will be updated with this saved
value, thus ensuring that the processor is woken up from any low power
state in which it may be residing. */
Index: config/msp430/msp430.h
===================================================================
--- config/msp430/msp430.h (revision 207333)
+++ config/msp430/msp430.h (working copy)
@@ -65,12 +65,13 @@ extern bool msp430x;
#undef LIB_SPEC
#define LIB_SPEC " \
--start-group \
-lc \
-lgcc \
+-lcrt \
%{msim:-lsim} \
%{!msim:-lnosys} \
--end-group \
%{!T*:%{!msim:%{mmcu=*:--script=%*.ld}}} \
%{!T*:%{!msim:%{!mmcu=*:%Tmsp430.ld}}} \
%{!T*:%{msim:%{mlarge:%Tmsp430xl-sim.ld}%{!mlarge:%Tmsp430-sim.ld}}} \