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

Ocamlopt generates segfaulting binary #5474

Closed
vicuna opened this issue Jan 12, 2012 · 7 comments
Closed

Ocamlopt generates segfaulting binary #5474

vicuna opened this issue Jan 12, 2012 · 7 comments

Comments

@vicuna
Copy link

vicuna commented Jan 12, 2012

Original bug ID: 5474
Reporter: dlovasko
Status: closed (set by @xavierleroy on 2012-09-25T18:10:24Z)
Resolution: unable to duplicate
Priority: normal
Severity: crash
Platform: x86_64
OS: Linux x86_64
OS Version: openSUSE 11.4
Version: 3.12.0
Category: -for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues
Monitored by: @protz mehdi @glondu

Bug description

source code:
let _ = Printf.printf "hello\n"

compilation:
ocamlopt -o foo ocaml.segfault.ml

result:
see attachment

after running the executable, error pops out:
Program received signal SIGSEGV, Segmentation fault.
0x000000000062ee00 in strcpy@@GLIBC_2.2.5 ()

the same code, but in ocaml interpreter works

glibc version: "2.11.3-12.15.1"

Steps to reproduce

Run the attachment

@vicuna
Copy link
Author

vicuna commented Jan 12, 2012

Comment author: @ygrek

cannot reproduce

@vicuna
Copy link
Author

vicuna commented Jan 12, 2012

Comment author: dlovasko

works(reproducing) for me:

ocaml-3.12.0-11.1.2.x86_64
glibc-2.14.1-14.12.5.x86_64
openSUSE 12.1

are you running the executable attached, or have you compiled one yourself?

@vicuna
Copy link
Author

vicuna commented Jan 12, 2012

Comment author: @ygrek

There is nothing attached. Where did you get ocaml from - self-compiled or from suse package? In the latter case - you'd better first discuss this issue with suse packagers.

@vicuna
Copy link
Author

vicuna commented Jan 12, 2012

Comment author: dlovasko

somehow the upload does not work for me, so i uploaded the binary here, please try it:
http://www.2shared.com/file/-V0LOCXj/foo.html

@vicuna
Copy link
Author

vicuna commented Jan 12, 2012

Comment author: @glondu

Indeed, the executable provided segfaults in a virtual machine running Debian stable. But I cannot reproduce it by recompiling from sources (but I tried only 3.12.1). I guess something is wrong with your toolchain.

strace output:

[...]
brk(0) = 0xec9000
brk(0xeea000) = 0xeea000
mmap(NULL, 270336, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0aef5f1000
mmap(NULL, 1024000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f0aef4f7000
sigaltstack({ss_sp=0x62f0a0, ss_flags=0, ss_size=8192}, NULL) = 0
rt_sigaction(SIGSEGV, {0x410e80, [], SA_RESTORER|SA_STACK|SA_NODEFER|SA_SIGINFO, 0x7f0aeec6a1e0}, NULL, 8) = 0
readlink("/proc/self/exe", "/home/steph/foo", 256) = 15
stat("/home/steph/foo", {st_mode=S_IFREG|0755, st_size=572315, ...}) = 0
lseek(0, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
lseek(1, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
lseek(2, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
rt_sigaction(SIGSEGV, {SIG_DFL, [], SA_RESTORER, 0x7f0aeec6a1e0}, NULL, 8) = 0
rt_sigreturn(0xb) = 15540656
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++

ltrace output:

__libc_start_main(0x40fecc, 1, 0x7fff705a20f8, 0x41fcc0, 0x41fd50 <unfinished ...>
malloc(16) = 0x00fa8010
malloc(16) = 0x00fa8030
malloc(16) = 0x00fa8050
getenv("OCAMLRUNPARAM") = NULL
getenv("CAMLRUNPARAM") = NULL
calloc(1024, 8) = 0x00fa8070
malloc(266240) = 0x7f7f9c152010
malloc(1019936) = 0x7f7f9c058010
malloc(16384) = 0x00faa080
sigemptyset(0x7fff705a1f18) = 0
sigaltstack(0x7fff705a1fb0, 0, 10, 0, 0xffffffff) = 0
sigaction(11, 0x7fff705a1f10, NULL) = 0
readlink(0x42127d, 0x636ca0, 256, -1, 0) = 15
__xstat64(1, "/home/steph/foo", 0x7fff705a1f30) = 0
__sigsetjmp(0x639040, 0, 0, -1, 0) = 0
malloc(4176) = 0x00fae090
lseek64(0, 0, 1, 0xfae080, 0) = -1
malloc(4176) = 0x00faf0f0
lseek64(1, 0, 1, 0xfaf0e0, 4) = -1
malloc(4176) = 0x00fb0150
lseek64(2, 0, 1, 0xfb0140, 4) = -1
malloc(45) = 0x00fb11b0
--- SIGSEGV (Segmentation fault) ---
getrlimit64(3, 0x630c90, 0x630cc0, 0xfb11a0, 0x7f7f9baf5ec8) = 0
sigemptyset(0x00630bf8) = 0
sigaction(11, 0x00630bf0, NULL) = 0
unexpected breakpoint at 0x62edff
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++

It looks like something is wrong in the initialization of the OCaml runtime. Did you try recompiling OCaml yourself, then use it to generate foo?

@vicuna
Copy link
Author

vicuna commented Jan 12, 2012

Comment author: @glondu

Oh, and the backtrace (with gdb):

#0 0x000000000062ee00 in strcpy@@GLIBC_2.2.5 ()
#1 0x000000000041bb4d in caml_register_named_value (vname=6461304, val=6459320) at /usr/include/bits/string3.h:105
#2 0x000000000041da24 in caml_c_call ()
#3 0x00000000000003e8 in ?? ()
#4 0x0000000000404e29 in caml_program ()
#5 0x000000000008bb9b in ?? ()
#6 0x000000000041da7a in caml_start_program ()
#7 0x0000000000000000 in ?? ()

@vicuna
Copy link
Author

vicuna commented Jan 12, 2012

Comment author: @glondu

I couldn't reproduce your segfaulting executable, even with an openSUSE 12.1 live CD and the same version of ocaml and glibc. The version of binutils is 2.21.1-12.1.4.

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

No branches or pull requests

1 participant