Dear all,
is there a reason that one should not be able to statically link a
Fortran binary that has been compiled with -fopenmp?
A tiny example seems to fail for me with all gfortran versions:
program p
!$omp parallel
!$omp end parallel
end
% gfortran -fopenmp foo.f90 -g -static
% OMP_NUM_THREADS=1 ./a.out
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
[...]
Running under gdb:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x0000000000405198 in __gthread_mutex_destroy (__mutex=0x72ced8)
at ../libgcc/gthr-default.h:739
#2 destroy_unit_mutex (u=0x72ce00) at ../../../libgfortran/io/unit.c:252
#3 close_unit_1 (u=0x72ce00, locked=locked@entry=1) at
../../../libgfortran/io/unit.c:743
#4 0x0000000000405202 in _gfortrani_close_units () at
../../../libgfortran/io/unit.c:780
#5 0x000000000044c53c in __libc_csu_fini () at elf-init.c:100
#6 0x0000000000452ef0 in __run_exit_handlers (status=0, listp=0x720630
<__exit_funcs>,
run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true)
at exit.c:83
#7 0x0000000000452f4a in exit (status=<optimized out>) at exit.c:105
#8 0x000000000044bdc6 in __libc_start_main (main=0x4030bd <main>, argc=1,
argv=0x7fffffffc348, init=0x44c470 <__libc_csu_init>, fini=0x44c510
<__libc_csu_fini>,
rtld_fini=0x0, stack_end=0x7fffffffc338) at ../csu/libc-start.c:342
#9 0x0000000000402fba in _start () at ../sysdeps/x86_64/start.S:120
I suspect either a locking issue for unit_root in unit.c, or maybe bad
initialization of it, but haven't stared long enough at the code.
According to git blame almost all related references date back to 2005.
Shall I open a PR against libfortran? Or is there something I am missing?
Thanks,
Harald