Development:StructPackVerifier

From FEX-Emu Wiki
Revision as of 14:33, 15 March 2021 by Sonicadvance1 (talk | contribs)
Jump to navigation Jump to search

Struct packing verifier

The struct packing verifier python script allows us to validate struct packings match between aliases and architectures. This is necessary to ensure auto generated structs match across architectures and handwritten structs match the original architecture's struct.

Struct annotations

The verifier tool looks for structures and unions with specifically crafted annotations to only check the ones we care about.

`__attribute__((annotate("alias-<arch>-<struct name>")))`

  • Where arch can be x86_32, x86_64, aarch64, win32, win64
  • Struct name is the original structure name that the struct to should alias to
  • eg `__attribute__((annotate("alias-x86_32-rusage")))`

`__attribute__((annotate("fex-match")))`

  • If a struct should be compared across architectures then we use this to ensure it matches
  • FEX will compare that the struct matches between x86-64 and aarch64 for compatibility

Dependencies

  • python3
  • python3-clang
  • clang (required to find default include paths)
  • Multilib packages
    • 32bit Linux
      • libc6-dev-i386-cross
      • libstdc++6-i386-cross
      • libstdc++-10-dev-i386-cross
      • linux-libc-dev-i386-cross
    • 64bit Linux
      • libc6-dev
      • linux-libc-dev
    • AArch64 Linux
      • libc6-dev-arm64-cross
      • linux-libc-dev-arm64-cross
      • libstdc++6-arm64-cross
      • libstdc++-10-dev-arm64-cross
    • Mingw for Windows
      • g++-mingw-w64-x86-64
      • g++-mingw-w64-x86-64-win32
      • g++-mingw-w64-x86-64-posix
      • g++-mingw-w64-i686
      • g++-mingw-w64-i686-win32
      • g++-mingw-w64-i686-posix

Getting a result

If the arguments are passed in to the tool correctly then it will return 0 if everything matches, else it returns 1 if something hasn't matched. You'll then get logging output to compare against

Bugs

The libclang python implementation might not be all encompassing of definitions. So one should be careful to only throw basic struct and union types at the tooling. Ideally only POD types should be compared with the expectation that structs will be crossing architecture boundaries and need to match.