-
Notifications
You must be signed in to change notification settings - Fork 38
Closed
Description
simpasm simplifies assembly by assembling and disassembling. Global labels are kept and branches adjusted accordingly:
- Global labels
0xDEADBEEF <LABEL>:are detected in the output ofobjdump --disassembleand replaced byLABEL:. - References of the form
0xDEADBEEF <LABEL>are detected and replaced byLABEL
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 --disassembleinto a triple (label, address, instruction) as follows:- For a label
0xDEADBEEF <LABEL>, produce the triple(LABEL, None, None). This is essentiallydecode_labelin the current implementation ofsimpasm. - 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.
- For a label
- 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 labelFUNCNAME_DEADBEEFin the first component. Replace the0xDEADBEEF <LABEL>byFUNCNAME_DEADBEEF. - Finally, produce the assembly by emitting, for each triple
(LABEL, ADDRESS, INSTRUCTION TEXT), eitherINSTRUCTION TEXTiflabelisNone, orLABEL: INSTRUCTION TEXTotherwise.
Metadata
Metadata
Assignees
Labels
No labels