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

macaw-ppc: Generalize ppc64_linux_info to take a Maybe (TOC w) argument instead of a LoadedBinary #415

Open
RyanGlScott opened this issue Jul 29, 2024 · 0 comments
Labels

Comments

@RyanGlScott
Copy link
Contributor

Compared to other ArchitectureInfo-producing functions, ppc64_linux_info is somewhat unusual in that it requires a LoadedBinary as an argument:

ppc64_linux_info :: ( BLP.HasTOC PPC64.PPC binFmt
) =>
BL.LoadedBinary PPC64.PPC binFmt
-> MI.ArchitectureInfo PPC64.PPC

This is because knowing the location of the entrypoint address in complicated on PPC64. In some cases, PPC64 binaries can have an .opd section with a table of contents (TOC), which is used to translate function addresses to the actual locations where the functions are defined. See this part of macaw-ppc-loader for the full story.

Ultimately, ppc64_linux_info's LoadedBinary argument is used to obtain the TOC for a binary. This approach is somewhat unsatisfactory, however, for two reasons:

  1. Not all PPC64 binaries have .opd sections (see macaw-loader-ppc crashes on PPC64 musl-gcc binaries  macaw-loader#21). For binaries without .opd sections, needing to pass in a TOC is overkill, since the TOC won't be used as part of the translation.
  2. It would be nice to develop a macaw-symbolic-syntax backend for PPC64 which consumes Crucible S-expression programs as input instead of binaries. This is currently impossible, however, as it is not possible to supply ppc64_linux_info with a LoadedBinary when the input isn't a binary in the first place.

To address both of these issues, I propose that we generalize the type of ppc64_linux_info to take a Maybe (TOC w) argument instead of a LoadedBinary argument. This way, one could pass Nothing to ppc64_linux_info whenever one has an .opd-less binary or a Crucible S-expression program as input. This approach would closely mirror how macaw-ppc's mkInitialAbsState function (which ppc64_linux_info invokes), which also takes a Maybe (TOC w) argument.

Note that it will likely be convenient to fix this issue and GaloisInc/macaw-loader#21 at the same time. A reasonable way to fix GaloisInc/macaw-loader#21 would be to change the return type of getTOC from TOC w to Maybe (TOC w). After this change has been made, one can call ppc64_linux_info (getTOC binary) to obtain an ArchitectureInfo value from a PPC64 binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant