diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2014-08-13 20:17:16 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2014-08-13 20:17:16 +0200 |
commit | 1d19c9525e3b6453b3402cee3ce59b5780782e75 (patch) | |
tree | 7b46a1582133f40ee2617bae397eaad8b22bb2ce /compiler | |
parent | 32a5d4baf0e4930dbb9da47b060784a948bc2bee (diff) | |
parent | 15734009ca9077cfc8c4139b8258b2db2d7492dd (diff) | |
download | Nim-1d19c9525e3b6453b3402cee3ce59b5780782e75.tar.gz |
Merge pull request #1400 from rbehrends/fix-stackscan
More robust implementation for finding the beginning of the stack.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/cgen.nim | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index b930bea8d..41f380d1b 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -954,8 +954,7 @@ proc genMainProc(m: BModule) = "\tsystemInit();$N" & "$1" & "$2" & - "$3" & - "$4" + "$3" MainProcs = "\tNimMain();$N" @@ -963,10 +962,19 @@ 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, NimMain)(void) {$N" & + "N_CDECL(void, NimMainInner)(void) {$N" & "\tPreMain();$N" & "$1" & + "}$N$N" & + "N_CDECL(void, NimMain)(void) {$N" & + "\tvoid (*volatile inner)();$N" & + "\tinner = NimMainInner;$N" & + "$2" & + "\t(*inner)();$N" & "}$N$N" PosixNimMain = @@ -1034,14 +1042,15 @@ proc genMainProc(m: BModule) = if optEndb in gOptions: gBreakpoints.app(m.genFilenames) - let initStackBottomCall = if emulatedThreadVars() or - platform.targetOS == osStandalone: "".toRope - else: ropecg(m, "\t#initStackBottom();$N") + let initStackBottomCall = + if emulatedThreadVars() or + 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, initStackBottomCall, gBreakpoints, otherModsInit]) + mainDatInit, gBreakpoints, otherModsInit]) - appcg(m, m.s[cfsProcs], nimMain, [mainModInit, toRope(m.labels)]) + appcg(m, m.s[cfsProcs], nimMain, [mainModInit, initStackBottomCall, toRope(m.labels)]) if optNoMain notin gGlobalOptions: appcg(m, m.s[cfsProcs], otherMain, []) |