summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-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:
re>e25474154 ^
4de84024e ^
367abca38 ^

4de84024e ^

e25474154 ^
4de84024e ^
e25474154 ^
902bf0587 ^

4de84024e ^



e25474154 ^



4de84024e ^
e25474154 ^

4de84024e ^


e25474154 ^
4de84024e ^


e25474154 ^





e25474154 ^
4de84024e ^
e25474154 ^
4de84024e ^

e25474154 ^
4de84024e ^

e25474154 ^







4de84024e ^
e25474154 ^






4de84024e ^
e25474154 ^



4de84024e ^
e25474154 ^
4de84024e ^








2df9b442c ^
4de84024e ^
d9d82fb0a ^
083d4f470 ^
28d9398de ^
d9d82fb0a ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110