Skip to main content

gtirb-rewriting

Overview

The gtirb-rewriting package provides a Python API for rewriting GTIRB files.

Getting Started

See the documentation in the Getting Started guide.

Watch the gtirb-rewriting presentation which introduces gtirb-rewriting and then demonstrates writing an example binary transform from scratch.

Supported ABIs

ISA File Format
ARM64 ELF
IA32 (x86) PE
X64 (x86-64) ELF
X64 (x86-64) PE
MIPS321 ELF

Design

A Pass registers changes to be made in a module with the RewritingContext passed to begin_module.

When using RewritingContext.register_insert, each change has a given Scope and a Patch to apply. The Scope allows the pass to declaratively state where the patch should be applied. Currently supported are:

  • AllBlocksScope to insert in every basic block
  • AllFunctionsScope to insert into every function's entry blocks or exit blocks.
  • SingleBlockScope to insert at a specific block

Alternatively, RewritingContext.insert_at and RewritingConext.replace_at take an exact location of function / block / offset to insert at.

A Patch consists of a method to generate an assembly string and a Constraints object that describes metadata about the assembly (e.g. what registers it clobbers or how many scratch registers it needs).

Once all changes from all passes have been registered, the rewriting context finds concrete insertion locations to insert the patch into. This is based off of the scope requested and the constraints in the patch. If the scope allows it, the rewriting context may attempt to find a location that is cheaper (e.g. requires no register spills). This is called bubbling.

After resolving the concrete insertion location, the patch is asked to generate its assembly code. The assembly is then assembled to machine code and inserted into the GTIRB representation. If the assembly refers to any symbols, the rewriting API will look them up in the GTIRB module's symbol table (asserting that they exist) and create the appropriate symbolic expressions. Also, if the patch's constraints require additional work like aligning the stack or spilling to free up the requested scratch register, this code will be generated at this point.

A pass may optionally be called back after all patches have been applied with the end_module method. This provides an opportunity to do per-module work, such as writing an edge map for a profiling pass.

Aux Data Tables

gtirb-rewriting uses some non-standardized aux data tables for preserving state across rewrites.

Label "leafFunctions" .
Type std::map<gtirb:UUID,uint8_t>
Key The gtirb::UUID of a function.
Value Whether or not the function was a leaf function (0/1).
AttachedTo gtirb::Module
Notes This table tracks whether functions were leaf functions when gtirb-rewriting initially saw them, which may not reflect the current state as rewriting passes can add calls.

Copyright and Acknowledgments

Copyright (C) 2020 GrammaTech, Inc.

This code is licensed under the GPLv3 license. See the LICENSE file in the project root for license terms.

This project is sponsored by the Office of Naval Research, One Liberty Center, 875 N. Randolph Street, Arlington, VA 22203 under contract #N68335-17-C-0700. The content of the information does not necessarily reflect the position or policy of the Government and no official endorsement should be inferred.

  1. Currently, only partial support is available for MIPS32. ↩

Release files for gtirb-rewriting 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for gtirb-rewriting 0.4.1
File Interpreter ABI Platform
gtirb_rewriting-0.4.1-py3-none-any.whl Python 3 none any Details

Release files / gtirb_rewriting-0.4.1-py3-none-any.whl

Download URL gtirb_rewriting-0.4.1-py3-none-any.whl
Size 142.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b5983bc701bf3dcb350c4a2e6a4d04c3c17c8be315178254f12bc57199bbc6f
BLAKE2b-256 checksum
How to use checksums
847e39aa97e7ee1db21949048c54832d9f8c5b6b0a2f72506935b4a880435ecb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release history Release notifications | RSS feed

This release

0.4.1 This release

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.24

1 release file

0.0.23

1 release file

0.0.22

1 release file

0.0.21

1 release file

0.0.20

1 release file

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page