Closed X547 closed 3 years ago
Global variables can be allocated in same segment with read-write data by specifying memory size larger then file size. Part that is not covered with file data will be filled with zeroes. PE executables also supports this feature.
Global variables seems to be allocated in segment 2 (memory size 0D0H - file size 90H = 64 that match size of global variables). But offsets in code points at wrong place.
Great finding!
The proposed fix is to HrE:
PROCEDURE ApplyToBkmrks (IN b: Y.Bkmrks; **base**: INTEGER);
VAR i: INTEGER;
BEGIN i := 0; WHILE b[i].offset # 0 DO FixupCode(b[i].last, **base + b[i].offset**); INC(i) END
END ApplyToBkmrks;
PROCEDURE ApplyGlobVarFixups (o: Y.GlobVar; **base**: INTEGER);
VAR more: Y.BkmrksPtr;
BEGIN
FixupCode(o.last, **base**);
ApplyToBkmrks(o.bkmrks, **base**); more := o.moreBkmrks;
WHILE more # NIL DO ApplyToBkmrks(more.bkmrks, **base**); more := more.more END
END ApplyGlobVarFixups;
PROCEDURE ApplyRIPFixupsToList (o: T.Symbol);
VAR next: T.Symbol; base: INTEGER;
BEGIN
WHILE o # NIL DO
WITH o: T.Object DO
IF T.used IN o.flags THEN
WITH
| o: Y.GlobVar DO
IF o.imno = 0 THEN **base := varsWRTcode** (* domestic var *)
ELSE **base := proxiesWRTcode** (* imported var *)
END;
ApplyGlobVarFixups(o, **base**)
See if it works, please
It didn't bolden the base, bummer
Fixed In HrBinder.
This is https://github.com/adimetrius/Herschel/commit/cc4bead0534a6824bca446a8d906e7952b0d8ffd.
In Albert example there are
VAR s: ARRAY 64 OF SHORTCHAR;
global variable and codes := "but not simpler";
that assigns value to it. But offset to global variable in code is wrong and it is outside of any ELF segments.ElfDecoder: