-
Notifications
You must be signed in to change notification settings - Fork 0
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
rewriter: Redeclare static functions that have their address taken with used #441
Conversation
Still need to add LIT annotations and a reference for the expected stdout to the new test. |
…th __used__ When we make call gates for static functions that have their address taken, the static function is only referenced from the asm for the call gate. When compiling with optimizations dead code elimination may get rid of the static functions unless they are marked with __attribute__((__used__)). The rewriter previously prepended this attribute in this case to avoid that. This commit removes the prepended attribute and instead redeclares these functions with that attribute. Closes #414 and fixes a test added for #428.
guess clang is more strict than gcc here. I could add a |
I went with the |
TODO: push the tests with the case mentioned in #414 |
@@ -48,7 +48,9 @@ | |||
#define IA2_CALL(opaque, id) opaque | |||
#define IA2_CAST(func, ty) (ty) (void *) func | |||
#else | |||
#define IA2_DEFINE_WRAPPER(func) IA2_DEFINE_WRAPPER_##func | |||
#define IA2_DEFINE_WRAPPER(func) \ | |||
__attribute__((__used__)) static void *keep_##func = (void *)func; \ |
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 don't love adding a function pointer to data just to mark a function as used. We don't have any other way?
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 haven't put much thought into this. There might be a way to get __attribute__((used)) typeof(func) func;
before the function definition, but I'd need to think about how that would work with the types func
's signature depends on.
Would marking them with |
When we make call gates for static functions that have their address taken, the static function is only referenced from the asm for the call gate. Compiling with optimizations may get rid of the static functions unless they are marked with
__attribute__((__used__))
. The rewriter previously prepended this attribute in this case to avoid that. This commit removes the prepended attribute and instead redeclares these functions with that attribute. Closes #414 and fixes a test added for #428.