PB executable file format

A couple months ago I had a terrible experience with GNU LD. I was trying to produce a certain executable layout for a program in my OS using a linker script. But the linker refused to obey the script. It went rogue. On this day I declared war on linkers. They are my enemy now and although linking, consolidātio, is a necessary process, linkers are a source of problems and must rejected.

In this vein I have created a new executable format for my operating system. It serves as a firewall against interaction with existing bloated toolchains. The name ‘PB’ is short for prōgramma bināre, whose meaning should be obvious.

The format itself is rather simple. It consists of a single continous “Read Only and Execute” section starting at the second 4096 byte page in the file which continous for an integer number of pages. At startup this data is copied into memory and mapped to some page aligned address, probably 0x1000. An integer number of zeroed pages are mapped in directly above the ROX pages. These are refered to as the preallocated or PA pages and are used for the main thread stack, globals et cetera. Execution of the program starts at lowest address of the mapped ROX pages. There is no _start symbol, we start at the actual start. Register values at execution start are undefined.

The first page in the executable file is used to store the header. The application is allowed to store arbitrary data in the file pages following the ROX section for loading and use at runtime.

Example file layout:

PB0: PB Header
PB1: ROX Page 0
PB1: ROX Page 1
PB2: ROX Page 2
PB3: ROX Page 3
PB4: ROX Page 4
PB5: Arbitrary data
PB6: Arbitrary data

Resulting memory layout:

0x1000: ROX Page 0
0x2000: ROX Page 1
0x3000: ROX Page 2
0x4000: ROX Page 3
0x5000: ROX Page 4
0x6000: PA Page 0
0x7000: PA Page 1
0x8000: PA Page 2

Execution starts at 0x1000

The header consists of a string to identify the file and two 64 bit little endian numbers. Number of ROX pages and number of PA pages.

0x11: 7 zero bytes
0x24: no_rox
0x32: no_pa

There will be a seperate object/lib format for precompiled libraries for use with the brevis language. But that is entirely seperate from the PB executable format. Because linking has nothing to do with loading and running a program.