Skip to content

Linking modules compiled with -labels and -nolabels is not safe #7432

@vicuna

Description

@vicuna

Original bug ID: 7432
Reporter: @yallop
Assigned to: @garrigue
Status: resolved (set by @garrigue on 2016-12-17T01:38:18Z)
Resolution: fixed
Priority: normal
Severity: minor
Fixed in version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Category: typing
Monitored by: @hcarty

Bug description

The -labels and -nolabels modes of the compiler have different views of type equality. There are some types that are considered equal with -nolabels, but incompatible with -labels.

It's possible, therefore, to pass a witness of type equality (compiled with -nolabels) to a function compiled (with -labels) under the assumption that no such witness can exist, leading to a crash.

Here's a demonstration:

$ cat a.ml 
type (_,_) eql = Refl : ('a, 'a) eql
type s = x:int -> y:float -> unit
type t = y:int -> x:float -> unit
let eql : (s, t) eql = Refl
$ cat b.ml 
open A

type silly = {silly: 'a.'a}

let f : [`L of (s, t) eql | `R of silly] -> 'a =
   function `R {silly} -> silly
let () = print_endline (f (`L A.eql))
$ ocamlopt -c -nolabels a.ml  && ocamlopt -c  b.ml && ocamlopt a.cmx b.cmx -o a.out
$ ./a.out 
Segmentation fault

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions