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

Add support for x86 64 bit integer stack arguments. #2007

Merged
merged 3 commits into from
Jan 16, 2024

Conversation

andreistefanescu
Copy link
Contributor

No description provided.

intTests/test_llvm_x86_08/test.sh Show resolved Hide resolved
intTests/test_llvm_x86_08/test.o Outdated Show resolved Hide resolved
intTests/test_llvm_x86_08/test.saw Show resolved Hide resolved
finalMem <- liftIO $ C.LLVM.doStore bak mem' ptr
rsp <- getReg Macaw.RSP regs
ptr <- liftIO $ C.LLVM.doPtrAddOffset bak mem rsp =<< W4.bvLit sym knownNat (BV.mkBV knownNat (-8))
let writeAlign = C.LLVM.noAlignment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change from integerToAlignment defaultStackBaseAlign to noAlignment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch! Actually, this reveals a bug. The stack needs to be 16 byte aligned before the call instruction is executed, that is, before the return address has been pushed. The existing check is on %rsp after the return address has been pushed.

src/SAWScript/Crucible/LLVM/X86.hs Show resolved Hide resolved
Copy link
Member

@kquick kquick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple of minor questions, possibly deserving some inline comments. Happy to approve when you are ready, just not doing so yet to avoid activating the mergebot.

liftIO $ exceptToFail (typeOfSetupValue cc tyenv nameEnv sval) >>= \case
C.LLVM.PtrType _ -> pure ()
C.LLVM.IntType 64 -> pure ()
_ -> fail "Stack argument is not a 64 bit integer."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we only handling 64-bit arguments at this point? If test_llvm_x86_08 changed argument h from unsigned long to unsigned char, does clang promote it to a ulong argument or do we fail here?

Also, what are the expected semantics of fail here? Do we have a MonadFail instance with special handling, or should this use panic as on line 1061?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Longer term, it might be interesting to look at the abide library and utilize the functionality from there in this effort to consolidate and centralize our ABI handling. That said, I think that would be a future effort and not part of this utilitarian PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this only handles 64-bit arguments. I didn't investigate what clang does, I think it doesn't promote it. The semantics if fail, since this can happen, and it's just not handled. Also, this doesn't handle float/doable, and other non-integer types.


regs' <- use x86Regs
rsp <- getReg Macaw.RSP regs'
rsp' <- liftIO $ C.LLVM.doPtrAddOffset bak mem rsp =<< W4.bvLit sym knownNat (BV.mkBV knownNat (-8))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we detect/handle stack overflow? Is that just normal SAW detection of addressing memory not valid for the allocation in 969+970?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's just standard detection.

@andreistefanescu andreistefanescu merged commit db2b19a into master Jan 16, 2024
38 checks passed
@andreistefanescu andreistefanescu deleted the x86-stack-args branch January 16, 2024 06:23
RyanGlScott added a commit that referenced this pull request Feb 1, 2024
RyanGlScott added a commit that referenced this pull request Feb 3, 2024
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

Successfully merging this pull request may close these issues.

3 participants