-
Notifications
You must be signed in to change notification settings - Fork 141
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
Fix behavior around jumps with immediate values > 0x7fffffff in the interpreter #447
Conversation
Signed-off-by: Alan Jowett <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
Signed-off-by: Alan Jowett <[email protected]>
external/bpf_conformance
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be a separate commit?
* @return The sign extended 64-bit value. | ||
*/ | ||
static int64_t sign_extend_immediate(int32_t immediate) { | ||
return (int64_t)immediate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am currently working through whether or not this is guaranteed to give the proper behavior according to the C standard. In newer versions of the C standard, twos complement representation of signed integers is specified. In older versions, it is not. Therefore, we will (I think) need to be very careful about this. See, e.g., https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2218.htm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further research:
- GCC represents integers as twos complement: https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Integers-implementation.html#Integers-implementation
- MSVC represents integers as twos complement: https://learn.microsoft.com/en-us/cpp/c-language/range-of-integer-values?view=msvc-170
There does not appear to be a place where Clang (llvm) defines its implementation-specific behavior. See llvm/llvm-project#11644 for the status of such a document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the yet-to-be standardized version of C, twos complement is specified as the representation to use for signed integers. See https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf
Signed-off-by: Alan Jowett <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that I am happy that what we have written will sign extend properly in the case of the three most common compilers on the platforms that we support.
* @return The sign extended 64-bit value. | ||
*/ | ||
static int64_t sign_extend_immediate(int32_t immediate) { | ||
return (int64_t)immediate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the yet-to-be standardized version of C, twos complement is specified as the representation to use for signed integers. See https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf
Resolves: #444
Interpreter wasn't correctly sign extending the immediate value before comparing it to the register.