This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Always provide exit() & friends prototypes.


Sergei Organov wrote:

Yeah, I see. I'll first try the CYGSEM_LIBC_STARTUP_MAIN_THREAD that I've somehow missed, then we will see...

It's possible you might have to enable CYGSEM_LIBC_STARTUP_MAIN_OTHER as well, I'm not sure. Let me know about any problems (preferably with patches ;-)).


It seems that GCC uses atexit() facility to register destructors for
static objects found inside functions, like this:

void foo() {
  [...]
  static SomeClassWithCtor_Dtor var;
  [...]
}
As 'var' should be initialized at the first pass through the function,
GCC registers a function calling destructor with atexit() after
constructor of the variable is actually called.

Interesting - it doesn't do this normally. I believe this may be a property of the toolchain. I do vaguely recall there's some option within GCC (i.e. when you do a GCC port) for whether to use a .dtor section for global destructors, or atexit. So far, it's always been .dtor.


Even if user app is plain C, silently calling atexit() seems to be
dangerous as user application code might still register something with
atexit() at startup.

True.


Unfortunately we have to have a default main, otherwise in our many
templates and configurations with the libc_startup package included,
any eCos test programs that don't use main() will not link.

Yeah, I see. Maybe Cyg_Thread::self()->suspend() in the main() when there is kernel there will help.

That's a good idea. Patch below, and applied.


Jifl

Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/startup/current/ChangeLog,v
retrieving revision 1.10
diff -u -5 -p -r1.10 ChangeLog
--- ChangeLog   11 Sep 2007 16:50:54 -0000      1.10
+++ ChangeLog   5 Oct 2007 17:41:22 -0000
@@ -1,5 +1,10 @@
+2007-10-05  Jonathan Larmour  <jifl@eCosCentric.com>
+
+       * src/main.cxx (main): Suspend main thread, rather than exit.
+       Thanks to Sergei Organov for the idea.
+
 2007-09-11  Andrew Lunn  <andrew.lunn@ascom.ch>

* src/cstartup.cxx: Change the INIT priority of
cyg_libc_startup_obj so that it is always called after the thread
has been constructed. Reported by taiyun@sunnorth.com.cn
Index: src/main.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/startup/current/src/main.cxx,v
retrieving revision 1.3
diff -u -5 -p -r1.3 main.cxx
--- src/main.cxx 23 May 2002 23:07:12 -0000 1.3
+++ src/main.cxx 5 Oct 2007 17:41:22 -0000
@@ -64,10 +64,16 @@


 #include <cyg/infra/cyg_type.h>    // Common type definitions and support
 #include <cyg/infra/cyg_trac.h>    // Common tracing support
 #include <cyg/infra/cyg_ass.h>     // Common assertion support

+#ifdef CYGPKG_KERNEL
+# include <pkgconf/kernel.h>       // kernel configuration
+# include <cyg/kernel/thread.hxx>  // For thread suspend
+# include <cyg/kernel/thread.inl>
+#endif
+
 // FUNCTION PROTOTYPES

 // We provide a weakly named main to allow this to link if the user
 // doesn't provide their own main. This isn't strictly good behaviour,
 // but if the user wants good performance then of _course_ they should
@@ -101,10 +107,14 @@ main( int argc, char *argv[] )
     // evidently the user didn't supply one - which can't be right. So we
     // assume that they have useful code to run in cyg_user_start() instead.
     // Its better than just exiting
 #ifndef CYGPKG_KERNEL
     cyg_user_start();
+#else
+    // Otherwise we suspend ourselves. This prevents problems caused by
+    // running atexit() handlers.
+    Cyg_Thread::self()->suspend();
 #endif

     CYG_REPORT_RETVAL(0);
     return 0; // some CPUs have 0 hard-wired - faster than a reg
 } // main()


-- eCosCentric Limited http://www.eCosCentric.com/ The eCos experts Barnwell House, Barnwell Drive, Cambridge, UK. Tel: +44 1223 245571 Registered in England and Wales: Reg No 4422071. >>>> Visit us on stand 810 at The Embedded Systems Show 2007, NEC <<<< >>>> Oct 17-18 Birmingham, UK http://www.edaexhibitions.com/ess/ <<<< ------["The best things in life aren't things."]------ Opinions==mine


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]