Browse Source

fixed caseTableSize for 64-bit binaries

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6618 8c9fc860-2736-0410-a75d-ab315db34111
eth.guenter 9 years ago
parent
commit
b0b36168ed
1 changed files with 7 additions and 2 deletions
  1. 7 2
      source/FoxBinaryObjectFile.Mod

+ 7 - 2
source/FoxBinaryObjectFile.Mod

@@ -398,6 +398,7 @@ TYPE
 	PROCEDURE MakeSectionOffsets(module: Sections.Module; VAR constSize, varSize, codeSize, caseTableSize: LONGINT; VAR const, code: ByteArray);
 	PROCEDURE MakeSectionOffsets(module: Sections.Module; VAR constSize, varSize, codeSize, caseTableSize: LONGINT; VAR const, code: ByteArray);
 	VAR symbolName: SyntaxTree.IdentifierString; symbol: SyntaxTree.Symbol; binarySection: BinaryCode.Section;
 	VAR symbolName: SyntaxTree.IdentifierString; symbol: SyntaxTree.Symbol; binarySection: BinaryCode.Section;
 		pc: LONGINT;
 		pc: LONGINT;
+		addrSize: LONGINT; (* size of ADDRESS in bytes *)
 
 
 		(*
 		(*
 		PROCEDURE InModule(s: Sections.Section):BOOLEAN;
 		PROCEDURE InModule(s: Sections.Section):BOOLEAN;
@@ -536,11 +537,12 @@ TYPE
 
 
 
 
 	BEGIN
 	BEGIN
+		addrSize := module.system.addressSize DIV 8;
 		FirstOffsets(module.allSections); (* regular sections *)
 		FirstOffsets(module.allSections); (* regular sections *)
 		SetOffsets(module.allSections,FALSE); (* regular sections *)
 		SetOffsets(module.allSections,FALSE); (* regular sections *)
 		pc := constSize;
 		pc := constSize;
 		SetOffsets(module.allSections, TRUE); (* case table sections *)
 		SetOffsets(module.allSections, TRUE); (* case table sections *)
-		caseTableSize := (constSize -pc) DIV 4 ;
+		caseTableSize := (constSize -pc) DIV addrSize;
 		FixupSections;
 		FixupSections;
 
 
 		NEW(const,constSize ); NEW(code,codeSize );
 		NEW(const,constSize ); NEW(code,codeSize );
@@ -555,6 +557,7 @@ TYPE
 		moduleScope: SyntaxTree.ModuleScope; fingerprinter: FingerPrinter.FingerPrinter;
 		moduleScope: SyntaxTree.ModuleScope; fingerprinter: FingerPrinter.FingerPrinter;
 		const, code: ByteArray; procedureFixupOffset : LONGINT;
 		const, code: ByteArray; procedureFixupOffset : LONGINT;
 		crc: LONGINT; crc32: Basic.CRC32Stream;
 		crc: LONGINT; crc32: Basic.CRC32Stream;
+		addrSize: LONGINT; (* size of ADDRESS in bytes *)
 
 
 		symbols, importedSymbols: SectionList; (* list of sections with fixups in the other direction, needed for this particular object file format *)
 		symbols, importedSymbols: SectionList; (* list of sections with fixups in the other direction, needed for this particular object file format *)
 
 
@@ -1073,7 +1076,8 @@ TYPE
 				INC(numberLinks);
 				INC(numberLinks);
 			END;
 			END;
 			IF caseTableSize > 0 THEN
 			IF caseTableSize > 0 THEN
-				w.Char(0X); w.Char(SysCallMap[CaseTable]); w.RawNum((constSize -caseTableSize *4));
+				w.Char(0X); w.Char(SysCallMap[CaseTable]); 
+				w.RawNum( constSize - (caseTableSize*addrSize) );
 				INC(numberLinks);
 				INC(numberLinks);
 				(* case table is fixuped by the loader using offset of case table in constant section
 				(* case table is fixuped by the loader using offset of case table in constant section
 					it is impossible to have disjoint case tables here
 					it is impossible to have disjoint case tables here
@@ -2229,6 +2233,7 @@ TYPE
 			References
 			References
 		*)
 		*)
 	BEGIN
 	BEGIN
+		addrSize := module.system.addressSize DIV 8;
 		MakeSectionOffsets(module,constSize,dataSize,codeSize,caseTableSize,const,code);
 		MakeSectionOffsets(module,constSize,dataSize,codeSize,caseTableSize,const,code);
 		MakeSections;
 		MakeSections;
 		(* from here on we do not need IntermediateCode.Sections any more *)
 		(* from here on we do not need IntermediateCode.Sections any more *)