[commit: ghc] master: Run ctors initializers backwards, see #5435. (85a9e24)

git at git.haskell.org git at git.haskell.org
Mon Sep 16 08:53:35 CEST 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/85a9e2468dc74b9e5ccde0dd61be86219fd323a2/ghc

>---------------------------------------------------------------

commit 85a9e2468dc74b9e5ccde0dd61be86219fd323a2
Author: Edward Z. Yang <ezyang at mit.edu>
Date:   Sun Sep 15 23:53:01 2013 -0700

    Run ctors initializers backwards, see #5435.
    
    Signed-off-by: Edward Z. Yang <ezyang at mit.edu>


>---------------------------------------------------------------

85a9e2468dc74b9e5ccde0dd61be86219fd323a2
 rts/Linker.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/rts/Linker.c b/rts/Linker.c
index 49c7d6c..e2c4081 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -4218,11 +4218,11 @@ ocRunInit_PEi386 ( ObjectCode *oc )
         char *secname = cstring_from_section_name(sectab_i->Name, strtab);
         if (0 == strcmp(".ctors", (char*)secname)) {
             UChar *init_startC = (UChar*)(oc->image) + sectab_i->PointerToRawData;
-            init_t *init = (init_t*)init_startC;
-            init_t *init_end = (init_t*)(init_startC + sectab_i->SizeOfRawData);
-            // I heard that .ctors might need to be run backwards, but
-            // if that is true then the MinGW toolchain ignores that.
-            for (; init < init_end; init++) {
+            init_t *init_start, *init_end, *init;
+            init_start = (init_t*)init_startC;
+            init_end = (init_t*)(init_startC + sectab_i->SizeOfRawData);
+            // ctors are run *backwards*!
+            for (init = init_end - 1; init >= init_start; init--) {
                 (*init)(argc, argv, envv);
             }
         }




More information about the ghc-commits mailing list