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

Build on OmniOS #9087

Closed
wants to merge 3 commits into from
Closed

Build on OmniOS #9087

wants to merge 3 commits into from

Conversation

mikeowens
Copy link

No description provided.

@xavierleroy
Copy link
Contributor

Some context to help review this PR:

OmniOS is a Unix distribution based on the Illumos kernel and core system, which is a descendant of Sun Solaris 2.

In #2024 we removed configure support for Solaris, along with other platforms that we were no longer actively supporting (e.g. no CI testing).

Before we accept this PR we should think of how OCaml on OmniOS will be tested and maintained in the future.

@mikeowens
Copy link
Author

Well for what it is worth, it seems to build and work perfectly on OmniOS/Illumos with very little modification. What's more, Illumos distros are the perfect host environments for OCaml applications precisely because they are so stable. I would be willing to help out with whatever is needed for CI as much as I can to get this supported, including providing a dedicated a OmniOS test machine. Solaris may be dead, but Illumos is certainly not.

@avsm
Copy link
Member

avsm commented Nov 4, 2019

It's excellent to see the Illumos kernel continue on! I notice that OmniOS publishes Amazon AMIs, so I could provision a machine or two on AWS for use by the Inria Jenkins CI. It'll be a while longer before we can meaningfully test opam on it, but we're on our way there with FreeBSD support being worked on for the next iteration of the opam CI at the moment...

@mikeowens
Copy link
Author

That is great to hear. If you need any help with OmniOS setup (which packages to install for compiler, headers etc.) or anything else, I will be glad to assist in any way I can.

@xavierleroy
Copy link
Contributor

I managed to install OmniOS as a VM in our CI system. This is good sign because I tried with IllumOS some time ago and could never get it to work.

However, I failed to build this PR on this OmniOS installation.

  • ./configure defaults to building for x86 32 bits, without native-code compilation. ./configure CC="gcc -m64" is necessary to get 64-bit support and native-code compilation. This would have been nice to mention, or even to autoselect as a default.

  • runtime/misc.c triggers a warning-as-error. This is actually a mistake in OCaml's code concerning the type pid_t. The fix is

--- a/runtime/misc.c
+++ b/runtime/misc.c
@@ -244,7 +244,7 @@ void caml_instr_atexit (void)
     char *name = fname;
 
     if (name[0] == '@'){
-      snprintf (buf, sizeof(buf), "%s.%d", name + 1, getpid ());
+      snprintf (buf, sizeof(buf), "%s.%ld", name + 1, (long)(getpid ()));
       name = buf;
     }
     if (name[0] == '+'){
  • Linking the bytecode interpreter fails:
gcc -m64 -O2 -fno-strict-aliasing -fwrapv -Wall -Werror -fno-tree-vrp -ffunction-sections -g -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE   -Wl,-E -o ocamlrun prims.o libcamlrun.a -lm  -lpthread -lposix4 -lsocket -lnsl -lrt -lresolv 
ld: fatal: unrecognized option '-E'
ld: fatal: use the -z help option for usage information

For reference, my configuration is:

$ uname -a
SunOS ocaml-omnios 5.11 omnios-r151030-1b80ce3d31 i86pc i386 i86pc
$ cat /etc/motd
OmniOS 5.11     omnios-r151030-1b80ce3d31       June 2019

@mikeowens
Copy link
Author

mikeowens commented Dec 8, 2019 via email

@mikeowens
Copy link
Author

mikeowens commented Dec 8, 2019 via email

@xavierleroy
Copy link
Contributor

Actually the changes are in my pull request:

I fetched your branch and ran "autoconf", then observed the two errors I reported (the fatal warning and the -Wl,-E option). Please make sure your pull request actually works.

@mikeowens
Copy link
Author

I am sorry. I found the problem. Starting at line 772 in configure.ac the clause should be changed to the following:

AS_IF([test x"$enable_shared" != "xno"],
  [AS_CASE([$host],
    [*-apple-darwin*],
      [mksharedlib="$CC -shared -flat_namespace -undefined suppress \
                   -Wl,-no_compact_unwind"
      shared_libraries_supported=true],
    [*-*-mingw32],
      [mksharedlib='$(FLEXLINK)'
      mkmaindll='$(FLEXLINK) -maindll'
      shared_libraries_supported=$with_sharedlibs],
    [*-pc-windows],
      [mksharedlib='$(FLEXLINK)'
      mkmaindll='$(FLEXLINK) -maindll'
      shared_libraries_supported=$with_sharedlibs],
    [*-*-cygwin*],
      [mksharedlib="$flexlink"
      mkmaindll="$flexlink -maindll"
      shared_libraries_supported=true],
    [powerpc-ibm-aix*],
      [AS_CASE([$CC],
               [xlc*],
               [mksharedlib="$CC -qmkshrobj -G"
                shared_libraries_supported=true])],
    [*-*-solaris*],
      [sharedlib_cflags="-fPIC"
      mksharedlib="$CC -shared"
      oc_ldflags="$oc_ldflags"
      rpath="-Wl,-rpath,"
      mksharedlibrpath="-Wl,-rpath,"
      natdynlinkopts=""
      shared_libraries_supported=true],
    [[*-*-linux*|*-*-freebsd[3-9]*|*-*-freebsd[1-9][0-9]*\
    |*-*-openbsd*|*-*-netbsd*|*-*-dragonfly*|*-*-gnu*|*-*-haiku*]],
      [sharedlib_cflags="-fPIC"
      mksharedlib="$CC -shared"
      oc_ldflags="$oc_ldflags -Wl,-E"
      rpath="-Wl,-rpath,"
      mksharedlibrpath="-Wl,-rpath,"
      natdynlinkopts="-Wl,-E"
      shared_libraries_supported=true])])

Basically Solaris needs to be removed from the last case with Linux and FreeBSD et. al. and given its own special case to omit the -Wl,E flags.

I think my diff was taken against release 4.09.0 rather than trunk and that's why I missed this. I am very sorry for the inconvenience.

@mikeowens
Copy link
Author

Also, another issue I ran into on this build. I am not sure is the right way to handle this in all cases but it is needed on Illumos:

--- a/otherlibs/systhreads/st_stubs.c
+++ b/otherlibs/systhreads/st_stubs.c
@@ -15,6 +15,9 @@
 
 #define CAML_INTERNALS
 
+/* Needed for sigwait */
+#define _POSIX_PTHREAD_SEMANTICS
+
 #include "caml/alloc.h"
 #include "caml/backtrace.h"
 #include "caml/callback.h"

@mikeowens
Copy link
Author

mikeowens commented Dec 9, 2019

Let me just check out the latest version on trunk, reapply the changes, test again and then I will notify you. I will have it done in the next day or so.

@mikeowens
Copy link
Author

mikeowens commented Dec 10, 2019

I have merged the latest from trunk and updated my branch (https://github.com/mikeowens/ocaml) to include the above changes. I am running into the following problem however where some system link flags are not being passed correctly with respect to otherlibs/unix/libunix.a:

../ocamlopt.opt -nostdlib -I ../stdlib -o ocamldoc.opt -linkall -I ../utils -I ../parsing -I ../typing -I ../driver -I ../bytecomp -I ../toplevel -I ../stdlib -I ../compilerlibs -I ../otherlibs/str -I ../otherlibs/dynlink -I ../otherlibs/dynlink/native -I ../otherlibs/unix -nostdlib ocamlcommon.cmxa unix.cmxa str.cmxa dynlink.cmxa odoc_config.cmx odoc_messages.cmx odoc_global.cmx odoc_types.cmx odoc_misc.cmx odoc_text_parser.cmx odoc_text_lexer.cmx odoc_text.cmx odoc_name.cmx odoc_parameter.cmx odoc_value.cmx odoc_type.cmx odoc_extension.cmx odoc_exception.cmx odoc_class.cmx odoc_module.cmx odoc_print.cmx odoc_str.cmx odoc_comments_global.cmx odoc_parser.cmx odoc_lexer.cmx odoc_see_lexer.cmx odoc_env.cmx odoc_merge.cmx odoc_sig.cmx odoc_ast.cmx odoc_control.cmx odoc_inherit.cmx odoc_search.cmx odoc_scan.cmx odoc_cross.cmx odoc_comments.cmx odoc_dep.cmx odoc_analyse.cmx odoc_info.cmx odoc_dag2html.cmx odoc_to_text.cmx odoc_ocamlhtml.cmx odoc_html.cmx odoc_man.cmx odoc_latex_style.cmx odoc_latex.cmx odoc_texi.cmx odoc_dot.cmx odoc_gen.cmx odoc_args.cmx odoc.cmx
Undefined                       first referenced
 symbol                             in file
bind                                ../otherlibs/unix/libunix.a(bind.o)
recv                                ../otherlibs/unix/libunix.a(sendrecv.o)
send                                ../otherlibs/unix/libunix.a(sendrecv.o)
getservbyname                       ../otherlibs/unix/libunix.a(getserv.o)
getservbyport                       ../otherlibs/unix/libunix.a(getserv.o)
socketpair                          ../otherlibs/unix/libunix.a(socketpair.o)
gethostbyaddr_r                     ../otherlibs/unix/libunix.a(gethost.o)
getsockname                         ../otherlibs/unix/libunix.a(getsockname.o)
accept                              ../otherlibs/unix/libunix.a(accept.o)
gethostbyname_r                     ../otherlibs/unix/libunix.a(gethost.o)
listen                              ../otherlibs/unix/libunix.a(listen.o)
sendto                              ../otherlibs/unix/libunix.a(sendrecv.o)
socket                              ../otherlibs/unix/libunix.a(socket.o)
getprotobyname                      ../otherlibs/unix/libunix.a(getproto.o)
getprotobynumber                    ../otherlibs/unix/libunix.a(getproto.o)
setsockopt                          ../otherlibs/unix/libunix.a(sockopt.o)
getsockopt                          ../otherlibs/unix/libunix.a(channels.o)
connect                             ../otherlibs/unix/libunix.a(connect.o)
getpeername                         ../otherlibs/unix/libunix.a(getpeername.o)
recvfrom                            ../otherlibs/unix/libunix.a(sendrecv.o)
shutdown                            ../otherlibs/unix/libunix.a(shutdown.o)
ld: fatal: symbol referencing errors. No output written to ocamldoc.opt
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking
make[3]: *** [Makefile:233: ocamldoc.opt] Error 2
make[3]: Leaving directory '/tmp/mike-ocaml/ocamldoc'
make[2]: *** [Makefile:1109: ocamldoc.opt] Error 2
make[2]: Leaving directory '/tmp/mike-ocaml'
make[1]: *** [Makefile:424: opt.opt] Error 2
make[1]: Leaving directory '/tmp/mike-ocaml'
make: *** [Makefile:477: world.opt] Error 2

I am pretty sure these correspond to "-lsocket -lnsl -lrt -lresolv" which I did include in the (seemingly) relevant places in the configure.ac file. Somehow they are not being passed down to the correct place here. I think if this can get resolved then everything should build correctly.

@tleedjarv
Copy link
Contributor

tleedjarv commented Nov 29, 2020

@mikeowens are you still maintaining this PR? Will you rebase and update, or should I open a new PR?

A variation/simplification of this PR works well for me on OmniOS (with GCC).

diff --git a/Makefile.config.in b/Makefile.config.in
index 6252b5dc4..eae3fcb8a 100644
--- a/Makefile.config.in
+++ b/Makefile.config.in
@@ -172,6 +172,7 @@ OTHERLIBRARIES=@otherlibraries@
 # Needed for the "systhreads" package
 PTHREAD_LINK=@pthread_link@
 PTHREAD_CAML_LINK=$(addprefix -cclib ,$(PTHREAD_LINK))
+PTHREAD_CFLAGS=@PTHREAD_CFLAGS@
 
 UNIX_OR_WIN32=@unix_or_win32@
 UNIXLIB=@unixlib@
diff --git a/configure.ac b/configure.ac
index f96dfdedc..df2a8cd7d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -836,6 +836,12 @@ AS_IF([test x"$enable_shared" != "xno"],
                [xlc*],
                [mksharedlib="$CC -qmkshrobj -G"
                 shared_libraries_supported=true])],
+    [*-*-solaris*],
+      [sharedlib_cflags="-fPIC"
+      mksharedlib="$CC -shared"
+      rpath="-Wl,-rpath,"
+      mksharedlibrpath="-Wl,-rpath,"
+      shared_libraries_supported=true],
     [[*-*-linux*|*-*-freebsd[3-9]*|*-*-freebsd[1-9][0-9]*\
     |*-*-openbsd*|*-*-netbsd*|*-*-dragonfly*|*-*-gnu*|*-*-haiku*]],
       [sharedlib_cflags="-fPIC"
@@ -867,6 +873,7 @@ AS_IF([test x"$enable_shared" != "xno"],
     [x86_64-*-darwin*], [natdynlink=true],
     [s390x*-*-linux*], [natdynlink=true],
     [powerpc*-*-linux*], [natdynlink=true],
+    [x86_64-*-solaris*], [natdynlink=true],
     [i686-*-kfreebsd*], [natdynlink=true],
     [x86_64-*-kfreebsd*], [natdynlink=true],
     [x86_64-*-dragonfly*], [natdynlink=true],
@@ -964,6 +971,8 @@ AS_CASE([$host],
     [arch=amd64; system=gnu],
   [x86_64-*-dragonfly*],
     [arch=amd64; system=dragonfly],
+  [x86_64-*-solaris*],
+    [arch=amd64; system=solaris],
   [x86_64-*-freebsd*],
     [arch=amd64; system=freebsd],
   [x86_64-*-netbsd*],
@@ -1003,7 +1012,6 @@ AC_CHECK_TOOL([DIRECT_LD],[ld])
 AS_IF([test -z "$PARTIALLD"],
   [AS_CASE(["$arch,$CC,$system,$model"],
     [amd64,gcc*,macosx,*], [PACKLD_FLAGS=' -arch x86_64'],
-    [amd64,gcc*,solaris,*], [PACKLD_FLAGS=' -m elf_x86_64'],
     [power,gcc*,elf,ppc], [PACKLD_FLAGS=' -m elf32ppclinux'],
     [power,gcc*,elf,ppc64], [PACKLD_FLAGS=' -m elf64ppc'],
     [power,gcc*,elf,ppc64le], [PACKLD_FLAGS=' -m elf64lppc'],
@@ -1253,6 +1261,9 @@ AS_CASE([$host],
   [*-*-haiku],
     [cclibs="$cclibs -lnetwork"
     sockets=true],
+  [*-*-solaris*],
+    [cclibs="$cclibs -lsocket -lnsl"
+    sockets=true],
   [
     AC_CHECK_FUNC([socket])
     AC_CHECK_FUNC([socketpair])
@@ -1624,7 +1635,6 @@ AS_IF([test x"$enable_systhreads" = "xno"],
       [systhread_support=true
       otherlibraries="$otherlibraries systhreads"
       AS_CASE([$host],
-        [*-*-solaris*], [pthread_link="-lpthread -lposix4"],
         [*-*-haiku*], [pthread_link=""],
         [*-*-android*], [pthread_link=""],
         [pthread_link="-lpthread"])
diff --git a/otherlibs/systhreads/Makefile b/otherlibs/systhreads/Makefile
index 5ac70d777..be42d0b81 100644
--- a/otherlibs/systhreads/Makefile
+++ b/otherlibs/systhreads/Makefile
@@ -22,7 +22,7 @@ ifneq "$(CCOMPTYPE)" "msvc"
 OC_CFLAGS += -g
 endif
 
-OC_CFLAGS += $(SHAREDLIB_CFLAGS)
+OC_CFLAGS += $(SHAREDLIB_CFLAGS) $(PTHREAD_CFLAGS)
 
 OC_CPPFLAGS += -I$(ROOTDIR)/runtime
 
diff --git a/otherlibs/systhreads/st_posix.h b/otherlibs/systhreads/st_posix.h
index b4ed6860c..e4b862a37 100644
--- a/otherlibs/systhreads/st_posix.h
+++ b/otherlibs/systhreads/st_posix.h
@@ -21,9 +21,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <pthread.h>
-#ifdef __sun
-#define _POSIX_PTHREAD_SEMANTICS
-#endif
 #include <signal.h>
 #include <time.h>
 #include <sys/time.h>
diff --git a/otherlibs/systhreads/st_stubs.c b/otherlibs/systhreads/st_stubs.c
index 9af8c45fe..64a559003 100644
--- a/otherlibs/systhreads/st_stubs.c
+++ b/otherlibs/systhreads/st_stubs.c
@@ -13,6 +13,10 @@
 /*                                                                        */
 /**************************************************************************/
 
+#if defined(__sun) && !defined(_POSIX_PTHREAD_SEMANTICS)
+#define _POSIX_PTHREAD_SEMANTICS
+#endif
+
 #define CAML_INTERNALS
 
 #include "caml/alloc.h"
diff --git a/otherlibs/unix/execvp.c b/otherlibs/unix/execvp.c
index ce3e99ec9..8063567b3 100644
--- a/otherlibs/unix/execvp.c
+++ b/otherlibs/unix/execvp.c
@@ -14,7 +14,11 @@
 /**************************************************************************/
 
 #define _GNU_SOURCE  /* helps to find execvpe() */
+#ifdef __sun
+#include <strings.h>
+#else
 #include <string.h>
+#endif
 #include <caml/mlvalues.h>
 #include <caml/memory.h>
 #define CAML_INTERNALS

The issue with _POSIX_PTHREAD_SEMANTICS is that even though it is defined in otherlibs/systhreads/st_posix.h, it is too late because otherlibs/systhreads/st_stubs.c includes caml/signals.h before st_posix.h.
There are two solutions to this. First, rely on autoconf setting PTHREAD_CFLAGS and PTHREAD_LIBS. Alternatively, add the definition in st_stubs.c. In the patch above, both of these solutions are present.

@tleedjarv
Copy link
Contributor

Separately, can enable stack overflow detection.

diff --git a/configure.ac b/configure.ac
index df2a8cd7d..d7f94647d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1616,7 +1616,7 @@ AC_MSG_CHECKING([whether stack overflows can be detected])
 
 AS_CASE([$arch,$system],
   [i386,linux_elf|amd64,linux|amd64,macosx \
-    |amd64,openbsd|i386,bsd_elf],
+    |amd64,solaris|amd64,openbsd|i386,bsd_elf],
     [AC_DEFINE([HAS_STACK_OVERFLOW_DETECTION])
     AC_MSG_RESULT([yes])],
   [AC_MSG_RESULT([no])])

@mikeowens
Copy link
Author

mikeowens commented Nov 29, 2020

@tleedjarv No I'm not maintaining this.

@ksromanov
Copy link
Contributor

This PR can be safely closed - the support for OmniOS was restored in #10063

@gasche gasche closed this Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants