docker-base-images icon indicating copy to clipboard operation
docker-base-images copied to clipboard

Base images for Fedora 40 which use GCC 14 and OCaml < 4.08 fail

Open mtelvers opened this issue 2 months ago • 1 comments

Taking a Fedora 40 image such as this one: https://images.ci.ocaml.org/job/2024-05-02/131216-ocluster-build-e4bdb0

docker run --rm -it ocurrent/opam-staging@sha256:2183cb377106178781bf86fe05b2b0d5e937bffac769db81765dc03ffbfc30b4

Then, attempting to install OCaml 4.07.1 like this:

cat /etc/fedora-release
curl -LO https://github.com/ocaml/ocaml/archive/4.07.1.tar.gz
rm -rf ocaml-4.07.1
tar -xzf 4.07.1.tar.gz && cd ocaml-4.07.1
curl -L https://github.com/ocaml/ocaml/commit/00b8c4d503732343d5d01761ad09650fe50ff3a0.patch?full_index=1 | patch -p1
./configure -prefix /usr -with-debug-runtime
make world

This fails with

make[1]: Entering directory '/home/opam/ocaml-4.07.1/stdlib'
../boot/ocamlrun ../boot/ocamlc -use-prims ../byterun/primitives -strict-sequence -absname -w +a-4-9-41-42-44-45-48 -g -warn-error A -bin-annot -nostdlib -safe-string -strict-formats  -nopervasives -c camlinternalFormatBasics.mli
Fatal error: exception Invalid_argument("Sys.getcwd not implemented")
make[1]: *** [Makefile:237: camlinternalFormatBasics.cmi] Error 2
make[1]: Leaving directory '/home/opam/ocaml-4.07.1/stdlib'
make: *** [Makefile:393: coldstart] Error 2

In byterun/sys.c we see

CAMLprim value caml_sys_getcwd(value unit)
{
  char_os buff[4096];
  char_os * ret;
#ifdef HAS_GETCWD
  ret = getcwd_os(buff, sizeof(buff)/sizeof(*buff));
#else
  caml_invalid_argument("Sys.getcwd not implemented");
#endif /* HAS_GETCWD */
  if (ret == 0) caml_sys_error(NO_ARG);
  return caml_copy_string_of_os(buff);
}

This is defined in configure:

if sh ./hasgot getcwd; then
  inf "getcwd() found."
  echo "#define HAS_GETCWD" >> s.h
fi

hasgot creates a tiny .c file like this

int main() { getcwd(); }

which when compiled fails:

$ gcc -o tst hasgot.c 
hasgot.c: In function ‘main’:
hasgot.c:1:14: error: implicit declaration of function ‘getcwd’ [-Wimplicit-function-declaration]
    1 | int main() { getcwd(); }
      |              ^~~~~~

This is a change in GCC 14, https://gcc.gnu.org/gcc-14/porting_to.html, which ships with Fedora 40.

$ gcc --version
gcc (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The original behaviour can be restored like this

cflags="-Wno-implicit-function-declaration" ./configure
make world

mtelvers avatar May 07 '24 13:05 mtelvers