summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2014-08-14 09:16:26 +0200
committerAndreas Rumpf <rumpf_a@web.de>2014-08-14 09:16:26 +0200
commitd8f6a2adcb980efcd75977ca8b9235fab3676ebd (patch)
tree6dd16cf5dff6b69faeda85e64cfe997b30fad638
parent1a7be4c66f90e63995eec0c27efdf85fa454c130 (diff)
parentd59b9a21689d82d424b7be0d699ccbf3ba538d31 (diff)
downloadNim-d8f6a2adcb980efcd75977ca8b9235fab3676ebd.tar.gz
Merge pull request #1481 from rbehrends/fix-stackscan2
Fix stack bottom initialization for non-main modules.
-rw-r--r--compiler/cgen.nim22
1 files changed, 15 insertions, 7 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 68431bd96..315b55801 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -949,12 +949,23 @@ proc genFilenames(m: BModule): PRope =
 
 proc genMainProc(m: BModule) =
   const 
+    # The use of a volatile function pointer to call Pre/NimMainInner
+    # prevents inlining of the NimMainInner function and dependent
+    # functions, which might otherwise merge their stack frames.
     PreMainBody =
-      "\tsystemDatInit();$N" &
+      "void PreMainInner() {$N" &
       "\tsystemInit();$N" &
       "$1" &
       "$2" &
-      "$3"
+      "$3" &
+      "}$N$N" &
+      "void PreMain() {$N" &
+      "\tvoid (*volatile inner)();$N" &
+      "\tsystemDatInit();$N" &
+      "\tinner = PreMainInner;$N" &
+      "$4" &
+      "\t(*inner)();$N" &
+      "}$N$N"
 
     MainProcs =
       "\tNimMain();$N"
@@ -962,9 +973,6 @@ proc genMainProc(m: BModule) =
     MainProcsWithResult =
       MainProcs & "\treturn nim_program_result;$N"
 
-    # The use of a volatile function pointer to call NimMainInner
-    # prevents inlining of the NimMainInner function and dependent
-    # functions, which might otherwise merge their stack frames.
     NimMainBody =
       "N_CDECL(void, NimMainInner)(void) {$N" &
         "$1" &
@@ -1047,8 +1055,8 @@ proc genMainProc(m: BModule) =
       platform.targetOS == osStandalone: "".toRope
     else: ropecg(m, "\t#initStackBottomWith((void *)&inner);$N")
   inc(m.labels)
-  appcg(m, m.s[cfsProcs], "void PreMain() {$N" & PreMainBody & "}$N$N", [
-    mainDatInit, gBreakpoints, otherModsInit])
+  appcg(m, m.s[cfsProcs], PreMainBody, [
+    mainDatInit, gBreakpoints, otherModsInit, initStackBottomCall])
 
   appcg(m, m.s[cfsProcs], nimMain, [mainModInit, initStackBottomCall, toRope(m.labels)])
   if optNoMain notin gGlobalOptions: