chicken-janitors
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

#1726: chicken.base#implicit-exit-handler reporting segmentation violati


From: Chicken Trac
Subject: #1726: chicken.base#implicit-exit-handler reporting segmentation violation with non-default heap size
Date: Fri, 15 Jan 2021 03:19:31 -0000

#1726: chicken.base#implicit-exit-handler reporting segmentation violation with
non-default heap size
-------------------------------------+----------------------------
            Reporter:  vjorlikowski  |       Type:  defect
              Status:  new           |   Priority:  minor
           Milestone:  someday       |  Component:  core libraries
             Version:  5.1.0         |   Keywords:
Estimated difficulty:                |
-------------------------------------+----------------------------
 I was experimenting with the "Man-or-boy" test
 (http://rosettacode.org/wiki/Man_or_boy_test) using Chicken Scheme;
 my variant looks like this:

 {{{
 vjo@glaucus/pts/11:chicken/man_or_boy % cat test.scm
 (import (chicken process-context)
         (chicken fixnum))

 (define (A k x1 x2 x3 x4 x5)
   (let
       ([+ fx+]
        [- fx-]
        [<= fx<=])
     (define (B)
       (set! k (- k 1))
       (A k B x1 x2 x3 x4))
     (if (<= k 0)
         (+ (x4) (x5))
         (B))))

 (define k (let ([args (command-line-arguments)])
             (if (> (length args) 0)
                 (string->number (car args))
                 10)))
 (print (A k
           (lambda () 1)
           (lambda () -1)
           (lambda () -1)
           (lambda () 1)
           (lambda () 0)))
 }}}

 This compiles fine, and runs great with the default heap size up to
 a value of k=27:

 {{{
 vjo@glaucus/pts/11:chicken/man_or_boy % csc -O4 test.scm
 vjo@glaucus/pts/11:chicken/man_or_boy % time ./test 26
 -21051458
 ./test 26  25.20s user 1.31s system 99% cpu 26.577 total
 vjo@glaucus/pts/11:chicken/man_or_boy % time ./test 27
 -46750171
 ./test 27  101.91s user 4.42s system 99% cpu 1:46.66 total
 }}}

 At k=28, however, we run out of heap, with the default settings:

 {{{
 vjo@glaucus/pts/11:chicken/man_or_boy % time ./test 28
 [panic] out of memory - heap has reached its maximum size - execution
 terminated

 ...more...
 test.scm:14: B
 test.scm:11: A
 test.scm:14: B
 test.scm:11: A
 test.scm:13: x4
 test.scm:11: A
 test.scm:14: B
 test.scm:11: A
 test.scm:14: B
 test.scm:11: A
 test.scm:13: x4
 test.scm:11: A
 test.scm:14: B
 test.scm:11: A
 test.scm:14: B
 test.scm:11: A  <--
 ./test 28  22.39s user 3.79s system 99% cpu 26.282 total
 }}}

 No problem, say I; let me re-compile with an increased heap.
 That works well - and the code gives back the correct answer - but,
 I now encounter the bug I wish to report:

 {{{
 vjo@glaucus/pts/11:chicken/man_or_boy % csc -O4 -heap-size 4096M test.scm
 vjo@glaucus/pts/11:chicken/man_or_boy % time ./test 28
 -103821058

 Error: segmentation violation

         Call history:

         test.scm:13: x5
         test.scm:11: A
         test.scm:13: x4
         test.scm:13: x5
         test.scm:13: x5
         test.scm:11: A
         test.scm:13: x4
         test.scm:11: A
         test.scm:13: x4
         test.scm:13: x5
         test.scm:13: x5
         test.scm:11: A
         test.scm:13: x4
         test.scm:13: x5
         test.scm:20: chicken.base#print
         chicken.base#implicit-exit-handler              <--
 ./test 28  90.91s user 1.71s system 99% cpu 1:32.65 total
 }}}

 It *appears* that the implicit-exit-handler triggers a segmentation
 violation for any binary compiled with a non-default heap size
 specified; as an illustrative example, here is the same code
 compiled with two different heap sizes and executed using k=26. The
 first shows what happens with an insufficient heap size, the second
 shows what happens when the heap size is *just barely* sufficient,
 but non-default value:

 {{{
 vjo@glaucus/pts/11:chicken/man_or_boy % csc -O4 -heap-size 928M test.scm
 vjo@glaucus/pts/11:chicken/man_or_boy % time ./test 26
 [panic] out of memory - heap full - execution terminated

 ...more...
 test.scm:14: B
 test.scm:11: A
 test.scm:14: B
 test.scm:11: A
 test.scm:13: x4
 test.scm:11: A
 test.scm:14: B
 test.scm:11: A
 test.scm:14: B
 test.scm:11: A
 test.scm:13: x4
 test.scm:11: A
 test.scm:14: B
 test.scm:11: A
 test.scm:14: B
 test.scm:11: A  <--
 ./test 26  5.01s user 0.44s system 99% cpu 5.471 total

 vjo@glaucus/pts/11:chicken/man_or_boy % csc -O4 -heap-size 929M test.scm
 vjo@glaucus/pts/11:chicken/man_or_boy % time ./test 26
 -21051458

 Error: segmentation violation

         Call history:

         test.scm:13: x5
         test.scm:13: x5
         test.scm:11: A
         test.scm:13: x4
         test.scm:11: A
         test.scm:13: x4
         test.scm:11: A
         test.scm:13: x4
         test.scm:13: x5
         test.scm:13: x5
         test.scm:13: x5
         test.scm:11: A
         test.scm:13: x4
         test.scm:13: x5
         test.scm:20: chicken.base#print
         chicken.base#implicit-exit-handler              <--
 ./test 26  25.87s user 0.73s system 99% cpu 26.620 total
 }}}

 The versions of all software involved have been determined below:

 {{{
 vjo@glaucus/pts/11:chicken/man_or_boy % csc -O4 -kv test.scm
 '/usr/bin/chicken' 'test.scm' -output-file 'test.c' -optimize-level 4
 -verbose
 'x86_64-linux-gnu-gcc' 'test.c' -o 'test.o' -c  -fno-strict-aliasing
 -fwrapv
 -DHAVE_CHICKEN_CONFIG_H -DC_ENABLE_PTABLES -g -O2
 -fdebug-prefix-map=/build/chicken-8b5V5S/chicken-5.1.0=. -fstack-
 protector-strong -Wformat
 -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2
 -I/usr/include/chicken
 'x86_64-linux-gnu-gcc' 'test.o' -o 'test' -L/usr/lib -Wl,-R/usr/lib
 -lchicken -lm -ldl

 vjo@glaucus/pts/11:chicken/man_or_boy % x86_64-linux-gnu-gcc --version
 x86_64-linux-gnu-gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008
 Copyright (C) 2019 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.

 vjo@glaucus/pts/11:chicken/man_or_boy % csc -version
 CHICKEN
 (c) 2008-2019, The CHICKEN Team
 (c) 2000-2007, Felix L. Winkelmann
 Version 5.1.0 (rev 8e62f718)
 linux-unix-gnu-x86-64 [ 64bit dload ptables ]
 }}}

-- 
Ticket URL: <https://bugs.call-cc.org/ticket/1726>
CHICKEN Scheme <https://www.call-cc.org/>
CHICKEN Scheme is a compiler for the Scheme programming language.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]