Skip to content

simpasm: Allow local labels #1163

@hanno-becker

Description

@hanno-becker

simpasm simplifies assembly by assembling and disassembling. Global labels are kept and branches adjusted accordingly:

  • Global labels 0xDEADBEEF <LABEL>: are detected in the output of objdump --disassemble and replaced by LABEL:.
  • References of the form 0xDEADBEEF <LABEL> are detected and replaced by LABEL

This does not work for local labels (.L-prefixed for gcc or L-prefixed for clang). For those, no label will be present in the output of objdump --disassemble, and branches will be relative to surrounding labels, e.g. 0xDEADBEEF <LABEL + 0xCAFFEE>.

Task:
simpasm should use a modified patch_disasm, which works as follows:

  • Decode every line in the output of objdump --disassemble into a triple (label, address, instruction) as follows:
    • For a label 0xDEADBEEF <LABEL>, produce the triple (LABEL, None, None). This is essentially decode_label in the current implementation of simpasm.
    • For a line of the form ADDRESS: BYTECODE {INSTRUCTION TEXT}, map it to (None, ADDRESS, INSTRUCTION TEXT)`. This is essentially the regexp after "Drop address and byte code form line"
    • Otherwise, drop the line.
  • Then, go through the resulting list of triples, and identify instructions whose instruction text contains relative labels 0xDEADBEEF <LABEL>. In this case, find the instruction with ADDRESS = 0xDEADBEEF in its second component, and add a dummy label FUNCNAME_DEADBEEF in the first component. Replace the 0xDEADBEEF <LABEL> by FUNCNAME_DEADBEEF.
  • Finally, produce the assembly by emitting, for each triple (LABEL, ADDRESS, INSTRUCTION TEXT), either INSTRUCTION TEXT if label is None, or LABEL: INSTRUCTION TEXT otherwise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions