You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
; ModuleID = 'other/array_acc'
source_filename = "other/array_acc"@rodata_11 = privateunnamed_addrconstant [41 x i8] c"\01\00\02\00data = %p\0A\00other = %p\0A\00Hello, World!\00", align4, !ROData_SecInfo!0declare dso_local i32@printf(i8*, ...)
define dso_local i32@test(i64%arg1) {
entry:
%stktop_8 = allocai8, i3224, align1%RSPAdj_N.16 = bitcasti8*%stktop_8toi64*%0 = getelementptri8, i8*%stktop_8, i6416%RBP_N.8 = bitcasti8*%0toi64*%1 = getelementptri8, i8*%stktop_8, i640%RSP_P.0 = bitcasti8*%1toi64*storei643735928559, i64*%RSP_P.0, align8%RBP = ptrtointi64*%RSP_P.0toi64storei64%arg1, i64*%RBP_N.8, align1%memload = loadi64, i64*%RBP_N.8, align1%2 = inttoptri64%memloadtoi64*%memload1 = loadi64, i64*%2, align1%EAX = calli32 (i8*, ...) @printf(i8*getelementptrinbounds ([41 x i8], [41 x i8]* @rodata_11, i320, i324), i64%memload1)
%memload2 = loadi64, i64*%RBP_N.8, align1%memref-disp = addi64%memload2, 8%3 = inttoptri64%memref-disptoi64*%memload3 = loadi64, i64*%3, align1%EAX4 = calli32 (i8*, ...) @printf(i8*getelementptrinbounds ([41 x i8], [41 x i8]* @rodata_11, i320, i3215), i64%memload3)
reti32%EAX4
}
define dso_local i32@main() {
entry:
%stktop_8 = allocai8, i3240, align1%RSPAdj_N.32 = bitcasti8*%stktop_8toi64*%0 = getelementptri8, i8*%stktop_8, i6416%RBP_N.24 = bitcasti8*%0toi64*%1 = getelementptri8, i8*%stktop_8, i6424%RBP_N.16 = bitcasti8*%1toi64*%2 = getelementptri8, i8*%stktop_8, i6436%RBP_N.4 = bitcasti8*%2toi32*%3 = getelementptri8, i8*%stktop_8, i640%RSP_P.0 = bitcasti8*%3toi64*storei643735928559, i64*%RSP_P.0, align8%RBP = ptrtointi64*%RSP_P.0toi64storei320, i32*%RBP_N.4, align1; %4 = input%4 = ptrtointi8*getelementptrinbounds ([41 x i8], [41 x i8]* @rodata_11, i320, i3227) toi64, !ROData_Index!1storei64%4, i64*%RBP_N.16, align1%memload = loadi64, i64*%RBP_N.16, align1storei64%memload, i64*%RSPAdj_N.32, align1; store 0 in RBP_N.24, which is calculated to be %stktop_8[16]; this is done because we have a stack of size 40; the problem is that the value is accessed relative to RBP with ; mov qword ptr [rbp - 24], 0; Detailed explanation with stack layout drawn attached%5 = zexti320toi64storei64%5, i64*%RBP_N.24, align1%RDI = ptrtointi64*%RSPAdj_N.32toi64%EAX = calli32@test(i64%RDI)
reti320
}
!0 = !{i642098368}
!1 = !{i8*getelementptrinbounds ([41 x i8], [41 x i8]* @rodata_11, i320, i3227)}
Stack layout of main
Stack just before calling test:
The total stack size used by the function is 40 bytes, 8 bytes by push rbp, while a further 32 bytes are allocated with sub rsp, 32. Mctoll incorrectly assumes that RBP points to the top of the stack (RSP when entering the function), which is off by 8 bytes, as the new value of RBP is set after push rbp.
I've only observed this bug in programs compiled with -O0, as (as far as I've seen) the stack is accessed relative to RSP with higher optimizations: https://godbolt.org/z/3vn6sMPPd.
While I have been trying to fix this issue, I've put it on hold because of this.
The text was updated successfully, but these errors were encountered:
Minimal example:
Output
Running the original and raised binary produces the following output:
Machine code
Compiled with clang-13
-O0
Raised bitcode
Stack layout of main
Stack just before calling
test
:The total stack size used by the function is 40 bytes, 8 bytes by
push rbp
, while a further 32 bytes are allocated withsub rsp, 32
. Mctoll incorrectly assumes thatRBP
points to the top of the stack (RSP when entering the function), which is off by 8 bytes, as the new value ofRBP
is set afterpush rbp
.I've only observed this bug in programs compiled with
-O0
, as (as far as I've seen) the stack is accessed relative toRSP
with higher optimizations: https://godbolt.org/z/3vn6sMPPd.While I have been trying to fix this issue, I've put it on hold because of this.
The text was updated successfully, but these errors were encountered: