Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file abi_mips64_relocation.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241(*Generated by Lem from abis/mips64/abi_mips64_relocation.lem.*)(** [abi_mips64_relocation] contains types and definitions relating to ABI
* specific relocation functionality for the MIPS64 ABI.
*)openLem_basic_classesopenLem_mapopenLem_maybeopenLem_numopenShowopenLem_stringopenLem_assert_extraopenErroropenMissing_pervasivesopenElf_fileopenElf_headeropenElf_relocationopenElf_symbol_tableopenElf_types_native_uintopenMemory_imageopenAbi_classesopenAbi_utilities(* Relocation types *)letr_mips_none:Nat_big_num.num=((Nat_big_num.of_int0))(** No reloc *)letr_mips_16:Nat_big_num.num=((Nat_big_num.of_int1))(** Direct 16 bit *)letr_mips_32:Nat_big_num.num=((Nat_big_num.of_int2))(** Direct 32 bit *)letr_mips_rel32:Nat_big_num.num=((Nat_big_num.of_int3))(** PC relative 32 bit *)letr_mips_26:Nat_big_num.num=((Nat_big_num.of_int4))(** Direct 26 bit shifted *)letr_mips_hi16:Nat_big_num.num=((Nat_big_num.of_int5))(** High 16 bit *)letr_mips_lo16:Nat_big_num.num=((Nat_big_num.of_int6))(** Low 16 bit *)letr_mips_gprel16:Nat_big_num.num=((Nat_big_num.of_int7))(** GP relative 16 bit *)letr_mips_literal:Nat_big_num.num=((Nat_big_num.of_int8))(** 16 bit literal entry *)letr_mips_got16:Nat_big_num.num=((Nat_big_num.of_int9))(** 16 bit GOT entry *)letr_mips_pc16:Nat_big_num.num=((Nat_big_num.of_int10))(** PC relative 16 bit *)letr_mips_call16:Nat_big_num.num=((Nat_big_num.of_int11))(** 16 bit GOT entry for function *)letr_mips_gprel32:Nat_big_num.num=((Nat_big_num.of_int12))(** GP relative 32 bit *)letr_mips_shift5:Nat_big_num.num=((Nat_big_num.of_int16))letr_mips_shift6:Nat_big_num.num=((Nat_big_num.of_int17))letr_mips_64:Nat_big_num.num=((Nat_big_num.of_int18))letr_mips_got_disp:Nat_big_num.num=((Nat_big_num.of_int19))letr_mips_got_page:Nat_big_num.num=((Nat_big_num.of_int20))letr_mips_got_ofst:Nat_big_num.num=((Nat_big_num.of_int21))letr_mips_got_hi16:Nat_big_num.num=((Nat_big_num.of_int22))letr_mips_got_lo16:Nat_big_num.num=((Nat_big_num.of_int23))letr_mips_sub:Nat_big_num.num=((Nat_big_num.of_int24))letr_mips_insert_a:Nat_big_num.num=((Nat_big_num.of_int25))letr_mips_insert_b:Nat_big_num.num=((Nat_big_num.of_int26))letr_mips_delete:Nat_big_num.num=((Nat_big_num.of_int27))letr_mips_higher:Nat_big_num.num=((Nat_big_num.of_int28))letr_mips_highest:Nat_big_num.num=((Nat_big_num.of_int29))letr_mips_call_hi16:Nat_big_num.num=((Nat_big_num.of_int30))letr_mips_call_lo16:Nat_big_num.num=((Nat_big_num.of_int31))letr_mips_scn_disp:Nat_big_num.num=((Nat_big_num.of_int32))letr_mips_rel16:Nat_big_num.num=((Nat_big_num.of_int33))letr_mips_add_immediate:Nat_big_num.num=((Nat_big_num.of_int34))letr_mips_pjump:Nat_big_num.num=((Nat_big_num.of_int35))letr_mips_relgot:Nat_big_num.num=((Nat_big_num.of_int36))letr_mips_jalr:Nat_big_num.num=((Nat_big_num.of_int37))letr_mips_tls_dtpmod32:Nat_big_num.num=((Nat_big_num.of_int38))(** Module number 32 bit *)letr_mips_tls_dtprel32:Nat_big_num.num=((Nat_big_num.of_int39))(** Module-relative offset 32 bit *)letr_mips_tls_dtpmod64:Nat_big_num.num=((Nat_big_num.of_int40))(** Module number 64 bit *)letr_mips_tls_dtprel64:Nat_big_num.num=((Nat_big_num.of_int41))(** Module-relative offset 64 bit *)letr_mips_tls_gd:Nat_big_num.num=((Nat_big_num.of_int42))(** 16 bit GOT offset for GD *)letr_mips_tls_ldm:Nat_big_num.num=((Nat_big_num.of_int43))(** 16 bit GOT offset for LDM *)letr_mips_tls_dtprel_hi16:Nat_big_num.num=((Nat_big_num.of_int44))(** Module-relative offset, high 16 bits *)letr_mips_tls_dtprel_lo16:Nat_big_num.num=((Nat_big_num.of_int45))(** Module-relative offset, low 16 bits *)letr_mips_tls_gottprel:Nat_big_num.num=((Nat_big_num.of_int46))(** 16 bit GOT offset for IE *)letr_mips_tls_tprel32:Nat_big_num.num=((Nat_big_num.of_int47))(** TP-relative offset, 32 bit *)letr_mips_tls_tprel64:Nat_big_num.num=((Nat_big_num.of_int48))(** TP-relative offset, 64 bit *)letr_mips_tls_tprel_hi16:Nat_big_num.num=((Nat_big_num.of_int49))(** TP-relative offset, high 16 bits *)letr_mips_tls_tprel_lo16:Nat_big_num.num=((Nat_big_num.of_int50))(** TP-relative offset, low 16 bits *)letr_mips_glob_dat:Nat_big_num.num=((Nat_big_num.of_int51))letr_mips_copy:Nat_big_num.num=((Nat_big_num.of_int126))letr_mips_jump_slot:Nat_big_num.num=((Nat_big_num.of_int127))(* TODO: borrowed from Dwarf, this should probbaly go somewhere else *)(*val natural_nat_shift_right : natural -> nat -> natural*)letbyte_mask:Nat_big_num.num=(natural_of_hex"0xFF")(*val get_mips64_relocation_subtypes : natural -> (natural * natural * natural)*)letget_mips64_relocation_subtypesrel_type1:Nat_big_num.num*Nat_big_num.num*Nat_big_num.num=(lettype1=(Nat_big_num.bitwise_andrel_type1byte_mask)inlettype2=(Nat_big_num.bitwise_and(Nat_big_num.shift_rightrel_type18)byte_mask)inlettype3=(Nat_big_num.bitwise_and(Nat_big_num.shift_rightrel_type116)byte_mask)in(type1,type2,type3))(*val string_of_mips64_relocation_subtype : natural -> string*)letstring_of_mips64_relocation_subtyperel_type1:string=(ifNat_big_num.equalrel_type1r_mips_nonethen"R_MIPS_NONE"elseifNat_big_num.equalrel_type1r_mips_16then"R_MIPS_16"elseifNat_big_num.equalrel_type1r_mips_32then"R_MIPS_32"elseifNat_big_num.equalrel_type1r_mips_rel32then"R_MIPS_REL32"elseifNat_big_num.equalrel_type1r_mips_26then"R_MIPS_26"elseifNat_big_num.equalrel_type1r_mips_hi16then"R_MIPS_HI16"elseifNat_big_num.equalrel_type1r_mips_lo16then"R_MIPS_LO16"elseifNat_big_num.equalrel_type1r_mips_gprel16then"R_MIPS_GPREL16"elseifNat_big_num.equalrel_type1r_mips_literalthen"R_MIPS_LITERAL"elseifNat_big_num.equalrel_type1r_mips_got16then"R_MIPS_GOT16"elseifNat_big_num.equalrel_type1r_mips_pc16then"R_MIPS_PC16"elseifNat_big_num.equalrel_type1r_mips_call16then"R_MIPS_CALL16"elseifNat_big_num.equalrel_type1r_mips_gprel32then"R_MIPS_GPREL32"elseifNat_big_num.equalrel_type1r_mips_shift5then"R_MIPS_SHIFT5"elseifNat_big_num.equalrel_type1r_mips_shift6then"R_MIPS_SHIFT6"elseifNat_big_num.equalrel_type1r_mips_64then"R_MIPS_64"elseifNat_big_num.equalrel_type1r_mips_got_dispthen"R_MIPS_GOT_DISP"elseifNat_big_num.equalrel_type1r_mips_got_pagethen"R_MIPS_GOT_PAGE"elseifNat_big_num.equalrel_type1r_mips_got_ofstthen"R_MIPS_GOT_OFST"elseifNat_big_num.equalrel_type1r_mips_got_hi16then"R_MIPS_GOT_HI16"elseifNat_big_num.equalrel_type1r_mips_got_lo16then"R_MIPS_GOT_LO16"elseifNat_big_num.equalrel_type1r_mips_subthen"R_MIPS_SUB"elseifNat_big_num.equalrel_type1r_mips_insert_athen"R_MIPS_INSERT_A"elseifNat_big_num.equalrel_type1r_mips_insert_bthen"R_MIPS_INSERT_B"elseifNat_big_num.equalrel_type1r_mips_deletethen"R_MIPS_DELETE"elseifNat_big_num.equalrel_type1r_mips_higherthen"R_MIPS_HIGHER"elseifNat_big_num.equalrel_type1r_mips_highestthen"R_MIPS_HIGHEST"elseifNat_big_num.equalrel_type1r_mips_call_hi16then"R_MIPS_CALL_HI16"elseifNat_big_num.equalrel_type1r_mips_call_lo16then"R_MIPS_CALL_LO16"elseifNat_big_num.equalrel_type1r_mips_scn_dispthen"R_MIPS_SCN_DISP"elseifNat_big_num.equalrel_type1r_mips_rel16then"R_MIPS_REL16"elseifNat_big_num.equalrel_type1r_mips_add_immediatethen"R_MIPS_ADD_IMMEDIATE"elseifNat_big_num.equalrel_type1r_mips_pjumpthen"R_MIPS_PJUMP"elseifNat_big_num.equalrel_type1r_mips_relgotthen"R_MIPS_RELGOT"elseifNat_big_num.equalrel_type1r_mips_jalrthen"R_MIPS_JALR"elseifNat_big_num.equalrel_type1r_mips_tls_dtpmod32then"R_MIPS_TLS_DTPMOD32"elseifNat_big_num.equalrel_type1r_mips_tls_dtprel32then"R_MIPS_TLS_DTPREL32"elseifNat_big_num.equalrel_type1r_mips_tls_dtpmod64then"R_MIPS_TLS_DTPMOD64"elseifNat_big_num.equalrel_type1r_mips_tls_dtprel64then"R_MIPS_TLS_DTPREL64"elseifNat_big_num.equalrel_type1r_mips_tls_gdthen"R_MIPS_TLS_GD"elseifNat_big_num.equalrel_type1r_mips_tls_ldmthen"R_MIPS_TLS_LDM"elseifNat_big_num.equalrel_type1r_mips_tls_dtprel_hi16then"R_MIPS_TLS_DTPREL_HI16"elseifNat_big_num.equalrel_type1r_mips_tls_dtprel_lo16then"R_MIPS_TLS_DTPREL_LO16"elseifNat_big_num.equalrel_type1r_mips_tls_gottprelthen"R_MIPS_TLS_GOTTPREL"elseifNat_big_num.equalrel_type1r_mips_tls_tprel32then"R_MIPS_TLS_TPREL32"elseifNat_big_num.equalrel_type1r_mips_tls_tprel64then"R_MIPS_TLS_TPREL64"elseifNat_big_num.equalrel_type1r_mips_tls_tprel_hi16then"R_MIPS_TLS_TPREL_HI16"elseifNat_big_num.equalrel_type1r_mips_tls_tprel_lo16then"R_MIPS_TLS_TPREL_LO16"elseifNat_big_num.equalrel_type1r_mips_glob_datthen"R_MIPS_GLOB_DAT"elseifNat_big_num.equalrel_type1r_mips_copythen"R_MIPS_COPY"elseifNat_big_num.equalrel_type1r_mips_jump_slotthen"R_MIPS_JUMP_SLOT"else"[Invalid MIPS relocation 0x"^((hex_string_of_naturalrel_type1)^"]"))(*val string_of_mips64_relocation_type : natural -> string*)letstring_of_mips64_relocation_typerel_type1:string=(let(type1,type2,type3)=(get_mips64_relocation_subtypesrel_type1)in(string_of_mips64_relocation_subtypetype1)^("/"^((string_of_mips64_relocation_subtypetype2)^("/"^(string_of_mips64_relocation_subtypetype3)))))(*val mips64_base_addr : symbol_reference_and_reloc_site -> natural -> natural*)letmips64_base_addrrrsite_addr:Nat_big_num.num=(letreloc_site1=((matchrr.maybe_relocwith|None->failwith"amd64_base_addr: no reloc site during relocation"|Somers->rs))inletoffset=(Ml_bindings.nat_big_num_of_uint64reloc_site1.ref_relent.elf64_ra_offset)inNat_big_num.sub_natsite_addroffset)(*val mips64_reloc : forall 'abifeature. reloc_fn 'abifeature*)letmips64_relocr:bool*('abifeatureannotated_memory_image->Nat_big_num.num->symbol_reference_and_reloc_site->Nat_big_num.num*(Nat_big_num.num->Nat_big_num.num->Nat_big_num.num->Nat_big_num.num))=((match(string_of_mips64_relocation_typer)with|"R_MIPS_NONE/R_MIPS_NONE/R_MIPS_NONE"->(false,(funimg2->(funsite_addr->(funrr->((Nat_big_num.of_int0),(funs->funa->funea->failwith"mips64_reloc: tried to apply a R_MIPS_NONE/R_MIPS_NONE/R_MIPS_NONE relocation"))))))(* TODO: not sure if always adding the base address is a good idea. Might be
better to make the caller do so only if the symbol is undefined. *)|"R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE"->(false,(funimg2->(funsite_addr->(funrr->((Nat_big_num.of_int8),(funs->funa->funea->Nat_big_num.add(i2n(Nat_big_num.add(Nat_big_num.suba(n2iea))(n2is)))(mips64_base_addrrrsite_addr)))))))|(* TODO *)"R_MIPS_TLS_TPREL64/R_MIPS_NONE/R_MIPS_NONE"->(false,(funimg2->(funsite_addr->(funrr->((Nat_big_num.of_int8),(funs->funa->funea->(Nat_big_num.of_int0)))))))|(* TODO *)"R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE"->(false,(funimg2->(funsite_addr->(funrr->((Nat_big_num.of_int8),(funs->funa->funea->(Nat_big_num.of_int0)))))))|"R_MIPS_JUMP_SLOT/R_MIPS_NONE/R_MIPS_NONE"->(false,(funimg2->(funsite_addr->(funrr->((Nat_big_num.of_int8),(funs->funa->funea->s))))))|_->failwith("unrecognised relocation "^(string_of_mips64_relocation_typer))))(* MIPS has a non-standard encoding for reloc info.
See https://sourceware.org/ml/libc-alpha/2003-03/msg00224.html *)(*val abi_mips_parse_elf64_relocation_info : elf64_xword -> (natural (* type *) * natural (* symbol *))*)letabi_mips_parse_elf64_relocation_infow:Nat_big_num.num*Nat_big_num.num=(letmask=(Uint64_wrapper.of_bigint(natural_of_hex"0xffffffff"))inletsym1=(Ml_bindings.nat_big_num_of_uint64(Uint64_wrapper.logandwmask))inlettyp=(Ml_bindings.nat_big_num_of_uint64(Uint64_wrapper.shift_rightw32))inlet(s1,s2,s3,s4)=(Uint32_wrapper.to_bytes(Uint32_wrapper.of_biginttyp))inlettyp=(Uint32_wrapper.to_bigint(Uint32_wrapper.of_quads4s3s2s1))in(typ,sym1))