by adimetrius » Wed Dec 02, 2020 10:53 am
Good question.
First, the OCF format is great - I like it much better than the ELF, had to study both in the last 5 weeks.
Second, While we can preserve the overall OCF file structure, some things in it will still have to change. The reason is that OCF holds the image for the metadata, and that hold pointers, and they grow from 4 to 8 bytes.
So my idea was that the processor code (a new one for amd64) could indicate that OCF holds 64-bit data. The new code would stop old tools from looking into the file and misinterpreting it.
Then, I've added two numbers to the header block: the importsCount and the externalsCount. Together these two values indicate the size of the proxy table used to link modules to each other and to external libraries. These numbers could be derived from analyzing the UseBlk at the end of OCF, however, having them in the header costs nothing in the compiler and saves the loader/binder from doing the analysis work. It allows the latter to allocate internal structures of sufficient size BEFORE processing the UseBlk, so I thought it's a nice optimization.
Now, to the UseBlk. Currently, Herschel generates PIC - it needs no relocations when it's base is changed (when it's loaded at varying base addresses). It also does not need any binding fixups (to bind/link to imported symbols). Addresses of imported CP procedures and external host library functions are collected in one place - the proxy table. References to the proxy table are hard-coded into the generated code. At load time, the proxy table is allocated at the end of the Meta segment, and should be filled out with appropriate addresses of imported symbols (by the BB or host os loader).
All this to say, the UseBlk's link list holds only one value.
This is how a UseBlk procedure entry was defined in OCF:
UProc = 4X name fprint link.
link = {fixupadr offset} 0X.
Now, in OCF/64, the fixupaddr is the address in the proxy table, and the offset is zero. (Also, fingerprinting is no yet implemented, so the fingerprints are written out as zeroes).
Does this answer your question?