New --emulator functionatily

In trying to use the new --emulator functionality to produce a saved state to run in multiple architectures I get the following error:

ERROR: /tmp/swipl-devel/build.release/home/xpce/prolog/boot/pce_principal.pl:215: Initialization goal raised exception:
ERROR: pl2xpce: cannot open shared object file: No such file or directory
ERROR: In:
ERROR:   [19] throw(error(shared_object(open,'pl2xpce: cannot open shared object file: No such file or directory'),context(...,_4360)))
ERROR:   [17] <meta call>
ERROR:   [16] with_mutex('$foreign',load_foreign_library(foreign(pl2xpce),pce_principal,default(install))) <foreign>
ERROR:   [12] '$run_init_goal'('$syspreds':use_foreign_library_noi(...)) at /usr/lib/swipl/boot/init.pl:808
ERROR:   [11] catch(system:'$run_init_goal'(...),_4498,system:'$initialization_error'(_4520,...,...)) at /usr/lib/swipl/boot/init.pl:561
ERROR:   [10] catch_with_backtrace(system:'$run_init_goal'(...),_4556,system:'$initialization_error'(_4578,...,...)) at /usr/lib/swipl/boot/init.pl:628
ERROR: 
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
ERROR: Initialization goal '$syspreds':use_foreign_library_noi(pce_principal:foreign(pl2xpce)) raised exception:
ERROR: pl2xpce: cannot open shared object file: No such file or directory
ERROR: In:
ERROR:   [28] throw(error(shared_object(open,'pl2xpce: cannot open shared object file: No such file or directory'),context(...,_12986)))
ERROR:   [26] <meta call>
ERROR:   [25] with_mutex('$foreign',load_foreign_library(foreign(pl2xpce),pce_principal,default(install))) <foreign>
ERROR:   [21] '$run_init_goal'('$syspreds':use_foreign_library_noi(...)) at /usr/lib/swipl/boot/init.pl:808
ERROR:   [20] catch(system:'$run_init_goal'(...),_13124,system:'$initialization_error'(_13146,...,-)) at /usr/lib/swipl/boot/init.pl:561
ERROR:   [19] catch_with_backtrace(system:'$run_init_goal'(...),_13182,system:'$initialization_error'(_13204,...,-)) at /usr/lib/swipl/boot/init.pl:628
ERROR: 
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
ERROR: Failed to initialise the XPCE toolkit.  This is normally
ERROR: caused by a missing or incompatible X11 library.
ERROR: See http://www.swi-prolog.org/build/issues/xpce.html
ERROR: Sorry, cannot recover from this.  Process terminates.

I built the saved state using:

swipl -o xx  --emulator=/usr/bin/swipl -c  xx.pl

It produces a file that works in the original system where it was compiled.

When I run the file on another system, which uses an swi-prolog compilation that has no X11 support I get the error above because the xpce shared library is not present. However, the application does not use xpce at all, so it seems to me that boot/pce_principal.pl should not have been included in the saved state because the application does not use X11 at all.

It is a bit too optimistic to call these states architecture independent. They only are that if the emulator is configured in the same way and the OS is the same, such that availability of resources and settings for Prolog flags that may affect conditional compilation (e.g. current_prolog_flag(windows, true)) are equal.

This was introduced for Debian to allow shipping packages that contain a SWI-Prolog saved state as noarch packages as SWI-Prolog is the same on Debian regardless of the architecture.

As for xpce, this is often included indirectly though “something” :frowning: the solution (work around) is to add --no-pce. For example, for s(CASP) I use

swipl --no-pce --undefined=error -O -o scasp -c prolog/scasp/main.pl

Adding too much to saved states is still something that should be improved. Ideally we would do a code reachability analysis from the main goal. As you know, this is hard with Prolog :frowning:

2 Likes

This trick worked, moving the saved state from x86 to arm. Worked even for different linux variants! Thanks!

Normally states should be quite portable between POSIX based systems provided the emulator has all features required by the application. CPU, word size (32/64 bits) nor big/little endian should matter. But, there are edge cases, making it difficult to promise anything :frowning: