You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 4878 Reporter: kiyoshi Status: closed (set by @xavierleroy on 2010-04-18T13:02:42Z) Resolution: not a bug Priority: normal Severity: tweak Version: 3.11.1 Category: ~DO NOT USE (was: OCaml general) Child of:#4841
Bug description
Cannot make callbacks from C code when using the -output-obj option under Mac OS X (other solution of 0004841)
ocamlopt -output-obj fails as follows:
$ cat a.ml
module A = struct
let inc_ml x = x + 1
end
as -arch x86_64 -o 'a.o' '/var/folders/fy/fyZMID8GGf0SqwDNwWx2XE+++TM/-Tmp-/camlasm26b96d.s'
as -arch x86_64 -o '/var/folders/fy/fyZMID8GGf0SqwDNwWx2XE+++TM/-Tmp-/camlstartupd0c5bb.o' '/var/folders/fy/fyZMID8GGf0SqwDNwWx2XE+++TM/-Tmp-/camlstartup7ac4c2.s'
ld -r -o 'a.o' '/var/folders/fy/fyZMID8GGf0SqwDNwWx2XE+++TM/-Tmp-/camlstartupd0c5bb.o' 'a.o' '/opt/local/lib/ocaml/stdlib.a'
$ cc -o a.out a.o a_impl.o -L/opt/local/lib/ocaml -lasmrun
Undefined symbols:
"_caml_apply2", referenced from:
_caml_callback2_exn in libasmrun.a(amd64.o)
"_caml_apply3", referenced from:
_caml_callback3_exn in libasmrun.a(amd64.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
$ nm -m a.o | grep _caml_apply[23]
0000000000000100 (__TEXT,__text) non-external _caml_apply2
00000000000000b0 (__TEXT,__text) non-external _caml_apply3
I know this problem was discussed and resolved in 0004841, but I also know "ld" command with "-keep_private_externs" option works well.
So I propose another way to resolve the problem.
Please refer to a patch attached to this report.
I think that this solution is more simple because ocamlopt can emit ".private_extern" declaration whether "-output-obj" option is specified or not.
A patched ocamlopt works well as follows:?
$ ocamlopt-patched -verbose -output-obj -o a.o a.ml
as -arch x86_64 -o 'a.o' '/var/folders/fy/fyZMID8GGf0SqwDNwWx2XE+++TM/-Tmp-/camlasmdf8f90.s'
as -arch x86_64 -o '/var/folders/fy/fyZMID8GGf0SqwDNwWx2XE+++TM/-Tmp-/camlstartup049736.o' '/var/folders/fy/fyZMID8GGf0SqwDNwWx2XE+++TM/-Tmp-/camlstartup56daaa.s'
$ uname -v
Darwin Kernel Version 10.0.0: Fri Jul 31 22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.6.1
BuildVersion: 10B504
$ port version
Version: 1.8.1
$ port list installed | grep ocaml
ocaml @3.11.1 lang/ocaml
$ cc -verson
i686-apple-darwin10-gcc-4.2.1: no input files
$
The fix of #4841 seems adequate so far. I'll keep your alternate fix in mind if the problem reappears later, but for the time being I'm closing this PR.
Original bug ID: 4878
Reporter: kiyoshi
Status: closed (set by @xavierleroy on 2010-04-18T13:02:42Z)
Resolution: not a bug
Priority: normal
Severity: tweak
Version: 3.11.1
Category: ~DO NOT USE (was: OCaml general)
Child of: #4841
Bug description
Cannot make callbacks from C code when using the -output-obj option under Mac OS X (other solution of 0004841)
ocamlopt -output-obj fails as follows:
$ cat a.ml
module A = struct
let inc_ml x = x + 1
end
let _ = Callback.register "A.inc_ml" A.inc_ml
$ cat a_impl.c
#include <stdio.h>
#include <caml/callback.h>
main (int argc, char** argv) {
caml_main(argv);
fprintf(stdout, "%li\n", Long_val(caml_callback_exn(*caml_named_value("A.inc_ml"), Val_long(1))));
fflush(stdout);
return 0;
}
$ cc -c -I /opt/local/lib/ocaml a_impl.c -o a_impl.o
$ ocamlopt -verbose -output-obj -o a.o a.ml
$ cc -o a.out a.o a_impl.o -L/opt/local/lib/ocaml -lasmrun
Undefined symbols:
"_caml_apply2", referenced from:
_caml_callback2_exn in libasmrun.a(amd64.o)
"_caml_apply3", referenced from:
_caml_callback3_exn in libasmrun.a(amd64.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
$ nm -m a.o | grep _caml_apply[23]
0000000000000100 (__TEXT,__text) non-external _caml_apply2
00000000000000b0 (__TEXT,__text) non-external _caml_apply3
I know this problem was discussed and resolved in 0004841, but I also know "ld" command with "-keep_private_externs" option works well.
So I propose another way to resolve the problem.
Please refer to a patch attached to this report.
I think that this solution is more simple because ocamlopt can emit ".private_extern" declaration whether "-output-obj" option is specified or not.
A patched ocamlopt works well as follows:?
$ ocamlopt-patched -verbose -output-obj -o a.o a.ml
$ cc -o a.out a.o a_impl.o -L/opt/local/lib/ocaml -lasmrun
$ nm -m a.o | grep _caml_apply[23]
0000000000000100 (__TEXT,__text) private external _caml_apply2
00000000000000b0 (__TEXT,__text) private external _caml_apply3
$ ./a.out
2
$
Additional information
$ uname -v
Darwin Kernel Version 10.0.0: Fri Jul 31 22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.6.1
BuildVersion: 10B504
$ port version
Version: 1.8.1
$ port list installed | grep ocaml
ocaml @3.11.1 lang/ocaml
$ cc -verson
i686-apple-darwin10-gcc-4.2.1: no input files
$
File attachments
The text was updated successfully, but these errors were encountered: