12.4 Non-Relocatable Image Files

Non-relocatable images have many disadvantages and there is no good reason to use them. They are documented here mainly for completeness and historical interest (originally Gforth did not support relocatable images).

Non-relocatable image files are simple memory dumps of the dictionary. They are specific to the executable (i.e., gforth file) they were created with. What’s worse, they are specific to the place on which the dictionary resided when the image was created. Now, there is no guarantee that the dictionary will reside at the same place the next time you start Gforth, so there’s no guarantee that a non-relocatable image will work the next time (Gforth will complain instead of crashing, though).

Indeed, on OSs with (enabled) address-space layout randomization (ASLR) non-relocatable images are unlikely to work. In Linux you can run a binary without ASLR by prefixing the invocation with setarch -R. You need to do this both when creating the image and when using it. This Linux-specific usage is shown below, and you may have to leave it away or replace it with something else on other OSs (if the OS supports disabling ASLR at all).

In addition, the image contains code addresses of the native code for the primitives; with dynamic native-code generation these code addresses point to code that is not saved in the image and is not regenerated from the image, either, so you need to disable dynamic native code generation with --no-dynamic on image creation if you want to use non-relocatable images. The image can then be loaded into an engine with enabled dynamic native code generation, and the result will be that the code in the image will not use dynamic native code, but code compiled after loading the image will (unless something else disables dynamic native-code generation).

Moreover, the code addresses in a non-relocatable image are engine-specific, so you need to use the image with the same engine (gforth, gforth-fast, gforth-itc) that generated it.

You can create a non-relocatable image file with savesystem, e.g., on Linux:

#create non-relocatable image app.fi:
setarch -R gforth --no-dynamic app.fs -e "savesystem app.fi bye"
#start Gforth with image app.fi:
setarch -R gforth -i app.fi
savesystem ( "image" –  ) gforth-0.2