delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2006/10/16/13:44:55

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Message-ID: <4533BF1A.5080806@drv.nu>
Date: Mon, 16 Oct 2006 13:19:22 -0400
From: Daniel Verkamp <daniel AT drv DOT nu>
User-Agent: Thunderbird 1.5.0.7 (Windows/20060909)
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Global constructor order patch
Reply-To: djgpp-workers AT delorie DOT com

This is a multi-part message in MIME format.
--------------030900070007060105090208
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Attached is a patch for DJGPP to execute constructors in LIFO order, to 
match other platforms, like MinGW (gccmain.c) and gcc on Linux 
(libgcc.c/crtstuff.c).  On those platforms, the __CTOR_LIST__ is always 
processed backwards.  Destructor order as implemented in DJGPP now is 
correct (FIFO).

The fix is by Andre Victor (av1ctor AT yahoo DOT com DOT br) of the FreeBASIC 
project - we stumbled across this problem while working on runtime 
initialization problems (the FB runtime's constructor must run before 
any user constructors).

Thanks,
-- Daniel Verkamp <daniel AT drv DOT nu>


--------------030900070007060105090208
Content-Type: text/plain;
 name="djgpp-ctor-order.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="djgpp-ctor-order.patch"

--- crt0/_main.c.orig	2006-10-16 13:15:38.250000000 -0400
+++ crt0/_main.c	2006-10-16 12:22:37.000000000 -0400
@@ -14,6 +14,9 @@
   if (been_there_done_that == __bss_count)
     return;
   been_there_done_that = __bss_count;
-  for (i=0; i<djgpp_last_ctor-djgpp_first_ctor; i++)
+  
+  /* fixed: the global constructors should be called in LIFO order, see libgcc2.c or crtstuff.c */
+  
+  for (i=(djgpp_last_ctor-djgpp_first_ctor)-1; i>=0; i--)
     djgpp_first_ctor[i]();
 }

--------------030900070007060105090208--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019