Beispiel #1
0
def AddIns(unit: elf_unit.Unit, ins: a32.Ins):
    if ins.has_reloc():
        sym = unit.FindOrAddSymbol(ins.reloc_symbol, ins.is_local_sym)
        unit.AddReloc(ins.reloc_kind, unit.sec_text, sym,
                      ins.operands[ins.reloc_pos])
        ins.clear_reloc()
    unit.sec_text.AddData(a32.Assemble(ins).to_bytes(4, byteorder='little'))
Beispiel #2
0
def AddIns(unit: elf_unit.Unit, ins: a32.Ins):
    if ins.reloc_kind != elf_enum.RELOC_TYPE_ARM.NONE:
        sym = unit.FindOrAddSymbol(ins.reloc_symbol, ins.is_local_sym)
        unit.AddReloc(ins.reloc_kind, unit.sec_text, sym,
                      ins.operands[ins.reloc_pos])
        # clear reloc info before proceeding
        ins.reloc_kind = elf_enum.RELOC_TYPE_ARM.NONE
        ins.operands[ins.reloc_pos] = 0
    unit.sec_text.AddData(a32.Assemble(ins).to_bytes(4, byteorder='little'))
Beispiel #3
0
 def AddIns(self, ins: arm.Ins):
     if ins.reloc_kind != elf_enum.RELOC_TYPE_ARM.NONE:
         sym = self.FindOrAddSymbol(ins.reloc_symbol, ins.is_local_sym)
         self.AddReloc(ins.reloc_kind, self.sec_text, sym,
                       ins.operands[ins.reloc_pos])
         # clear reloc info before proceeding
         ins.reloc_kind = elf_enum.RELOC_TYPE_ARM.NONE
         ins.operands[ins.reloc_pos] = 0
     self.sec_text.AddData(
         arm.Assemble(ins).to_bytes(4, byteorder='little'))
Beispiel #4
0
 def AppendArmIns(armins: arm.Ins):
     if armins.reloc_kind != enum_tab.RELOC_TYPE_ARM.NONE:
         sym = armunit.FindOrAddSymbol(armins.reloc_symbol,
                                       armins.is_local_sym)
         armunit.AddReloc(armins.reloc_kind, sec_text, sym,
                          armins.operands[armins.reloc_pos])
         # clear reloc info before proceeding
         armins.reloc_kind = enum_tab.RELOC_TYPE_ARM.NONE
         armins.operands[armins.reloc_pos] = 0
     sec_text.AddData(
         arm.Assemble(armins).to_bytes(4, byteorder='little'))
Beispiel #5
0
def InsSymbolize(ins: a32.Ins) -> Tuple[str, List[str]]:
    """Convert all the operands in an arm.Ins to strings including relocs
    """
    ops = []
    for pos, (ok, value) in enumerate(zip(ins.opcode.fields, ins.operands)):
        if ok in _RELOC_OK and ins.has_reloc() and ins.reloc_pos == pos:
            # Note: we essentially store the "addend" here
            ops.append(_EmitReloc(ins, pos))
        else:
            ops.append(_SymbolizeOperand(ok, value))

    return ins.opcode.name, ops
Beispiel #6
0
def _HandleReloc(armins: arm.Ins, pos: int, ins: ir.Ins, op: PARAM):
    assert armins.reloc_kind == 0
    armins.reloc_pos = pos

    def movt_or_movw_rel(is_low):
        return enum_tab.RELOC_TYPE_ARM.MOVW_ABS_NC if is_low else enum_tab.RELOC_TYPE_ARM.MOVT_ABS

    if op in {PARAM.mem1_num2_lo16, PARAM.mem1_num2_hi16}:
        armins.reloc_kind = movt_or_movw_rel(op is PARAM.mem1_num2_lo16)
        mem = ins.operands[1]
        assert isinstance(mem, ir.Mem), f"{ins} {mem}"
        armins.reloc_symbol = mem.name
        num = ins.operands[2]
        assert isinstance(num, ir.Const), f"{ins} {num}"
        assert armins.operands[pos] == 0
        armins.operands[pos] = num.value
    elif op in {PARAM.jtb1_lo16, PARAM.jtb1_hi16}:
        armins.reloc_kind = movt_or_movw_rel(op is PARAM.jtb1_lo16)
        armins.is_local_sym = True
        jtb = ins.operands[1]
        assert isinstance(jtb, ir.Jtb), f"{ins} {jtb}"
        armins.reloc_symbol = jtb.name
    elif op in {PARAM.fun1_lo16, PARAM.fun1_hi16}:
        armins.reloc_kind = movt_or_movw_rel(op is PARAM.fun1_lo16)
        fun = ins.operands[1]
        assert isinstance(fun, ir.Fun), f"{ins} {fun}"
        armins.reloc_symbol = fun.name
    elif op is PARAM.bbl0:
        armins.reloc_kind = enum_tab.RELOC_TYPE_ARM.JUMP24
        armins.is_local_sym = True
        bbl = ins.operands[0]
        assert isinstance(bbl, ir.Bbl), f"{ins} {bbl}"
        armins.reloc_symbol = bbl.name
    elif op is PARAM.bbl2:
        armins.reloc_kind = enum_tab.RELOC_TYPE_ARM.JUMP24
        armins.is_local_sym = True
        bbl = ins.operands[2]
        assert isinstance(bbl, ir.Bbl), f"{ins} {bbl}"
        armins.reloc_symbol = bbl.name
    elif op is PARAM.fun0:
        armins.reloc_kind = enum_tab.RELOC_TYPE_ARM.CALL
        fun = ins.operands[0]
        assert isinstance(fun, ir.Fun), f"{ins} {fun}"
        armins.reloc_symbol = fun.name
    else:
        assert False