Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build error by segmentation fault #52

Closed
MasahikoIto opened this issue Apr 25, 2012 · 15 comments
Closed

build error by segmentation fault #52

MasahikoIto opened this issue Apr 25, 2012 · 15 comments

Comments

@MasahikoIto
Copy link

$ cat /etc/slackware-version
Slackware 13.37.0

$ uname -a
Linux c760 3.1.10 #1 PREEMPT Thu Feb 16 01:18:19 JST 2012 armv5tel XScale-PXA255 rev 6 (v5l) SHARP Husky GNU/Linux

$ tar xvzf mruby-mruby-e26bf08.tar.gz
$ cd mruby-mruby-e26bf08
$ make

snip

gcc -o ../../bin/mrbc ../../src/../tools/mrbc/mrbc.o ../../src/transcode.o ../../src/state.o ../../src/string.o ../../src/ascii.o ../../src/unicode.o ../../src/cdump.o ../../src/
crc.o ../../src/struct.o ../../src/codegen.o ../../src/sprintf.o ../../src/init.o ../../src/kernel.o ../../src/us_ascii.o ../../src/gc.o ../../src/vm.o ../../src/regparse.o ../..
/src/class.o ../../src/etc.o ../../src/dump.o ../../src/re.o ../../src/regcomp.o ../../src/version.o ../../src/encoding.o ../../src/error.o ../../src/hash.o ../../src/regenc.o ..
/../src/object.o ../../src/utf_8.o ../../src/compar.o ../../src/proc.o ../../src/regexec.o ../../src/variable.o ../../src/range.o ../../src/pool.o ../../src/enum.o ../../src/nume
ric.o ../../src/array.o ../../src/regerror.o ../../src/print.o ../../src/symbol.o ../../src/st.o ../../src/y.tab.o -lm
make: built targets of /home/m-ito/tmp/mruby-mruby-e26bf08/tools/mrbc
cat struct.rb error.rb string.rb hash.rb compar.rb range.rb enum.rb numeric.rb kernel.rb array.rb print.rb > mrblib.rbtmp
../bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp; cat init_mrblib.c mrblib.ctmp > mrblib.c
/bin/sh: line 1: 14047 Segmentation fault ../bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp

snip

make: built targets of /home/m-ito/tmp/mruby-mruby-e26bf08/mrblib
gcc -o ../../bin/mruby ../../src/../tools/mruby/mruby.o ../../src/transcode.o ../../src/unicode.o ../../src/crc.o ../../src/struct.o ../../src/us_ascii.o ../../src/proc.o ../../s
rc/pool.o ../../src/regenc.o ../../src/load.o ../../src/ascii.o ../../src/version.o ../../src/hash.o ../../src/utf_8.o ../../src/codegen.o ../../src/range.o ../../src/enum.o ../.
./src/regerror.o ../../src/symbol.o ../../src/object.o ../../src/state.o ../../src/vm.o ../../src/print.o ../../src/sprintf.o ../../src/init.o ../../src/numeric.o ../../src/error
.o ../../src/regparse.o ../../src/init_ext.o ../../src/class.o ../../src/etc.o ../../src/string.o ../../src/regcomp.o ../../src/kernel.o ../../src/encoding.o ../../src/compar.o .
./../src/regexec.o ../../src/variable.o ../../src/re.o ../../src/array.o ../../src/gc.o ../../src/st.o ../../src/y.tab.o ../../src/../mrblib/mrblib.o -lm
../../src/../mrblib/mrblib.o: In function mrb_init_mrblib': /home/m-ito/tmp/mruby-mruby-e26bf08/mrblib/mrblib.c:16: undefined reference tomrblib_irep'
collect2: ld returned 1 exit status
make[1]: *** [../../bin/mruby] Error 1
make: *** [src/init_ext.o] Error 2

$ cd mrblib/
$ ../bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp
Segmentation fault

$ gdb ../bin/mrbc
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-slackware-linux-gnueabi".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...
Reading symbols from /home/m-ito/tmp/mruby-mruby-e26bf08/bin/mrbc...done.
(gdb) run -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp
Starting program: /home/m-ito/tmp/mruby-mruby-e26bf08/bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp

Program received signal SIGSEGV, Segmentation fault.
0x000ab7ec in parser_yylex (p=0x11c8f0) at ../../src/parse.y:4451
4451 if (!identchar(c)) {
(gdb) list
4446 case '_':
4447 token_column = newtok(p);
4448 break;
4449
4450 default:
4451 if (!identchar(c)) {
4452 yyerror_i(p, "Invalid char `\x%02X' in expression", c);
4453 goto retry;
4454 }
4455
(gdb) p c
$1 = 2686976
(gdb) quit
A debugging session is active.

    Inferior 1 [process 14086] will be killed.

Quit anyway? (y or n) y

What can I do ?

@matz
Copy link
Member

matz commented May 17, 2012

Can you still reproduce the error?

@MasahikoIto
Copy link
Author

Now I'm compiling from newest source on ARMedslack-13.1 on SL-C860 :)

@MasahikoIto
Copy link
Author

Almost same error :(

gcc -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include -c vm.c -o vm.o
bison -o ./y.tab.c ./parse.y
gcc -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include -c ./y.tab.c -o ./y.tab.o
ar r ../lib/libmruby_core.a ./array.o ./cdump.o ./class.o ./codegen.o ./compar.o ./crc.o ./dump.o ./enum.o ./error.o ./etc.o ./gc.o ./hash.o ./init.o ./init_ext.o ./kernel.o ./load.o ./math.o ./numeric.o ./object.o ./pool.o ./print.o ./proc.o ./range.o ./re.o ./regcomp.o ./regenc.o ./regerror.o ./regexec.o ./regparse.o ./sprintf.o ./st.o ./state.o ./string.o ./struct.o ./symbol.o ./time.o ./variable.o ./vm.o ./y.tab.o
ar: creating ../lib/libmruby_core.a
cat ./.rb > mrblib.rbtmp
make -C ../tools/mrbc CC='gcc' LL='gcc' ALL_CFLAGS='-Wall -Werror-implicit-function-declaration -g -O3'
gcc -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I../../src -I../../src/../include -c ../../src/../tools/mrbc/mrbc.c -o ../../src/../tools/mrbc/mrbc.o
gcc -o ../../bin/mrbc ../../src/../tools/mrbc/mrbc.o ../../lib/libmruby_core.a -lm
../bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp; cat init_mrblib.c mrblib.ctmp > mrblib.c
/bin/sh: line 1: 13844 Segmentation fault ../bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp
gcc -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I../src -I../include -c mrblib.c -o mrblib.o
cp ../lib/libmruby_core.a ../lib/libmruby.a
ar r ../lib/libmruby.a mrblib.o
gcc -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I../../src -I../../src/../include -c ../../src/../tools/mruby/mruby.c -o ../../src/../tools/mruby/mruby.o
gcc -o ../../bin/mruby -g -O3 ../../src/../tools/mruby/mruby.o ../../lib/libmruby.a -lm
../../lib/libmruby.a(mrblib.o): In function mrb_init_mrblib': /home/m-ito/tmp/mruby-mruby-bf747ef/mrblib/mrblib.c:16: undefined reference tomrblib_irep'
collect2: ld returned 1 exit status
make[1]: *
* [../../bin/mruby] Error 1
make: *** [all] Error 2
10004 m-ito@c860:~/tmp/mruby-mruby-bf747ef$

@matz
Copy link
Member

matz commented Jun 24, 2012

I've notice the line "cat ./.rb > mrblib.rbtmp". It should be "cat ./*.rb > mrblib.rbtmp"
Does your shell have any issue to expand wild card?

Besides that, the biggest problem is SEGV from mrbc. Is there any way to get backtrace?

@MasahikoIto
Copy link
Author

Sorry, It exactly performed "cat ./.rb > mrblib.rbtmp". I'm not sure, but Github system might delete "" from my cut&paste to avoid something cracking?

BTW, What do you mean "backtrace"? I can do "gdb" or "strace". Which one do you need? or Do you need to perform another tool?

Thanx!

@MasahikoIto
Copy link
Author

Now I understood that I should post like "cat ./*.rb ..." :P

@matz
Copy link
Member

matz commented Jun 25, 2012

You can do "gdb"! That's good news.
Please try following:

$ cd mrblib
$ .run ./bin/mrbc
(gdb) run -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp
segmentation fault
(gdb) where

I want to see the output from "where" command.

@MasahikoIto
Copy link
Author

10132 m-ito@c860:/tmp/mruby-mruby-bf747ef$ export LC_ALL=C
10133 m-ito@c860:
/tmp/mruby-mruby-bf747ef$ cd mrblib
10134 m-ito@c860:~/tmp/mruby-mruby-bf747ef/mrblib$ gdb ../bin/mrbc
GNU gdb (GDB) 7.1
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-slackware-linux-gnueabi".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...
Reading symbols from /home/m-ito/tmp/mruby-mruby-bf747ef/bin/mrbc...done.
(gdb) run -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp
Starting program: /home/m-ito/tmp/mruby-mruby-bf747ef/bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp

Program received signal SIGSEGV, Segmentation fault.
0x0002c56c in parser_yylex (p=0x7afd0) at ./parse.y:4481
4481 if (!identchar(c)) {
(gdb) where
#0 0x0002c56c in parser_yylex (p=0x7afd0) at ./parse.y:4481
#1 yylex (p=0x7afd0) at ./parse.y:4637
#2 yyparse (p=0x7afd0) at ./y.tab.c:4961
#3 0x000325fc in mrb_parser_parse (p=) at ./parse.y:4659
#4 0x00032864 in mrb_parse_file (mrb=0x69008, f=0x752f0) at ./parse.y:4743
#5 0x00009568 in main (argc=, argv=0xbeffec94) at ../../src/../tools/mrbc/mrbc.c:175
(gdb) quit
A debugging session is active.

    Inferior 1 [process 27327] will be killed.

Quit anyway? (y or n) y
10135 m-ito@c860:~/tmp/mruby-mruby-bf747ef/mrblib$

@matz
Copy link
Member

matz commented Jun 26, 2012

Thank you. One more request.
Can I see the value of c at the point of segv?
It can be seen by

(gdb) p c

please?

@MasahikoIto
Copy link
Author

9999 m-ito@c860:~/tmp/mruby-mruby-bf747ef/mrblib$ gdb ../bin/mrbc
GNU gdb (GDB) 7.1
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-slackware-linux-gnueabi".
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...
Reading symbols from /home/m-ito/tmp/mruby-mruby-bf747ef/bin/mrbc...done.
(gdb) run -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp
Starting program: /home/m-ito/tmp/mruby-mruby-bf747ef/bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp

Program received signal SIGSEGV, Segmentation fault.
0x0002c56c in parser_yylex (p=0x7afd0) at ./parse.y:4481
4481 if (!identchar(c)) {
(gdb) p c
$1 =
(gdb)

Should I use "-O0" for building mruby? or
Should I change "register int c" to "int c" in ../src/parse.y? or
Should I do printf debug in ../src/parse.y to see value of "c"?

@matz
Copy link
Member

matz commented Jun 26, 2012

I think -O0 will make it printable. Could try again?

@monaka
Copy link
Contributor

monaka commented Jun 27, 2012

This comment is just a reference.

I'm trying ARM bare metal target (not the target of this issue) and have some issues about parser.y
I got debugger log like this.

Breakpoint 4, parser_yylex (p=0xab158) at parse.y:4481
4481        if (!identchar(c)) {
1: /c c = 0 '\000'

I think c should be positive value always.

@monaka
Copy link
Contributor

monaka commented Jun 27, 2012

I'm not sure ... but.
As I wrote in #331 #333, It's possible this is caused by address alignment.

It will be fixed by adding '#define ALLOC_ALIGN 4' on the top of src/pool.c, when this issue is as same as I encountered.

@MasahikoIto
Copy link
Author

(gdb) run -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp
Starting program: /home/m-ito/tmp/mruby-mruby-bf747ef/bin/mrbc -Bmrblib_irep -omrblib.ctmp mrblib.rbtmp

Program received signal SIGSEGV, Segmentation fault.
0x0003c5e0 in parser_yylex (p=0x8afd0) at ./parse.y:4481
4481 if (!identchar(c)) {
(gdb) p c
$1 = 6422528
(gdb)

@MasahikoIto
Copy link
Author

I put "#define ALLOC_ALIGN 4" in src/pool.c and do "make && make test" and I succeed to build mruby!

10023 m-ito@c860:~/tmp/mruby-mruby-bf747ef$ LC_ALL=C make test
make[1]: Nothing to be done for all'. make[1]: Nothing to be done forall'.
make[1]: Nothing to be done for all'. make[1]: Nothing to be done forall'.
./mrbtest
mrbtest - Embeddable Ruby Test

This is a very early version, please test and report errors.
Thanks :)

........................................................................................
........................................................................................
........................................................................................
........................................................................................
........................................................................................
......
Total: 446
OK: 446
KO: 0
Crash: 0
Time: 0.188898 seconds
10024 m-ito@c860:~/tmp/mruby-mruby-bf747ef$

Thanx so much matz & monaka :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants