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

Building julia with clang: tests fail #602

Closed
ViralBShah opened this issue Mar 18, 2012 · 12 comments
Closed

Building julia with clang: tests fail #602

ViralBShah opened this issue Mar 18, 2012 · 12 comments
Assignees
Labels
kind:bug Indicates an unexpected problem or unintended behavior

Comments

@ViralBShah
Copy link
Member

Building julia with clang segfaults when building sys0.ji. Using OS X 10.7.3, with the clang that ships with XCode 4.3.1 (Apple clang version 3.1 (tags/Apple/clang-318.0.54) (based on LLVM 3.1svn))

(gdb) set args -b stage0.jl
(gdb) r
Starting program: /Users/viral/julia/julia -b stage0.jl
Reading symbols for shared libraries ++++++................................................................................................ done
Reading symbols for shared libraries . done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x00000000000000a0
0x000000010064c7f5 in fl_raise (e=4331668007) at flisp.c:175
175     while (readstate != (fl_readstate_t*)fl_ctx->rdst) {
(gdb) bt
#0  0x000000010064c7f5 in fl_raise (e=4331668007) at flisp.c:175
#1  0x000000010064cd6d in type_error (fname=0x10067d72e "apply", expected=0x1006ab117 "function", got=1) at flisp.c:217
#2  0x0000000100654e3b in _applyn (n=0) at flisp.c:637
#3  0x00000001006550c7 in fl_applyn (n=0, f=1) at flisp.c:674
#4  0x000000010001423f in jl_init_frontend () at ast.c:95
#5  0x0000000100060c6a in julia_init (imageFile=0x0) at init.c:112
#6  0x0000000100002122 in main ()
Current language:  auto; currently minimal
(gdb) 
@ghost ghost assigned JeffBezanson Mar 18, 2012
@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 18, 2012

Here's my backtrace, based on Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn). (note that sys0.ji built ok, it's stage1 that failed)

(lldb) run -J sys0.ji stage1.jl                                                                                                                 Process 70160 launched: '/Users/jameson/Documents/no-backup/julia/julia' (x86_64)
Process 70160 stopped
* thread #1: tid = 0x1f03, 0x00000001006658c3 julia`apply_cl + 99 at flisp.c:958, stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
    frame #0: 0x00000001006658c3 julia`apply_cl + 99 at flisp.c:958
   955   apply_cl_top:
   956      captured = 0;
   957      func = Stack[SP-nargs-1];
-> 958      ip = cv_data((cvalue_t*)ptr(fn_bcode(func)));
   959      assert(!ismanaged((uptrint_t)ip));
   960      while (SP+GET_INT32(ip) > N_STACK) {
   961          grow_stack();
(lldb) 

And on Ubuntu clang version 2.9 (tags/RELEASE_29/final) i386-pc-linux-gnu

(gdb) run -b stage0.jl
Starting program: /home/jameson/julia-clang/julia-debug-readline -b stage0.jl
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x0879499d in apply_cl (nargs=1) at flisp.c:958
958         ip = cv_data((cvalue_t*)ptr(fn_bcode(func)));
(gdb) bt
#0  0x0879499d in apply_cl (nargs=1) at flisp.c:958
#1  0x0878af91 in _applyn (n=1) at flisp.c:629
#2  0x0878b158 in fl_applyn (n=1, f=3078179338) at flisp.c:674
#3  0x08066479 in jl_expand (expr=0x89fe160) at ast.c:446
#4  0x08069d7f in jl_toplevel_eval_flex (e=0x89fe160, fast=0, plineno=0xbfffd8a8) at builtins.c:362
#5  0x0806a5f2 in jl_load_file_expr (fname=0x89a7fa8 "/home/jameson/julia-clang/jl/base.jl", ast=0x89ec570) at builtins.c:446
#6  0x0806aac2 in jl_load (fname=0x89e3f40 "base.jl") at builtins.c:502
#7  0x0806ab1c in jl_load_ (str=0x89e6950) at builtins.c:509
#8  0xb7600383 in ?? ()
#9  0x08060085 in jl_apply (f=0x89eb190, args=0xbfffda54, nargs=1) at ./julia.h:780
#10 0x08061b6d in jl_apply_generic (F=0x89b3330, args=0xbfffda54, nargs=1) at gf.c:1185
#11 0x080c6fc5 in jl_apply (f=0x89b3330, args=0xbfffda54, nargs=1) at ./julia.h:780
#12 0x080c6f5f in do_call (f=0x89b3330, args=0x89f2d64, nargs=1, locals=0x0, nl=0) at interpreter.c:57
#13 0x080c5c7d in eval (e=0x89ec560, locals=0x0, nl=0) at interpreter.c:115
#14 0x080c58fe in jl_interpret_toplevel_expr (e=0x89ec560) at interpreter.c:20
#15 0x08069f26 in jl_toplevel_eval_flex (e=0x89eb1c0, fast=0, plineno=0xbfffe1d8) at builtins.c:387
#16 0x0806a5f2 in jl_load_file_expr (fname=0x899b410 "/home/jameson/julia-clang/jl/sysimg.jl", ast=0x89eb1b0) at builtins.c:446
#17 0x0806aac2 in jl_load (fname=0x8965aa0 "sysimg.jl") at builtins.c:502
#18 0x0806ab1c in jl_load_ (str=0x89cdcc8) at builtins.c:509
#19 0xb7600383 in ?? ()
#20 0x08069755 in jl_apply (f=0x89eb190, args=0xbfffe404, nargs=1) at ./julia.h:780
#21 0x0806ca7f in jl_trampoline (F=0x89eb190, args=0xbfffe404, nargs=1) at builtins.c:895
#22 0x08060085 in jl_apply (f=0x89eb190, args=0xbfffe404, nargs=1) at ./julia.h:780
#23 0x08061b6d in jl_apply_generic (F=0x89b3330, args=0xbfffe404, nargs=1) at gf.c:1185
#24 0x080c6fc5 in jl_apply (f=0x89b3330, args=0xbfffe404, nargs=1) at ./julia.h:780
#25 0x080c6f5f in do_call (f=0x89b3330, args=0x89e3ef4, nargs=1, locals=0x0, nl=0) at interpreter.c:57
#26 0x080c5c7d in eval (e=0x89eb180, locals=0x0, nl=0) at interpreter.c:115
#27 0x080c58fe in jl_interpret_toplevel_expr (e=0x89eb180) at interpreter.c:20
#28 0x08069f26 in jl_toplevel_eval_flex (e=0x89b3b90, fast=0, plineno=0xbfffed78) at builtins.c:387
#29 0x08069b10 in jl_eval_module_expr (ex=0x89b3480, plineno=0xbfffed78) at builtins.c:264
#30 0x08069ce1 in jl_toplevel_eval_flex (e=0x89b3480, fast=0, plineno=0xbfffed78) at builtins.c:349
#31 0x0806a5f2 in jl_load_file_expr (fname=0x89ae0b8 "/home/jameson/julia-clang/jl/stage0.jl", ast=0x89b3470) at builtins.c:446
#32 0x0806aac2 in jl_load (fname=0xbffff2f0 "stage0.jl") at builtins.c:502
#33 0x080513de in exec_program ()
#34 0x08050fc2 in true_main ()
#35 0x080cd11e in julia_trampoline (argc=1, argv=0xbffff15c, pmain=0x8050e00 <true_main>) at init.c:203
#36 0x0805166a in main ()

@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 18, 2012

Out of curiosity, I built src/flisp and src/support with gcc, then everything else with clang (on my mac). Somewhat surprisingly (to me at least :), the backtrace was the same in my previous post.

@JeffBezanson
Copy link
Sponsor Member

Now that is fascinating... fl_applyn is the problem, and it is a varargs function. The backtrace here actually shows 1 less argument to it than is present in the source code. Must be calling convention related.

@ViralBShah
Copy link
Member Author

I bet the ubuntu stacktrace will be the same as what I posted or the mac one, if you build flisp and support in debug mode also. Use src/Makefile.debug for that.

-viral

On 18-Mar-2012, at 10:34 AM, Jameson Nash wrote:

Here's my backtrace, based on Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn). (note that sys0.ji built ok, it's stage1 that failed)

(lldb) run -J sys0.ji stage1.jl                                                                                                                 Process 70160 launched: '/Users/jameson/Documents/no-backup/julia/julia' (x86_64)
Process 70160 stopped
* thread #1: tid = 0x1f03, 0x00000001006658c3 julia`apply_cl + 99 at flisp.c:958, stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
   frame #0: 0x00000001006658c3 julia`apply_cl + 99 at flisp.c:958
  955      apply_cl_top:
  956         captured = 0;
  957         func = Stack[SP-nargs-1];
-> 958        ip = cv_data((cvalue_t*)ptr(fn_bcode(func)));
  959         assert(!ismanaged((uptrint_t)ip));
  960         while (SP+GET_INT32(ip) > N_STACK) {
  961             grow_stack();
(lldb) 

And on Ubuntu clang version 2.9 (tags/RELEASE_29/final) i386-pc-linux-gnu

(gdb) run -b stage0.jl
Starting program: /home/jameson/julia-clang/julia-debug-readline -b stage0.jl
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x0879499d in apply_cl (nargs=1) at flisp.c:958
958         ip = cv_data((cvalue_t*)ptr(fn_bcode(func)));
(gdb) bt
#0  0x0879499d in apply_cl (nargs=1) at flisp.c:958
#1  0x0878af91 in _applyn (n=1) at flisp.c:629
#2  0x0878b158 in fl_applyn (n=1, f=3078179338) at flisp.c:674
#3  0x08066479 in jl_expand (expr=0x89fe160) at ast.c:446
#4  0x08069d7f in jl_toplevel_eval_flex (e=0x89fe160, fast=0, plineno=0xbfffd8a8) at builtins.c:362
#5  0x0806a5f2 in jl_load_file_expr (fname=0x89a7fa8 "/home/jameson/julia-clang/jl/base.jl", ast=0x89ec570) at builtins.c:446
#6  0x0806aac2 in jl_load (fname=0x89e3f40 "base.jl") at builtins.c:502
#7  0x0806ab1c in jl_load_ (str=0x89e6950) at builtins.c:509
#8  0xb7600383 in ?? ()
#9  0x08060085 in jl_apply (f=0x89eb190, args=0xbfffda54, nargs=1) at ./julia.h:780
#10 0x08061b6d in jl_apply_generic (F=0x89b3330, args=0xbfffda54, nargs=1) at gf.c:1185
#11 0x080c6fc5 in jl_apply (f=0x89b3330, args=0xbfffda54, nargs=1) at ./julia.h:780
#12 0x080c6f5f in do_call (f=0x89b3330, args=0x89f2d64, nargs=1, locals=0x0, nl=0) at interpreter.c:57
#13 0x080c5c7d in eval (e=0x89ec560, locals=0x0, nl=0) at interpreter.c:115
#14 0x080c58fe in jl_interpret_toplevel_expr (e=0x89ec560) at interpreter.c:20
#15 0x08069f26 in jl_toplevel_eval_flex (e=0x89eb1c0, fast=0, plineno=0xbfffe1d8) at builtins.c:387
#16 0x0806a5f2 in jl_load_file_expr (fname=0x899b410 "/home/jameson/julia-clang/jl/sysimg.jl", ast=0x89eb1b0) at builtins.c:446
#17 0x0806aac2 in jl_load (fname=0x8965aa0 "sysimg.jl") at builtins.c:502
#18 0x0806ab1c in jl_load_ (str=0x89cdcc8) at builtins.c:509
#19 0xb7600383 in ?? ()
#20 0x08069755 in jl_apply (f=0x89eb190, args=0xbfffe404, nargs=1) at ./julia.h:780
#21 0x0806ca7f in jl_trampoline (F=0x89eb190, args=0xbfffe404, nargs=1) at builtins.c:895
#22 0x08060085 in jl_apply (f=0x89eb190, args=0xbfffe404, nargs=1) at ./julia.h:780
#23 0x08061b6d in jl_apply_generic (F=0x89b3330, args=0xbfffe404, nargs=1) at gf.c:1185
#24 0x080c6fc5 in jl_apply (f=0x89b3330, args=0xbfffe404, nargs=1) at ./julia.h:780
#25 0x080c6f5f in do_call (f=0x89b3330, args=0x89e3ef4, nargs=1, locals=0x0, nl=0) at interpreter.c:57
#26 0x080c5c7d in eval (e=0x89eb180, locals=0x0, nl=0) at interpreter.c:115
#27 0x080c58fe in jl_interpret_toplevel_expr (e=0x89eb180) at interpreter.c:20
#28 0x08069f26 in jl_toplevel_eval_flex (e=0x89b3b90, fast=0, plineno=0xbfffed78) at builtins.c:387
#29 0x08069b10 in jl_eval_module_expr (ex=0x89b3480, plineno=0xbfffed78) at builtins.c:264
#30 0x08069ce1 in jl_toplevel_eval_flex (e=0x89b3480, fast=0, plineno=0xbfffed78) at builtins.c:349
#31 0x0806a5f2 in jl_load_file_expr (fname=0x89ae0b8 "/home/jameson/julia-clang/jl/stage0.jl", ast=0x89b3470) at builtins.c:446
#32 0x0806aac2 in jl_load (fname=0xbffff2f0 "stage0.jl") at builtins.c:502
#33 0x080513de in exec_program ()
#34 0x08050fc2 in true_main ()
#35 0x080cd11e in julia_trampoline (argc=1, argv=0xbffff15c, pmain=0x8050e00 <true_main>) at init.c:203
#36 0x0805166a in main ()

Reply to this email directly or view it on GitHub:
#602 (comment)

@ViralBShah
Copy link
Member Author

We use -std=gnu99 with gcc in Make.inc, which suggests some kind of dependency on a GNU standard. As per clang docs, it also defaults to the gnu99 standard.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Mar 18, 2012

I don't know if it helps, but here's a more complete traceback from my mac:
(I think gdb is just ignoring varags in the function count.)

frame #0: 0x00000001006658c3 julia`apply_cl + 99 at flisp.c:958
   955   apply_cl_top:
   956      captured = 0;
   957      func = Stack[SP-nargs-1];
-> 958      ip = cv_data((cvalue_t*)ptr(fn_bcode(func)));
   959      assert(!ismanaged((uptrint_t)ip));
   960      while (SP+GET_INT32(ip) > N_STACK) {
   961          grow_stack();
(lldb) frame variable
(uint32_t) nargs = 1
(uint32_t) top_frame = 0
(uint32_t) n = 0
(uint32_t) captured = 0
(uint32_t) bp = 32767
(const uint8_t *) ip = 0x0000000100c305f0
(fixnum_t) s = 4307748336
(fixnum_t) hi = 4307864080
(uint32_t) i = 0
(symbol_t *) sym = 0x0000000100654e6a
(lldb) up
frame select -r 1
frame #1: 0x000000010065c9ee julia`_applyn + 206 at flisp.c:629
   626          v = ((builtin_t*)ptr(f))[3](&Stack[SP-n], n);
   627      }
   628      else if (isfunction(f)) {
-> 629          v = apply_cl(n);
   630      }
   631      else if (isbuiltin(f)) {
   632          value_t tab = symbol_value(builtins_table_sym);
(lldb) frame variable
(uint32_t) n = 1
(value_t) f = 4334490402
(uint32_t) saveSP = 2
(value_t) v = 15855067719180737544
(lldb) up
frame select -r 1
frame #2: 0x000000010065cd39 julia`fl_applyn + 649 at flisp.c:674
   671          value_t a = va_arg(ap, value_t);
   672          PUSH(a);
   673      }
-> 674      value_t v = _applyn(n);
   675      POPN(n+1);
   676      va_end(ap);
   677      return v;
(lldb) frame variable
(uint32_t) n = 1
(value_t) f = 4334490402
(va_list) ap = {
  [0] = {
    gp_offset = 24
    fp_offset = 48
    overflow_arg_area = 0x00007fff5fbfd0f0
    reg_save_area = 0x00007fff5fbfcfe0
  }
}
(size_t) i = 1
(value_t) v = 140734799794368
(lldb) up
frame select -r 1
frame #3: 0x0000000100014fdb julia`jl_expand + 107 at ast.c:439
   436  {
   437      int np = jl_gc_n_preserved_values();
   438      value_t e = fl_applyn(1, symbol_value(symbol("jl-expand-to-thunk")),
-> 439                            julia_to_scm(expr));
   440      jl_value_t *result;
   441      if (e == FL_T || e == FL_F || e == FL_EOF) {
   442          result = NULL;
(lldb) frame variable
(jl_value_t *) expr = 0x00000001013ef028
(int) np = 0
(value_t) e = 4295364389
(jl_value_t *) result = 0x00007fff5fbfd140
(lldb) 

JeffBezanson added a commit that referenced this issue Mar 19, 2012
@JeffBezanson
Copy link
Sponsor Member

D'oh. julia_to_scm, of course, allocates scheme objects, causing the object returned by symbol_value to move if a gc happens. The compilers were evaluating the arguments in different orders.

@ViralBShah
Copy link
Member Author

Compiles fine with clang for me now, but goes into infinite loop in the hashing tests on OS X. Does anyone else see this? Surprisingly, CPU usage is 30% only.

I am reopening this - with an updated title.

@ViralBShah ViralBShah reopened this Mar 19, 2012
@JeffBezanson
Copy link
Sponsor Member

Excellent; our infinite loops are efficient :)

@JeffBezanson
Copy link
Sponsor Member

I get everything passing in debug build, and the hashing test segfaults in release build :(

@ViralBShah
Copy link
Member Author

The debug build completes all the tests successfully. The release build does not.

@ViralBShah
Copy link
Member Author

Works for me now.

LilithHafner pushed a commit to LilithHafner/julia that referenced this issue Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants