Issue 1:
Real reason is the OOM killer (see the updated title and comment below)

Original post:

With the patch below (the /dev/tty part might not be necessary) I've got the following backtrace on a machine that can reproduce the EOFError issue (or what looks like it)

signal (8): Floating point exception
__gmp_exception at /usr/lib/libgmp.so (unknown line)
unknown function (ip: 1705129166)
__gmpz_powm at /usr/lib/libgmp.so (unknown line)
powermod at ./gmp.jl:424
powermod at ./gmp.jl:430
unknown function (ip: 1399079124)
jl_apply_generic at /home/yuyichao/project/julia/src/gf.c:1663
anonymous at ./test.jl:105
do_test_throws at ./test.jl:59
jl_apply_generic at /home/yuyichao/project/julia/src/gf.c:1663
do_call at /home/yuyichao/project/julia/src/interpreter.c:66
eval at /home/yuyichao/project/julia/src/interpreter.c:212
jl_toplevel_eval_flex at /home/yuyichao/project/julia/src/toplevel.c:539
jl_toplevel_eval_flex at /home/yuyichao/project/julia/src/toplevel.c:568
jl_load at /home/yuyichao/project/julia/src/toplevel.c:615
include at ./boot.jl:253
jl_apply_generic at /home/yuyichao/project/julia/src/gf.c:1663
runtests at /home/yuyichao/project/julia/test/testdefs.jl:198
unknown function (ip: 1711445219)
jl_apply_generic at /home/yuyichao/project/julia/src/gf.c:1663
jl_f_apply at /home/yuyichao/project/julia/src/builtins.c:473
anonymous at ./multi.jl:854
run_work_thunk at ./multi.jl:605
jl_apply_generic at /home/yuyichao/project/julia/src/gf.c:1663
anonymous at ./multi.jl:854
start_task at /home/yuyichao/project/julia/src/task.c:234
unknown function (ip: 0)

diff --git a/src/init.c b/src/init.c
index 06a58c7..a394b31 100644
--- a/src/init.c
+++ b/src/init.c
@@ -249,6 +249,12 @@ static int is_addr_on_stack(void *addr)

void sigdie_handler(int sig, siginfo_t *info, void *context)
{
+ int fd = open("/dev/tty", O_RDWR);
+ int oldfd1 = dup(1);
+ int oldfd2 = dup(2);
+ dup2(fd, 1);
+ dup2(fd, 2);
+ close(fd);
if (sig != SIGINFO) {
sigset_t sset;
uv_tty_reset_mode();
@@ -269,6 +275,10 @@ void sigdie_handler(int sig, siginfo_t *info, void *context)
sig != SIGINFO) {
raise(sig);
}
+ dup2(oldfd1, 1);
+ dup2(oldfd2, 2);
+ close(oldfd1);
+ close(oldfd2);
}
#endif

@@ -1201,6 +1211,9 @@ void jl_install_default_signal_handlers(void)
sigemptyset(&act_die.sa_mask);
act_die.sa_sigaction = sigdie_handler;
act_die.sa_flags = SA_SIGINFO;
+ for (int i = 0;i < 32;i++) {
+ sigaction(i, &act_die, NULL);
+ }
if (sigaction(SIGINFO, &act_die, NULL) < 0) {
jl_errorf("fatal error: sigaction: %s\n", strerror(errno));
}

Issue 2:
Hi there,

I'm pretty sure, that this is a bug:

function findclosestsquare(n::Real)
# a cannot be greater than the square root of n
# b cannot be smaller than the square root of n
# we get the maximum allowed value of a
amax = floor(sqrt(n));
if 0 == rem(n, amax)
# special case where n is a square number
return (amax, n / amax)
end
# Get its prime factors of n
primeFactors = factor(n);
# Start with a factor 1 in the list of candidates for a
candidates = Int[1]
for (f, _) in primeFactors
# Add new candidates which are obtained by multiplying
# existing candidates with the new prime factor f
# Set union ensures that duplicate candidates are removed
candidates = union(candidates, f .* candidates);
# throw out candidates which are larger than amax
filter!(x-> x <= amax, candidates)
end
# Take the largest factor in the list d
(Int(candidates[end])::Int, Int(n/candidates[end])::Int)::Tuple{Int, Int}
end
julia> findclosestsquare(8)
(2.0,4.0)
julia> findclosestsquare(10)
(2,5)

code llvm:

define %jl_value_t* @julia_findclosestsquare_21056(i64) {
top:
%1 = alloca [9 x %jl_value_t*], align 8
%.sub = getelementptr inbounds [9 x %jl_value_t*]* %1, i64 0, i64 0
%2 = getelementptr [9 x %jl_value_t*]* %1, i64 0, i64 2
store %jl_value_t* inttoptr (i64 14 to %jl_value_t*), %jl_value_t** %.sub, align 8
%3 = getelementptr [9 x %jl_value_t*]* %1, i64 0, i64 1
%4 = load %jl_value_t*** @jl_pgcstack, align 8
%.c = bitcast %jl_value_t** %4 to %jl_value_t*
store %jl_value_t* %.c, %jl_value_t** %3, align 8
store %jl_value_t** %.sub, %jl_value_t*** @jl_pgcstack, align 8
%5 = getelementptr [9 x %jl_value_t*]* %1, i64 0, i64 7
store %jl_value_t* null, %jl_value_t** %5, align 8
%6 = getelementptr [9 x %jl_value_t*]* %1, i64 0, i64 8
store %jl_value_t* null, %jl_value_t** %6, align 8
store %jl_value_t* null, %jl_value_t** %2, align 8
%7 = getelementptr [9 x %jl_value_t*]* %1, i64 0, i64 3
store %jl_value_t* null, %jl_value_t** %7, align 8
%8 = getelementptr [9 x %jl_value_t*]* %1, i64 0, i64 4
store %jl_value_t* null, %jl_value_t** %8, align 8
%9 = getelementptr [9 x %jl_value_t*]* %1, i64 0, i64 5
store %jl_value_t* null, %jl_value_t** %9, align 8
%10 = getelementptr [9 x %jl_value_t*]* %1, i64 0, i64 6
store %jl_value_t* null, %jl_value_t** %10, align 8
%11 = call %jl_value_t* @jl_new_box(%jl_value_t* null)
store %jl_value_t* %11, %jl_value_t** %2, align 8
%12 = sitofp i64 %0 to double
%13 = fcmp uge double %12, 0.000000e+00
br i1 %13, label %pass, label %fail

fail: ; preds = %top
%14 = load %jl_value_t** @jl_domain_exception, align 8
call void @jl_throw_with_superfluous_argument(%jl_value_t* %14, i32 5)
unreachable

pass: ; preds = %top
%15 = call double @llvm.sqrt.f64(double %12)
%16 = call double @llvm.floor.f64(double %15)
%17 = call %jl_value_t* @alloc_1w()
%18 = getelementptr inbounds %jl_value_t* %17, i64 -1, i32 0
store %jl_value_t* inttoptr (i64 140422167868560 to %jl_value_t*), %jl_value_t** %18, align 8
%19 = bitcast %jl_value_t* %17 to double*
store double %16, double* %19, align 8
%20 = getelementptr inbounds %jl_value_t* %11, i64 -1, i32 0
%21 = bitcast %jl_value_t** %20 to i64*
%22 = load i64* %21, align 8
%23 = and i64 %22, 1
%24 = icmp eq i64 %23, 0
br i1 %24, label %cont, label %wb_may_trigger

wb_may_trigger: ; preds = %pass
%25 = bitcast %jl_value_t** %18 to i64*
%26 = load i64* %25, align 8
%27 = and i64 %26, 1
%28 = icmp eq i64 %27, 0
br i1 %28, label %wb_trigger, label %cont

wb_trigger: ; preds = %wb_may_trigger
call void @gc_queue_root(%jl_value_t* %11)
br label %cont

cont: ; preds = %wb_trigger, %wb_may_trigger, %pass
%29 = getelementptr inbounds %jl_value_t* %11, i64 0, i32 0
store %jl_value_t* %17, %jl_value_t** %29, align 8
%30 = load %jl_value_t** %2, align 8
%31 = getelementptr inbounds %jl_value_t* %30, i64 0, i32 0
%32 = load %jl_value_t** %31, align 8
%33 = bitcast %jl_value_t* %32 to double*
%34 = load double* %33, align 8
%35 = frem double %12, %34
%36 = fcmp une double %35, 0.000000e+00
br i1 %36, label %L, label %if

if: ; preds = %cont
%37 = insertvalue [2 x double] undef, double %34, 0
%38 = fdiv double %12, %34
%39 = insertvalue [2 x double] %37, double %38, 1
%40 = call %jl_value_t* @allocobj(i64 16)
%41 = getelementptr inbounds %jl_value_t* %40, i64 -1, i32 0
store %jl_value_t* inttoptr (i64 140422167868464 to %jl_value_t*), %jl_value_t** %41, align 8
%42 = bitcast %jl_value_t* %40 to [2 x double]*
store [2 x double] %39, [2 x double]* %42, align 8
%43 = load %jl_value_t** %3, align 8
%44 = getelementptr inbounds %jl_value_t* %43, i64 0, i32 0
store %jl_value_t** %44, %jl_value_t*** @jl_pgcstack, align 8
ret %jl_value_t* %40

L: ; preds = %cont
%45 = call %jl_value_t* @julia_factor_20947(i64 %0)
store %jl_value_t* %45, %jl_value_t** %7, align 8
%46 = load %jl_value_t** inttoptr (i64 140422201087640 to %jl_value_t**), align 8
store %jl_value_t* %46, %jl_value_t** %5, align 8
store %jl_value_t* inttoptr (i64 140422167601280 to %jl_value_t*), %jl_value_t** %6, align 8
%47 = call %jl_value_t* @julia_getindex_20958(%jl_value_t* inttoptr (i64 140422221313200 to %jl_value_t*), %jl_value_t** %5, i32 2)
store %jl_value_t* %47, %jl_value_t** %8, align 8
%48 = call i64 @julia_skip_deleted_20959(%jl_value_t* %45, i64 1)
%49 = getelementptr inbounds %jl_value_t* %45, i64 2, i32 0
%50 = load %jl_value_t** %49, align 8
store %jl_value_t* %50, %jl_value_t** %9, align 8
%51 = getelementptr inbounds %jl_value_t* %50, i64 1
%52 = bitcast %jl_value_t* %51 to i64*
%53 = load i64* %52, align 8
%54 = icmp slt i64 %53, %48
br i1 %54, label %L7, label %L2.preheader

L2.preheader: ; preds = %L
%55 = getelementptr inbounds %jl_value_t* %45, i64 1, i32 0
br label %L2

L2: ; preds = %idxend4, %L2.preheader
%"#s1.0" = phi i64 [ %75, %idxend4 ], [ %48, %L2.preheader ]
%56 = load %jl_value_t** %55, align 8
%57 = add i64 %"#s1.0", -1
%58 = getelementptr inbounds %jl_value_t* %56, i64 1
%59 = bitcast %jl_value_t* %58 to i64*
%60 = load i64* %59, align 8
%61 = icmp ult i64 %57, %60
br i1 %61, label %idxend, label %oob

oob: ; preds = %L2
%62 = alloca i64, align 8
store i64 %"#s1.0", i64* %62, align 8
call void @jl_bounds_error_ints(%jl_value_t* %56, i64* %62, i64 1)
unreachable

idxend: ; preds = %L2
%63 = load %jl_value_t** %49, align 8
%64 = getelementptr inbounds %jl_value_t* %63, i64 1
%65 = bitcast %jl_value_t* %64 to i64*
%66 = load i64* %65, align 8
%67 = icmp ult i64 %57, %66
br i1 %67, label %idxend4, label %oob3

oob3: ; preds = %idxend
%68 = alloca i64, align 8
store i64 %"#s1.0", i64* %68, align 8
call void @jl_bounds_error_ints(%jl_value_t* %63, i64* %68, i64 1)
unreachable

idxend4: ; preds = %idxend
%69 = bitcast %jl_value_t* %56 to i8**
%70 = load i8** %69, align 8
%71 = bitcast i8* %70 to i64*
%72 = getelementptr i64* %71, i64 %57
%73 = load i64* %72, align 8
%74 = add i64 %"#s1.0", 1
%75 = call i64 @julia_skip_deleted_20959(%jl_value_t* %45, i64 %74)
%76 = load %jl_value_t** %8, align 8
store %jl_value_t* %76, %jl_value_t** %5, align 8
%77 = load %jl_value_t** %8, align 8
%78 = call %jl_value_t* @"julia_.*_20965"(i64 %73, %jl_value_t* %77)
store %jl_value_t* %78, %jl_value_t** %6, align 8
%79 = call %jl_value_t* @julia_union_20960(%jl_value_t* inttoptr (i64 140422221185360 to %jl_value_t*), %jl_value_t** %5, i32 2)
store %jl_value_t* %79, %jl_value_t** %8, align 8
%80 = load %jl_value_t** %2, align 8
%81 = call %jl_value_t* (i64, ...)* @jl_svec(i64 1, %jl_value_t* %80)
store %jl_value_t* %81, %jl_value_t** %5, align 8
%82 = call %jl_value_t* @jl_new_closure(i8* null, %jl_value_t* %81, %jl_value_t* inttoptr (i64 140422224092848 to %jl_value_t*))
store %jl_value_t* %82, %jl_value_t** %5, align 8
%83 = load %jl_value_t** %8, align 8
store %jl_value_t* %83, %jl_value_t** %6, align 8
%84 = call %jl_value_t* @"julia_filter!_20966"(%jl_value_t* inttoptr (i64 140422221154000 to %jl_value_t*), %jl_value_t** %5, i32 2)
%85 = load %jl_value_t** %49, align 8
store %jl_value_t* %85, %jl_value_t** %10, align 8
%86 = getelementptr inbounds %jl_value_t* %85, i64 1
%87 = bitcast %jl_value_t* %86 to i64*
%88 = load i64* %87, align 8
%89 = icmp slt i64 %88, %75
br i1 %89, label %L7, label %L2

L7: ; preds = %idxend4, %L
%90 = load %jl_value_t** %8, align 8
%91 = getelementptr inbounds %jl_value_t* %90, i64 1
%92 = bitcast %jl_value_t* %91 to i64*
%93 = load i64* %92, align 8
%uadd = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %93, i64 -1)
%94 = extractvalue { i64, i1 } %uadd, 1
br i1 %94, label %idxend11, label %oob8

oob8: ; preds = %L7
%95 = alloca i64, align 8
store i64 %93, i64* %95, align 8
call void @jl_bounds_error_ints(%jl_value_t* %90, i64* %95, i64 1)
unreachable

idxend11: ; preds = %L7
%96 = extractvalue { i64, i1 } %uadd, 0
%97 = bitcast %jl_value_t* %90 to i8**
%98 = load i8** %97, align 8
%99 = bitcast i8* %98 to i64*
%100 = getelementptr i64* %99, i64 %96
%101 = load i64* %100, align 8
%102 = sitofp i64 %101 to double
%103 = fdiv double %12, %102
%104 = fptosi double %103 to i64
%105 = sitofp i64 %104 to double
%106 = fptosi double %105 to i64
%107 = icmp eq i64 %104, %106
%108 = fcmp oeq double %103, %105
%109 = and i1 %108, %107
br i1 %109, label %pass13, label %fail12

fail12: ; preds = %idxend11
%110 = load %jl_value_t** @jl_inexact_exception, align 8
call void @jl_throw_with_superfluous_argument(%jl_value_t* %110, i32 23)
unreachable

pass13: ; preds = %idxend11
%111 = insertvalue [2 x i64] undef, i64 %101, 0
%112 = insertvalue [2 x i64] %111, i64 %104, 1
%113 = call %jl_value_t* @allocobj(i64 16)
%114 = getelementptr inbounds %jl_value_t* %113, i64 -1, i32 0
store %jl_value_t* inttoptr (i64 140422168339856 to %jl_value_t*), %jl_value_t** %114, align 8
%115 = bitcast %jl_value_t* %113 to [2 x i64]*
store [2 x i64] %112, [2 x i64]* %115, align 8
%116 = load %jl_value_t** %3, align 8
%117 = getelementptr inbounds %jl_value_t* %116, i64 0, i32 0
store %jl_value_t** %117, %jl_value_t*** @jl_pgcstack, align 8
ret %jl_value_t* %113
}

Julia version:

Julia Version 0.4.0-dev+5199

Commit 5ea501d (2015-06-04 05:45 UTC)

Platform Info:

System: Linux (x86_64-linux-gnu)

CPU: Intel(R) Core(TM) i3-4130 CPU @ 3.40GHz

WORD_SIZE: 64

BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)

LAPACK: libopenblas

LIBM: libopenlibm

LLVM: libLLVM-3.3

It was also present on:

Julia Version 0.4.0-dev+4566

Commit 74a0253 (2015-04-29 10:15 UTC)

Platform Info:

System: Windows (x86_64-w64-mingw32)

CPU: Intel(R) Core(TM) i5-4200U CPU @ 1.60GHz

WORD_SIZE: 64

BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)

LAPACK: libopenblas

LIBM: libopenlibm

LLVM: libLLVM-3.3