Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference data created in other patches #9

Open
avncharlie opened this issue Aug 11, 2023 · 2 comments
Open

Reference data created in other patches #9

avncharlie opened this issue Aug 11, 2023 · 2 comments

Comments

@avncharlie
Copy link

Is there a way to define data in one patch that can be used in another patch?
I've tried to do like so:

context.register_insert(
    SingleBlockScope(module.entry_point, BlockPosition.ENTRY),
        Patch.from_function(lambda _:'''
            nop

            .data
            __variable:   .quad 0
    ''', Constraints(x86_syntax=X86Syntax.INTEL))
)

context.register_insert_function(
    'inserted_function_that_uses_var',
    Patch.from_function(lambda _: '''
        mov rdi, [rip + __variable]
    ''', Constraints(x86_syntax=X86Syntax.INTEL))
)

This causes this error:

    gtirb_rewriting.driver.main(AddAFLPass)
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/driver.py", line 350, in main
    _driver_core([entrypoint], False, argv)
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/driver.py", line 316, in _driver_core
    pass_man.run(ir)
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/passes.py", line 116, in run
    context.apply()
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/rewriting.py", line 1039, in apply
    self._apply_function_insertion(
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/rewriting.py", line 732, in _apply_function_insertion
    assembler_result = self._invoke_patch(
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/rewriting.py", line 404, in _invoke_patch
    assembler.assemble(asm, patch.constraints.x86_syntax)
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/assembler/assembler.py", line 333, in assemble
    assembler.assemble(_Streamer(self._state), asm)
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/assembler/assembler.py", line 122, in impl
    return func(self, *args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/assembler/assembler.py", line 998, in emit_instruction
    ] = self._fixup_to_symbolic_operand(
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/assembler/assembler.py", line 1584, in _fixup_to_symbolic_operand
    return self._mcexpr_to_symbolic_operand(expr, is_branch, loc)
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/assembler/assembler.py", line 1552, in _mcexpr_to_symbolic_operand
    sym = self._resolve_symbol_ref(expr)
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/assembler/assembler.py", line 1447, in _resolve_symbol_ref
    return self._resolve_symbol(expr.symbol, expr.location)
  File "/usr/local/lib/python3.9/dist-packages/gtirb_rewriting/assembler/assembler.py", line 1432, in _resolve_symbol
    raise UndefSymbolError._make(
gtirb_rewriting.assembler.assembler.UndefSymbolError: __variable is an undefined symbol reference

I've also tried to add the data in a seperate pass before it gets used but this also doesn't seem to work.
Thanks

@avncharlie
Copy link
Author

Using one pass to add the data and another to reference ended up working, I just wasn't doing it correctly. Closing as resolved

@jranieri-grammatech
Copy link
Collaborator

jranieri-grammatech commented Aug 14, 2023

Could you re-open this? I think gtirb-rewriting could handle this better at some point.

@avncharlie avncharlie reopened this Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants