Skip to content
Snippets Groups Projects

checkasm: Improve 32-bit parameter clobbering on x86-64

Merged Henrik Gramner requested to merge gramner/dav1d:checkasm_arg_clobber into master
All threads resolved!

The previous method of doing parameter clobbering was hacky and unreliable, but this approach works much better. The same could probably be done for AArch64 as well.

Also fix one bug that was detected because of this improvement.

This relies on _Generic(), which is part of C11. AFAIK pretty much all reasonably modern compilers support this, however MSVC doesn't enable it unless compiled with /std:c11. We already use some C11 features (stdatomic.h and anonymous structs/unions), so maybe we should just embrace C11?

Merge request reports

Checking pipeline status.

Approved by

Merged by Henrik GramnerHenrik Gramner 2 years ago (Sep 30, 2022 2:33pm UTC)

Merge details

  • Changes merged into master with 58c856b7.
  • Deleted the source branch.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Martin Storsjö
    • Resolved by Martin Storsjö

      FWIW I think the form used here, to just check if we happen to have _Generic available even if we're in C99 mode and conditionally use it then, is fine - it doesn't disrupt builds in other configurations, etc, and should be plenty, as long as most compilers used in the CI actually do end up enabling it.

    • Resolved by Martin Storsjö

      The same could probably be done for AArch64 as well.

      Yeah, I guess so. On the other hand, I haven't ever seen an aarch64 compiler call functions by locally pushing registers on the stack, as opposed to just write them into a preallocated stack area, so there's not much rush either (other than to keep things consistent - and reduce the risk of later surprises of course).

      I guess one upside of the previous approach, is that it also takes care of clobbering more than 32 bit for smaller arguments, if the ABI allows more bits of a parameter register to be undefined.

  • Henrik Gramner resolved all threads

    resolved all threads

  • Henrik Gramner added 3 commits

    added 3 commits

    • 6fefa6a5 - checkasm: Improve 32-bit parameter clobbering on x86-64
    • 0b0b5fbf - checkasm: Move printf format string to .rodata on x86
    • 58c856b7 - build: strip() the result of cc.get_define()

    Compare with previous version

  • Martin Storsjö resolved all threads

    resolved all threads

  • Martin Storsjö approved this merge request

    approved this merge request

  • LGTM, this looks reasonable to me. I didn't check the asm changes in detail (in particular not the change to move the string constant to rodata), but I didn't see anything I'd object to at least.

  • Please register or sign in to reply
    Loading