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

Compiling with '-pack' and '-a x.ml -o x.cma' succeeds and but the executable segfaults #7479

Closed
vicuna opened this issue Feb 9, 2017 · 3 comments

Comments

@vicuna
Copy link

vicuna commented Feb 9, 2017

Original bug ID: 7479
Reporter: etc
Status: resolved (set by @xavierleroy on 2017-02-19T16:50:01Z)
Resolution: fixed
Priority: normal
Severity: minor
Platform: Linux
OS: arch linux
OS Version: 4.7.2-1
Version: 4.02.3
Target version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Fixed in version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Category: back end (clambda to assembly)

Bug description

Compiling with -pack and -a x.ml -o x.cma will succeed but when it's linked and used it will segfault.

I found that by changing the makefile to use -c x.ml -o x.cmo instead is how it's supposed to be done. Maybe compiling with -a shouldn't succeed when it's also -pack?

Steps to reproduce

Clone this git repository: https://github.com/Charlesetc/ocaml-segfault/

$ make
$ ./test.byte

Additional information

On the same git repo, there's a "success" branch https://github.com/Charlesetc/ocaml-segfault/tree/success, which has a change in the command that actually works. Thanks for taking a look!

@vicuna
Copy link
Author

vicuna commented Feb 19, 2017

Comment author: @xavierleroy

As far as I see the problem comes from
ocamlc -I pear -pack pear/grape.cma -o pear.cma
i.e. an attempt to build a pack from multiple compilation units found in grape.cma.

(By the way, -pack always produces a single object file, so the output should be "-o pear.cmo". But .cmo and .cma have different magic numbers so ocamlc is not confused.)

Here we get a pear.cmi that contains
module Pear : sig module Grape : sig ... end end
but a pear.cmo/pear.cma that contains
0 CONST0
1 MAKEBLOCK1 0
3 SETGLOBAL Pear
i.e. that sets Pear = struct end (the empty module). Hence the segfault when Pear is used in Main.

@vicuna
Copy link
Author

vicuna commented Feb 19, 2017

Comment author: @xavierleroy

Also: you write "Compiling with -pack and -a x.ml -o x.cma... will segfault", but this is not what your repro is testing. Are there other problems with the combination you describe but do not reproduce?

@vicuna
Copy link
Author

vicuna commented Feb 19, 2017

Comment author: @xavierleroy

Fixed the easy way in 4.05: ocamlc -pack rejects arguments that are .cma files, and ocamlopt -pack rejects arguments that are .cmxa files.

@vicuna vicuna closed this as completed Feb 19, 2017
@vicuna vicuna added this to the 4.05.0 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
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