[Oberon] Static variable overflow (bug?)

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Mon Feb 24 13:23:24 CET 2020

  > CONST 
  >    max = 16377;  (* If max >= 16367 the frame name disappears; If max >= 16377 the whole menu line disappears! *)
  >    menu = "System.Close System.Copy System.Grow”; 
  > VAR bitmap: ARRAY max OF SET;  (* with this variable present the menu may remain empty! *)

The issue is that Project Oberon 2013 does not know how to handle data accesses at offsets > 64KB from the module’s static base. A module block in memory consists of 3 sections (see ch. 6, p. 79 of the book Project Oberon 2013)
  - data  (which in turn contains type descriptors, the variable space and strings - in that order!)
  - code
  - meta

If you declare a global bitmap variable which takes up more than 64KB, the module loader will actually allocate the appropriate amount of variable space (even if it is >64KB) and even place your string “menu” just after that (strings are treated like pre-initialized, immutable global variables).

But one cannot access the string, as it is beyond the 64KB boundary. This is an undocumented limitation of PO 2013 and the Oberon-07 compiler (regrettably) does not warn you about it, when compiling a program.

This limitation has to do with the way global variables are accessed. It typically involves loading the static base of the module via a LD instruction + adding an offset via an ADD instruction. However, an ADD instruction which has an offset field of only 16 bits = 64KB, this is where the limitation comes from. There are ways around this, but it’s just not implemented in Project Oberon 2013.

=> If you remove the bitmap variable declaration or make it so small that the sum of the bitmap + your string is <64KB, your program should work.

To use a bitmap of more than 64KB you can allocate in the heap, as in

      CONST max = 16384;
      TYPE BitMap = POINTER TO BitMapDesc;
        BitMapDesc = RECORD bits: ARRAY max OF SET END ;

      VAR bitmap: BitMap;

      PROCEDURE AllocateBitmap*;
      BEGIN NEW(bitmap)
      END AllocateBitmap;
    END M.

    ORP.Compile M.Mod/s ~

But remember, even the heap space in Project Oberon 2013 is limited to a few hundred KB only.

More information about the Oberon mailing list