-
Notifications
You must be signed in to change notification settings - Fork 120
Change the definition of shemu_printf so that unused parameters are removed from the compiled binary #111
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
Change the definition of shemu_printf so that unused parameters are removed from the compiled binary #111
Conversation
…ngs etc.) are removed from the compiled binary
|
Unfortunately static inline void shemu_printf_helper(SHEMU_CONTEXT *c, ...) { (void)c; }
#define shemu_printf(c, f, ...) do { (void)f; shemu_printf_helper(c, __VA_ARGS__); } while (0)Alternatively we could disable the unused variable warnings for |
|
You could just rename This does not lead to any warnings, and the formatting strings will no longer be a part of the binary. |
|
Both approaches look good to me, as long as it does remove the strings. Btw thank you for your fast replies! |
Where, exactly? There shouldn't be any warnings/errors, if implemented correctly (I tested it locally, and there are none). |
Triggers multiple warnings with clang: https://godbolt.org/z/6WPGsvTWK |
Ok my bad, I checked again and there are no warnings/errors with your approach. I probably did not implemented it exactly like that when I tested previously. [Edit] Just saw the comment from ianichitei. Checking the approach suggested by ianichitei. |
True, but we can accept |
This does not work either because the formatstring is missing in the invocation of shemu_printf_helper and leads to types mismatch when interpreting VA_ARGS: |
Yes, we can solve this from our CMake build script. Speaking of which, the way we always enable all warnings isn't friendly to people who consume A solution that will work regardless of compiler and compiler flags: #define shemu_printf(c, f, ...) do { (void)f; shemu_printf_internal(c, NULL, __VA_ARGS__); } while (0)With |
This works as well. |
|
I fixed the code on my branch according to your last comment, and pushed. |
|
|
||
| Context->Log(buff, Context->AuxData); | ||
| } | ||
| #else |
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.
This part needs to stay the same, only the name must be changed to shemu_internal_printf.
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.
Done
bdshemu/include/bdshemu_common.h
Outdated
| #ifndef BDDISASM_NO_FORMAT | ||
| #define shemu_printf(Context, formatstring, ...) shemu_internal_printf(Context, formatstring, __VA_ARGS__) | ||
| #else | ||
| #define shemu_printf(Context, formatstring, ...) do { (void)formatstring; shemu_internal_printf(Context, NULL, __VA_ARGS__); } while (0) |
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.
There is no NULL defined in bddisasm/bdshemu. There is, instead, ND_NULL - which you should use instead.
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.
Fixed
|
All checks passed, the required one that's stuck can be ignored (not a real check, config issue). |
With the current implementation of shemu_printf, when BDDISASM_NO_FORMAT is defined, the parameters of shemu_printf are present in the output binary even though they are not used. This is due to the fact that shemu_printf is defined as a function.
For example, strings like " Loop BREAK from RIP 0x%016llx, TARGET 0x%016llx, ITER %llu\n" can be found in the binary.
I am working on an embedded device where I do not have a lot of memory and it does not make sense in this context to embed these strings if they are not used.
This PR introduces a new declaration of shemu_printf based on a macro that enables the compilers to remove these strings from the output binary and reduce its size.