ciao-lang / ciao

Ciao is a modern Prolog implementation that builds up from a logic-based simple kernel designed to be portable, extensible, and modular.
https://ciao-lang.org
GNU Lesser General Public License v3.0
272 stars 21 forks source link

Support ppc64le CPU architecture #41

Closed AlbertoGP closed 2 years ago

AlbertoGP commented 2 years ago

Hi, I’m trying to compile on an unsupported CPU architecture and for that the first step is to do some trivial changes in eng_predef.h.

However, ./ciao-boot.sh configure fails precisely because it would need those changes to run.

It says compiling ciaoengine (engine for ciaoc.sta) so I imagine that ciaoc.sta is a pre-compiled file. I’ve tried removing the file core/bootstrap/ciaoc.car/ciaoc.sta hoping it would be rebuilt from the C source, but it surprisingly still says compiling ciaoengine (engine for ciaoc.sta), so I guess it got built into yet another file which is the one actually loaded.

My question is: can I somehow bootstrap from C?

jfmc commented 2 years ago

Hi Alberto. The bootstrap process is delicate. Currently it is based on a few POSIX-compatible shell scripts that guesses some of the parameters from the current OS and architecture, compiles a bootstrap engine (from a few automatically generated and C files) and boots Ciao (indeed a Ciao compiler, ciaoc.sta). This initial system compiles itself to generate a new compiler and a new collection of automatically generated C files.

If you give us some information about the new unsupported CPU architecture we'd gladly help or guide you to make it work.

AlbertoGP commented 2 years ago

The CPU is an IBM Power9 in little-endian mode, which in Linux is identified as ppc64le. eng_predef.h defaults to 32 bits when encountering an unsupported arch, and then tagged_t has a different size from tagged_t*.

Ideally, I would like to learn the bootstrapping process so that I can do that again in the future if I need to, and add it to the documentation.

Edit: I’m reading now builder/README.md, seems to describe the bootstrapping process. Edit 2: The bootstrapping process is described in the documentation at https://ciao-lang.org/ciao/build/doc/ciao_builder.html/ciao_builder.html#Bootstrapping%20the%20build%20system

jfmc commented 2 years ago

The place to start would be the files at: https://github.com/ciao-lang/ciao/tree/master/builder/sh_src/config-sysdep

Then I'd do a recursive grep over all the code, locate ppc64 and change it to accept ppc64le too. Please tell me if you need any help.

jfmc commented 2 years ago

BTW, if you agree I'd rename this issue to "support ppc64le architecture".

AlbertoGP commented 2 years ago

BTW, if you agree I'd rename this issue to "support ppc64le architecture".

Sure, no problem, although I intend to document here the bootstrapping process once I get a reproducible sequence of steps.

As for replacing ppc64 with ppc64le, I’ll try first to have both there.

jfmc commented 2 years ago

My mistake: I intended to say add ppc64le in addition to ppc64 rather than replacing one with the other.

AlbertoGP commented 2 years ago

add ppc64le in addition to ppc64

I should have read more carefully, was jumping around reading docs and source code.

Did a couple of changes and it seems to be running.

Some test fail, but I tried on a clean checkout on a Linux x64 machine and they fail in the same way. I’ll file a separate issue for that. Edit: done at #42

AlbertoGP commented 2 years ago

Well, it turns out that there wasn’t much to figure out about the bootstrapping process, it’s just that you need to delete the build/ and build-boot directories if you change the C sources for those changes to be picked up. It was enough to add ppc64le next to ppc64 in a few places as you suggested, and fix a small mistake in the implementation of hrtime() for PowerPC.

The pull request is at: #45

Thanks!