Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3694 closed defect (fixed)

Stack overflow in Modelica Parser

Reported by: Henning Kiel Owned by: Martin Sjölund
Priority: critical Milestone: 1.9.4
Component: Parser Version: v1.9.4-dev-nightly
Keywords: Cc:

Description

When loading the ScalableTestSuite I encounter a "Bus error: 10" on OSX (maybe stack overflow?)
With lldb I this backtrace. so maybe element_list causes a too deep recursion level?

(lldb) bt
* thread #2: tid = 0x4a1ded, 0x000000010004c630 libOpenModelicaRuntimeC.dylib`GC_clear_stack_inner(arg=0x0000000000000000, limit="") + 32 at misc.c:336, stop reason = EXC_BAD_ACCESS (code=2, address=0x70000028fcd8)
  * frame #0: 0x000000010004c630 libOpenModelicaRuntimeC.dylib`GC_clear_stack_inner(arg=0x0000000000000000, limit="") + 32 at misc.c:336
    frame #1: 0x000000010004c64a libOpenModelicaRuntimeC.dylib`GC_clear_stack_inner(arg=0x0000000000000000, limit="") + 58 at misc.c:338
[...]
    frame #9: 0x000000010004c64a libOpenModelicaRuntimeC.dylib`GC_clear_stack_inner(arg=0x0000000000000000, limit="") + 58 at misc.c:338
    frame #10: 0x0000000100048ae4 libOpenModelicaRuntimeC.dylib`GC_generic_malloc_many(lb=<unavailable>, k=<unavailable>, result=<unavailable>) + 948 at mallocx.c:443
    frame #11: 0x0000000100051a02 libOpenModelicaRuntimeC.dylib`GC_malloc(bytes=<unavailable>) + 146 at thread_local_alloc.c:175
    frame #12: 0x00000001010094d3 libOpenModelicaCompiler.dylib`type_specifier [inlined] mmc_alloc_words(nwords=4) + 10 at mmc_gc.h:99
    frame #13: 0x00000001010094c9 libOpenModelicaCompiler.dylib`type_specifier [inlined] mmc_mk_box3(ctor=3, x0=<unavailable>, x1=0x0000000116411003) at meta_modelica_mk_box.h:26
    frame #14: 0x00000001010094c9 libOpenModelicaCompiler.dylib`type_specifier(ctx=0x0000000102007800) + 713 at ModelicaParser.c:10149
    frame #15: 0x0000000101008ac4 libOpenModelicaCompiler.dylib`component_clause(ctx=0x0000000102007800) + 180 at ModelicaParser.c:9556
    frame #16: 0x0000000101006c4d libOpenModelicaCompiler.dylib`element(ctx=0x0000000102007800) + 1229 at ModelicaParser.c:8246
    frame #17: 0x0000000101006047 libOpenModelicaCompiler.dylib`element_list(ctx=0x0000000102007800, ann=0x000070000030e8a0) + 247 at ModelicaParser.c:7610
[...]
    frame #4400: 0x0000000101006047 libOpenModelicaCompiler.dylib`element_list(ctx=0x0000000102007800, ann=0x000070000030e8a0) + 247 at ModelicaParser.c:7610

Change History (12)

comment:1 by Henning Kiel, 9 years ago

This is definitely a stack issue, because if I increase stack with ulimit the error occurs later.

comment:2 by Henning Kiel, 9 years ago

Component: *unknown*Backend
Owner: changed from somebody to Lennart Ochel

comment:3 by Adrian Pop, 9 years ago

Component: BackendParser
Owner: changed from Lennart Ochel to Martin Sjölund
Status: newassigned

comment:4 by Martin Sjölund, 9 years ago

Status: assignedaccepted

I could not reproduce this using ScalableTestSuite on Linux as the minimum allowed stack size is 137 kB due to our stack overflow detection. I even tried to use -O0 -g to compile the parser... It still handled it. With 200 000 elements in a 4MB custom-made file, I could manage to fill a 137 kB stack though.

comment:5 by Henning Kiel, 9 years ago

Can you test on an OSX system?
What can I do to investigate?

comment:6 by Martin Sjölund, 9 years ago

I have a hopefully working fix. I don't want to change the result of parsing so close to a release. The parsing now needs to listReverse the element_list in order to be tail-recursive. I also fixed some problems with scaling in SCodeUtil/InstUtil when dealing with 100k+ elements in a list.

https://github.com/OpenModelica/OMCompiler/pull/426

comment:7 by Henning Kiel, 9 years ago

The change to Modelica.g fixed the described failure for element_list, but now I get a stack overflow for equation_annotation_list. Can you fix that one too?

frame #5332: 0x000000010100c807 libOpenModelicaCompiler.dylib`equation_annotation_list(ctx=0x0000000103801800, ann=0x000070000030ee80) + 951 at ModelicaParser.c:13129

What I am doing is to run a .mos with

loadFile("ScalableTestSuite/package.mo");

comment:8 by Martin Sjölund, 9 years ago

Does the current master work on OSX now? (It does on Linux using my 8MB test-file with just a huge list of elements followed by a huge list of equations followed by a huge list of algorithm statements)

comment:9 by Henning Kiel, 9 years ago

The parser works now. So this ticket can be closed.

However, I still cannot load the library as I get the error
Error: Failed to load package ScalableTestSuite () using MODELICAPATH /Users/omc/src/libs/ScalableTestSuite:/Users/omc/src/OpenModelica/build/lib/omlibrary:/Users/omc/.openmodelica/libraries/.

comment:10 by Henning Kiel, 9 years ago

Resolution: fixed
Status: acceptedclosed

comment:11 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

comment:12 by Martin Sjölund, 9 years ago

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.