Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#9741 closed bug (fixed)

Interpreter stack checks are not quite right

Reported by: simonpj Owned by: simonmar
Priority: highest Milestone: 7.10.1
Component: Compiler Version: 7.8.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

In my experimental branch, I'm getting this failure on tests/ghci/should_run/ghcirun002:

<interactive>: internal error: ASSERTION FAILED: file rts/Interpreter.c, line 778

    (GHC version 7.9.20141029 for x86_64_unknown_linux)

The ASSERTION failure means that I must have -DDEBUG in my RTS; I have no idea why. My validate.mk looks like this:

GhcStage1HcOpts += -ticky  -DDEBUG
GhcStage2HcOpts +=  -ticky
GhcLibHcOpts +=  -Wwarn -ticky
SplitObjs       = YES

That is mysterious but not the main point. Somehow we are getting a stack overflow in the interpreter.

So I added this line to Interpreter on line 772:

        debugBelch ( "Interpreter Sp=%p SpLim=%p headroom = %ld\n\n", Sp, SpLim, Sp-SpLim ) ;

Sure enough, when running test ghcirun002 on HEAD, I get this output

Interpreter Sp=0x7f42649d0228 SpLim=0x7f42649d00c0 headroom = 45
Interpreter Sp=0x7f42649d0228 SpLim=0x7f42649d00c0 headroom = 45
Interpreter Sp=0x7f42649d0228 SpLim=0x7f42649d00c0 headroom = 45
Interpreter Sp=0x7f42649d0238 SpLim=0x7f42649d00c0 headroom = 47
Interpreter Sp=0x7f42649d0228 SpLim=0x7f42649d00c0 headroom = 45
Interpreter Sp=0x7f42649d0228 SpLim=0x7f42649d00c0 headroom = 45
Interpreter Sp=0x7f42649d0228 SpLim=0x7f42649d00c0 headroom = 45
Interpreter Sp=0x7f42649d0228 SpLim=0x7f42649d00c0 headroom = 45
Interpreter Sp=0x7f42649d0228 SpLim=0x7f42649d00c0 headroom = 45
Interpreter Sp=0x7f42649d0210 SpLim=0x7f42649d00c0 headroom = 42
Interpreter Sp=0x7f4264b40230 SpLim=0x7f4264b400c0 headroom = 46
Interpreter Sp=0x7f42649e1230 SpLim=0x7f42649e10c0 headroom = 46
Interpreter Sp=0x7f42649d9230 SpLim=0x7f42649d90c0 headroom = 46
Interpreter Sp=0x7f4264182230 SpLim=0x7f42641820c0 headroom = 46
Interpreter Sp=0x7f426417a230 SpLim=0x7f426417a0c0 headroom = 46
Interpreter Sp=0x7f4264172230 SpLim=0x7f42641720c0 headroom = 46
Interpreter Sp=0x7f426416a230 SpLim=0x7f426416a0c0 headroom = 46
Interpreter Sp=0x7f4264162230 SpLim=0x7f42641620c0 headroom = 46
Interpreter Sp=0x7f426415a230 SpLim=0x7f426415a0c0 headroom = 46
Interpreter Sp=0x7f4264152230 SpLim=0x7f42641520c0 headroom = 46
Interpreter Sp=0x7f426414a230 SpLim=0x7f426414a0c0 headroom = 46
Interpreter Sp=0x7f4264142230 SpLim=0x7f42641420c0 headroom = 46
Interpreter Sp=0x7f426413a230 SpLim=0x7f426413a0c0 headroom = 46
Interpreter Sp=0x7f4264132230 SpLim=0x7f42641320c0 headroom = 46
Interpreter Sp=0x7f42649d0238 SpLim=0x7f42649d00c0 headroom = 47
Interpreter Sp=0x7f4264a1e238 SpLim=0x7f4264a1e0c0 headroom = 47
Interpreter Sp=0x7f4264a16238 SpLim=0x7f4264a160c0 headroom = 47
Interpreter Sp=0x7f4264a0e238 SpLim=0x7f4264a0e0c0 headroom = 47
Interpreter Sp=0x7f4264a06238 SpLim=0x7f4264a060c0 headroom = 47
Interpreter Sp=0x7f4257ff8238 SpLim=0x7f4257ff80c0 headroom = 47
Interpreter Sp=0x7f4257ff0238 SpLim=0x7f4257ff00c0 headroom = 47
Interpreter Sp=0x7f4257fe8238 SpLim=0x7f4257fe80c0 headroom = 47
Interpreter Sp=0x7f4257fe0238 SpLim=0x7f4257fe00c0 headroom = 47
Interpreter Sp=0x7f4257fd8238 SpLim=0x7f4257fd80c0 headroom = 47
Interpreter Sp=0x7f4257fd0238 SpLim=0x7f4257fd00c0 headroom = 47
Interpreter Sp=0x7f4257fc8238 SpLim=0x7f4257fc80c0 headroom = 47
Interpreter Sp=0x7f4257fc0238 SpLim=0x7f4257fc00c0 headroom = 47
Interpreter Sp=0x7f4257fb8238 SpLim=0x7f4257fb80c0 headroom = 47
Interpreter Sp=0x7f4257fb0238 SpLim=0x7f4257fb00c0 headroom = 47
Interpreter Sp=0x7f42641f8238 SpLim=0x7f42641f80c0 headroom = 47
Interpreter Sp=0x7f42641f0238 SpLim=0x7f42641f00c0 headroom = 47
Interpreter Sp=0x7f42644f8238 SpLim=0x7f42644f80c0 headroom = 47
Interpreter Sp=0x7f42644ef238 SpLim=0x7f42644ef0c0 headroom = 47
Interpreter Sp=0x7f42644e7238 SpLim=0x7f42644e70c0 headroom = 47
Interpreter Sp=0x7f42644de238 SpLim=0x7f42644de0c0 headroom = 47
Interpreter Sp=0x7f42644d6238 SpLim=0x7f42644d60c0 headroom = 47
Interpreter Sp=0x7f42644ce238 SpLim=0x7f42644ce0c0 headroom = 47
Interpreter Sp=0x7f42644c5238 SpLim=0x7f42644c50c0 headroom = 47
Interpreter Sp=0x7f42644bd238 SpLim=0x7f42644bd0c0 headroom = 47
Interpreter Sp=0x7f42644b4238 SpLim=0x7f42644b40c0 headroom = 47
Interpreter Sp=0x7f42644ac238 SpLim=0x7f42644ac0c0 headroom = 47
Interpreter Sp=0x7f42644a4238 SpLim=0x7f42644a40c0 headroom = 47
Interpreter Sp=0x7f426449b238 SpLim=0x7f426449b0c0 headroom = 47
Interpreter Sp=0x7f4264493238 SpLim=0x7f42644930c0 headroom = 47
Interpreter Sp=0x7f426448a238 SpLim=0x7f426448a0c0 headroom = 47
Interpreter Sp=0x7f4264482238 SpLim=0x7f42644820c0 headroom = 47
Interpreter Sp=0x7f426447a238 SpLim=0x7f426447a0c0 headroom = 47
Interpreter Sp=0x7f426454e238 SpLim=0x7f426454e0c0 headroom = 47
Interpreter Sp=0x7f42641e8238 SpLim=0x7f42641e80c0 headroom = 47
Interpreter Sp=0x7f426417c238 SpLim=0x7f426417c0c0 headroom = 47
Interpreter Sp=0x7f4264174238 SpLim=0x7f42641740c0 headroom = 47
Interpreter Sp=0x7f426416c238 SpLim=0x7f426416c0c0 headroom = 47
Interpreter Sp=0x7f4264164238 SpLim=0x7f42641640c0 headroom = 47
Interpreter Sp=0x7f426415c238 SpLim=0x7f426415c0c0 headroom = 47
Interpreter Sp=0x7f4264154238 SpLim=0x7f42641540c0 headroom = 47
Interpreter Sp=0x7f426414c238 SpLim=0x7f426414c0c0 headroom = 47
Interpreter Sp=0x7f42643e0238 SpLim=0x7f42643e00c0 headroom = 47
Interpreter Sp=0x7f42643d8238 SpLim=0x7f42643d80c0 headroom = 47
Interpreter Sp=0x7f42643d0238 SpLim=0x7f42643d00c0 headroom = 47
Interpreter Sp=0x7f42643c8238 SpLim=0x7f42643c80c0 headroom = 47
Interpreter Sp=0x7f42643c0238 SpLim=0x7f42643c00c0 headroom = 47
Interpreter Sp=0x7f42643b8238 SpLim=0x7f42643b80c0 headroom = 47
Interpreter Sp=0x7f42643e0238 SpLim=0x7f42643e00c0 headroom = 47
Interpreter Sp=0x7f4264154138 SpLim=0x7f42641540c0 headroom = 15
Interpreter Sp=0x7f42641541d0 SpLim=0x7f42641540c0 headroom = 34
Interpreter Sp=0x7f426415c230 SpLim=0x7f426415c0c0 headroom = 46
Interpreter Sp=0x7f4264164130 SpLim=0x7f42641640c0 headroom = 14
Interpreter Sp=0x7f42641641c8 SpLim=0x7f42641640c0 headroom = 33
Interpreter Sp=0x7f426447a0e0 SpLim=0x7f426447a0c0 headroom = 4
Interpreter Sp=0x7f426447a178 SpLim=0x7f426447a0c0 headroom = 23
Interpreter Sp=0x7f426447a210 SpLim=0x7f426447a0c0 headroom = 42
Interpreter Sp=0x7f4264482138 SpLim=0x7f42644820c0 headroom = 15
Interpreter Sp=0x7f42644821d0 SpLim=0x7f42644820c0 headroom = 34
Interpreter Sp=0x7f426448a228 SpLim=0x7f426448a0c0 headroom = 45
Interpreter Sp=0x7f4264493238 SpLim=0x7f42644930c0 headroom = 47
Interpreter Sp=0x7f426449b130 SpLim=0x7f426449b0c0 headroom = 14
Interpreter Sp=0x7f426449b1c8 SpLim=0x7f426449b0c0 headroom = 33
Interpreter Sp=0x7f42644ac0d0 SpLim=0x7f42644ac0c0 headroom = 2
Interpreter Sp=0x7f42644ac168 SpLim=0x7f42644ac0c0 headroom = 21
Interpreter Sp=0x7f42644ac200 SpLim=0x7f42644ac0c0 headroom = 40
Interpreter Sp=0x7f42644b4230 SpLim=0x7f42644b40c0 headroom = 46
Interpreter Sp=0x7f42644bd108 SpLim=0x7f42644bd0c0 headroom = 9
Interpreter Sp=0x7f42644bd1a0 SpLim=0x7f42644bd0c0 headroom = 28
Interpreter Sp=0x7f42644bd238 SpLim=0x7f42644bd0c0 headroom = 47
Interpreter Sp=0x7f42644ce140 SpLim=0x7f42644ce0c0 headroom = 16
Interpreter Sp=0x7f42644ce1d8 SpLim=0x7f42644ce0c0 headroom = 35
Interpreter Sp=0x7f42644d6218 SpLim=0x7f42644d60c0 headroom = 43
Interpreter Sp=0x7f42644de0e0 SpLim=0x7f42644de0c0 headroom = 4
Interpreter Sp=0x7f42644de178 SpLim=0x7f42644de0c0 headroom = 23
Interpreter Sp=0x7f42644de210 SpLim=0x7f42644de0c0 headroom = 42
Interpreter Sp=0x7f42644e70c0 SpLim=0x7f42644e70c0 headroom = 0
Interpreter Sp=0x7f42644e7158 SpLim=0x7f42644e70c0 headroom = 19
Interpreter Sp=0x7f42644e71f0 SpLim=0x7f42644e70c0 headroom = 38
Interpreter Sp=0x7f42644ef230 SpLim=0x7f42644ef0c0 headroom = 46
Interpreter Sp=0x7f42644f8190 SpLim=0x7f42644f80c0 headroom = 26
Interpreter Sp=0x7f42644f8228 SpLim=0x7f42644f80c0 headroom = 45
Interpreter Sp=0x7f42641f00d8 SpLim=0x7f42641f00c0 headroom = 3
Interpreter Sp=0x7f42641f0170 SpLim=0x7f42641f00c0 headroom = 22
Interpreter Sp=0x7f42641f0208 SpLim=0x7f42641f00c0 headroom = 41
Interpreter Sp=0x7f4257fb8210 SpLim=0x7f4257fb80c0 headroom = 42
Interpreter Sp=0x7f4257fb80f0 SpLim=0x7f4257fb80c0 headroom = 6
Interpreter Sp=0x7f4257fb8188 SpLim=0x7f4257fb80c0 headroom = 25
Interpreter Sp=0x7f4257fb8220 SpLim=0x7f4257fb80c0 headroom = 44
Interpreter Sp=0x7f4257fc00d0 SpLim=0x7f4257fc00c0 headroom = 2
Interpreter Sp=0x7f4257fc0168 SpLim=0x7f4257fc00c0 headroom = 21
Interpreter Sp=0x7f4257fc0200 SpLim=0x7f4257fc00c0 headroom = 40
Interpreter Sp=0x7f4257fc80b0 SpLim=0x7f4257fc80c0 headroom = -2    <---- NB
Interpreter Sp=0x7f4257fc8148 SpLim=0x7f4257fc80c0 headroom = 17
Interpreter Sp=0x7f4257fc81e0 SpLim=0x7f4257fc80c0 headroom = 36
Interpreter Sp=0x7f4257fd0228 SpLim=0x7f4257fd00c0 headroom = 45
Interpreter Sp=0x7f4257fe0228 SpLim=0x7f4257fe00c0 headroom = 45
Interpreter Sp=0x7f4257fe8140 SpLim=0x7f4257fe80c0 headroom = 16
Interpreter Sp=0x7f4257fe81d8 SpLim=0x7f4257fe80c0 headroom = 35
Interpreter Sp=0x7f4257ff0120 SpLim=0x7f4257ff00c0 headroom = 12
Interpreter Sp=0x7f4257ff01b8 SpLim=0x7f4257ff00c0 headroom = 31
Interpreter Sp=0x7f4257ff8100 SpLim=0x7f4257ff80c0 headroom = 8
Interpreter Sp=0x7f4257ff8198 SpLim=0x7f4257ff80c0 headroom = 27
Interpreter Sp=0x7f4257ff8230 SpLim=0x7f4257ff80c0 headroom = 46
Interpreter Sp=0x7f4264a060e0 SpLim=0x7f4264a060c0 headroom = 4
Interpreter Sp=0x7f4264a06178 SpLim=0x7f4264a060c0 headroom = 23
Interpreter Sp=0x7f4264a06210 SpLim=0x7f4264a060c0 headroom = 42
Interpreter Sp=0x7f4264a0e0c0 SpLim=0x7f4264a0e0c0 headroom = 0
Interpreter Sp=0x7f4264a0e158 SpLim=0x7f4264a0e0c0 headroom = 19
Interpreter Sp=0x7f4264a0e1f0 SpLim=0x7f4264a0e0c0 headroom = 38
Interpreter Sp=0x7f4264a16138 SpLim=0x7f4264a160c0 headroom = 15
Interpreter Sp=0x7f4264a161d0 SpLim=0x7f4264a160c0 headroom = 34
Interpreter Sp=0x7f4264a1e118 SpLim=0x7f4264a1e0c0 headroom = 11

So yes, we get into a situation in which we have negative headroom. Presumably if the ASSERT is off, we simply don't notice. But it's clearly wrong.

Change History (5)

comment:1 Changed 5 years ago by simonpj

Milestone: 7.10.1
Owner: set to simonmar

comment:2 Changed 5 years ago by simonpj

Priority: normalhighest

I'll mark this as high priority because it looks like a potential seg-fault.

comment:3 Changed 5 years ago by simonmar

Resolution: fixed
Status: newclosed

It turns out that things were working mostly correctly, and there was no danger of a segfault. SpLim has a certain amount of headroom to allow for the space needed to save things when a stack check fails, which is why we appeared to be going over the limit sometimes. The assertion was the bug.

However, I did find some other bugs while tracking this down, the patches I committed are:

83cf31e42e87e93eda3e576bc5935509959c2f49 4cd277b4dcb91c6c6aa7e071ef0364570566de37 4cd277b4dcb91c6c6aa7e071ef0364570566de37 e6b38294512896cf55f2d05d09d742d82313f598 081ef2fb351831081bf6851fd3907679b1b98405

comment:4 Changed 5 years ago by simonpj

Well done -- thanks!

comment:5 Changed 5 years ago by simonmar

Oh, and the reason you have the debug RTS in your compiler is because -ticky implies -debug. Incidentally this is probably slowing down your builds quite a lot, so you might want to turn it off.

Note: See TracTickets for help on using tickets.