@@ -569,7 +569,6 @@ def _handle_relocation(
569569 assert what & 0x9F000000 == 0x90000000 , what
570570 addend = ((what & 0x60000000 ) >> 29 ) | ((what & 0x01FFFFE0 ) >> 3 ) << 12
571571 addend = sign_extend_64 (addend , 33 )
572- # assert symbol.startswith(self.SYMBOL_PREFIX), symbol
573572 symbol = symbol .removeprefix (self .SYMBOL_PREFIX )
574573 if (symbol , addend ) not in self .got_entries :
575574 self .got_entries .append ((symbol , addend ))
@@ -595,7 +594,6 @@ def _handle_relocation(
595594 if what & 0x04800000 == 0x04800000 :
596595 implicit_shift = 4
597596 addend <<= implicit_shift
598- # assert symbol.startswith(self.SYMBOL_PREFIX), symbol
599597 symbol = symbol .removeprefix (self .SYMBOL_PREFIX )
600598 if (symbol , addend ) not in self .got_entries :
601599 self .got_entries .append ((symbol , addend ))
@@ -615,7 +613,6 @@ def _handle_relocation(
615613 assert what & 0x9F000000 == 0x90000000 , what
616614 addend = ((what & 0x60000000 ) >> 29 ) | ((what & 0x01FFFFE0 ) >> 3 ) << 12
617615 addend = sign_extend_64 (addend , 33 )
618- # assert symbol.startswith(self.SYMBOL_PREFIX), symbol
619616 symbol = symbol .removeprefix (self .SYMBOL_PREFIX )
620617 return Hole (HoleKind .REL_21 , symbol , offset , addend )
621618 case {
@@ -640,22 +637,8 @@ def _handle_relocation(
640637 if what & 0x04800000 == 0x04800000 :
641638 implicit_shift = 4
642639 addend <<= implicit_shift
643- # assert symbol.startswith(self.SYMBOL_PREFIX), symbol
644640 symbol = symbol .removeprefix (self .SYMBOL_PREFIX )
645641 return Hole (HoleKind .ABS_12 , symbol , offset , addend )
646- case {
647- "Length" : 3 as length ,
648- "Offset" : int (offset ),
649- "PCRel" : 0 as pcrel ,
650- "Section" : {"Value" : str (section )},
651- "Type" : {"Value" : "ARM64_RELOC_UNSIGNED" },
652- }:
653- offset += base
654- where = slice (offset , offset + (1 << length ))
655- what = int .from_bytes (self .body [where ], "little" , signed = False )
656- addend = what
657- section = remove_prefix (section , self .SYMBOL_PREFIX )
658- return Hole (HoleKind .ABS_64 , section , offset , addend )
659642 case {
660643 "Length" : 3 as length ,
661644 "Offset" : int (offset ),
@@ -814,7 +797,7 @@ def _handle_relocation(
814797 offset += base
815798 where = slice (offset , offset + 8 )
816799 what = int .from_bytes (self .body [where ], sys .byteorder )
817- assert not what , what
800+ symbol = symbol . removeprefix ( self . SYMBOL_PREFIX )
818801 return Hole (HoleKind .ABS_64 , symbol , offset , addend )
819802 case {
820803 "Addend" : 0 ,
@@ -832,12 +815,49 @@ def _handle_relocation(
832815 if (symbol , addend ) not in self .got_entries :
833816 self .got_entries .append ((symbol , addend ))
834817 addend = len (self .body ) + self .got_entries .index ((symbol , addend )) * 8
818+ symbol = symbol .removeprefix (self .SYMBOL_PREFIX )
835819 return Hole (HoleKind .REL_21 , "_JIT_BASE" , offset , addend )
820+ case {
821+ "Addend" : int (addend ),
822+ "Offset" : int (offset ),
823+ "Symbol" : {'Value' : str (symbol )},
824+ "Type" : {"Value" : "R_AARCH64_ADD_ABS_LO12_NC" },
825+ }:
826+ offset += base
827+ where = slice (offset , offset + 4 )
828+ what = int .from_bytes (self .body [where ], "little" , signed = False )
829+ # XXX: This nonsense...
830+ assert what & 0x3B000000 == 0x39000000 or what & 0x11C00000 == 0x11000000 , what
831+ addend += (what & 0x003FFC00 ) >> 10
832+ implicit_shift = 0
833+ if what & 0x3B000000 == 0x39000000 :
834+ implicit_shift = (what >> 30 ) & 0x3
835+ if implicit_shift == 0 :
836+ if what & 0x04800000 == 0x04800000 :
837+ implicit_shift = 4
838+ addend <<= implicit_shift
839+ symbol = symbol .removeprefix (self .SYMBOL_PREFIX )
840+ return Hole (HoleKind .ABS_12 , symbol , offset , addend )
841+ case {
842+ "Addend" : int (addend ),
843+ "Offset" : int (offset ),
844+ "Symbol" : {'Value' : str (symbol )},
845+ "Type" : {"Value" : "R_AARCH64_ADR_PREL_PG_HI21" },
846+ }:
847+ offset += base
848+ where = slice (offset , offset + 4 )
849+ what = int .from_bytes (self .body [where ], "little" , signed = False )
850+ # XXX: This nonsense...
851+ assert what & 0x9F000000 == 0x90000000 , what
852+ addend += ((what & 0x60000000 ) >> 29 ) | ((what & 0x01FFFFE0 ) >> 3 ) << 12
853+ addend = sign_extend_64 (addend , 33 )
854+ symbol = symbol .removeprefix (self .SYMBOL_PREFIX )
855+ return Hole (HoleKind .REL_21 , symbol , offset , addend )
836856 case {
837857 "Addend" : 0 ,
838858 "Offset" : int (offset ),
839859 "Symbol" : {"Value" : str (symbol )},
840- "Type" : {"Value" : "R_AARCH64_CALL26" | "R_AARCH64_JUMP26" }, # XXX
860+ "Type" : {"Value" : "R_AARCH64_CALL26" | "R_AARCH64_JUMP26" },
841861 }:
842862 offset += base
843863 where = slice (offset , offset + 4 )
@@ -848,6 +868,7 @@ def _handle_relocation(
848868 ), what
849869 addend = (what & 0x03FFFFFF ) << 2
850870 addend = sign_extend_64 (addend , 28 )
871+ symbol = symbol .removeprefix (self .SYMBOL_PREFIX )
851872 return Hole (HoleKind .REL_26 , symbol , offset , addend )
852873 case {
853874 "Addend" : 0 ,
@@ -871,51 +892,8 @@ def _handle_relocation(
871892 if (symbol , addend ) not in self .got_entries :
872893 self .got_entries .append ((symbol , addend ))
873894 addend = len (self .body ) + self .got_entries .index ((symbol , addend )) * 8
895+ symbol = symbol .removeprefix (self .SYMBOL_PREFIX )
874896 return Hole (HoleKind .ABS_12 , "_JIT_BASE" , offset , addend )
875- case {
876- "Addend" : int (addend ),
877- "Offset" : int (offset ),
878- "Symbol" : {"Value" : str (symbol )},
879- "Type" : {"Value" : "R_AARCH64_MOVW_UABS_G0_NC" },
880- }:
881- offset += base
882- where = slice (offset , offset + 4 )
883- what = int .from_bytes (self .body [where ], "little" , signed = False )
884- assert ((what >> 5 ) & 0xFFFF ) == 0 , what
885- return Hole (HoleKind .ABS_16_A , symbol , offset , addend )
886- case {
887- "Addend" : int (addend ),
888- "Offset" : int (offset ),
889- "Symbol" : {"Value" : str (symbol )},
890- "Type" : {"Value" : "R_AARCH64_MOVW_UABS_G1_NC" },
891- }:
892- offset += base
893- where = slice (offset , offset + 4 )
894- what = int .from_bytes (self .body [where ], "little" , signed = False )
895- assert ((what >> 5 ) & 0xFFFF ) == 0 , what
896- return Hole (HoleKind .ABS_16_B , symbol , offset , addend )
897- case {
898- "Addend" : int (addend ),
899- "Offset" : int (offset ),
900- "Symbol" : {"Value" : str (symbol )},
901- "Type" : {"Value" : "R_AARCH64_MOVW_UABS_G2_NC" },
902- }:
903- offset += base
904- where = slice (offset , offset + 4 )
905- what = int .from_bytes (self .body [where ], "little" , signed = False )
906- assert ((what >> 5 ) & 0xFFFF ) == 0 , what
907- return Hole (HoleKind .ABS_16_C , symbol , offset , addend )
908- case {
909- "Addend" : int (addend ),
910- "Offset" : int (offset ),
911- "Symbol" : {"Value" : str (symbol )},
912- "Type" : {"Value" : "R_AARCH64_MOVW_UABS_G3" },
913- }:
914- offset += base
915- where = slice (offset , offset + 4 )
916- what = int .from_bytes (self .body [where ], "little" , signed = False )
917- assert ((what >> 5 ) & 0xFFFF ) == 0 , what
918- return Hole (HoleKind .ABS_16_D , symbol , offset , addend )
919897 case _:
920898 raise NotImplementedError (relocation )
921899
@@ -1228,7 +1206,7 @@ def dump(self) -> str:
12281206def main (host : str ) -> None :
12291207 for engine , ghccc , cflags in [
12301208 (aarch64_apple_darwin , False , [f"-I{ ROOT } " ]),
1231- (aarch64_unknown_linux_gnu , False , [f"-I{ ROOT } " , "-fno-pic" , "-mcmodel=large" ]),
1209+ (aarch64_unknown_linux_gnu , False , [f"-I{ ROOT } " ]),
12321210 (i686_pc_windows_msvc , True , [f"-I{ PC } " , "-fno-pic" , "-mcmodel=large" ]),
12331211 (x86_64_apple_darwin , True , [f"-I{ ROOT } " ]),
12341212 (x86_64_pc_windows_msvc , True , [f"-I{ PC } " , "-fno-pic" , "-mcmodel=large" ]),
0 commit comments