-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
define_shared_lib( | ||
SRCS lib.c | ||
NEEDS_LD_WRAP | ||
PKEY 2 | ||
) | ||
|
||
define_test( | ||
SRCS main.c | ||
NEEDS_LD_WRAP | ||
PKEY 1 | ||
CRITERION_TEST | ||
) | ||
|
||
define_ia2_wrapper() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
typedef void (*fn_ptr_ty)(void); | ||
|
||
static void inline_noop(void) { | ||
printf("called %s defined in header\n", __func__); | ||
} | ||
|
||
fn_ptr_ty *get_ptrs_in_main(void); | ||
fn_ptr_ty *get_ptrs_in_lib(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <criterion/criterion.h> | ||
#include <criterion/logging.h> | ||
#include <ia2.h> | ||
|
||
//#include <test_fault_handler.h> | ||
|
||
#define IA2_COMPARTMENT 2 | ||
#include <ia2_compartment_init.inc> | ||
|
||
#include "static_fns.h" | ||
|
||
static void duplicate_noop(void) { | ||
printf("called %s in library\n", __func__); | ||
} | ||
|
||
static void identical_name(void) { | ||
static int x = 4; | ||
printf("%s in library read x = %d\n", __func__, x); | ||
} | ||
|
||
static fn_ptr_ty ptrs[3] IA2_SHARED_DATA = { | ||
inline_noop, duplicate_noop, identical_name | ||
}; | ||
|
||
fn_ptr_ty *get_ptrs_in_lib(void) { | ||
return ptrs; | ||
} | ||
|
||
Test(static_addr_taken, call_ptrs_in_lib) { | ||
for (int i = 0; i < 3; i++) { | ||
ptrs[i](); | ||
} | ||
} | ||
|
||
Test(static_addr_taken, call_ptr_from_main) { | ||
fn_ptr_ty *main_ptrs = get_ptrs_in_main(); | ||
for (int i = 0; i < 3; i++) { | ||
main_ptrs[i](); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <criterion/criterion.h> | ||
#include <criterion/logging.h> | ||
#include <ia2.h> | ||
|
||
//#define IA2_DEFINE_TEST_HANDLER | ||
//#include <test_fault_handler.h> | ||
|
||
INIT_RUNTIME(2); | ||
#define IA2_COMPARTMENT 1 | ||
#include <ia2_compartment_init.inc> | ||
|
||
#include "static_fns.h" | ||
|
||
#define LOCAL static | ||
|
||
LOCAL void duplicate_noop(void) { | ||
printf("called %s in main binary\n", __func__); | ||
} | ||
|
||
static void identical_name(void) { | ||
static int x = 3; | ||
printf("%s in main binary read x = %d\n", __func__, x); | ||
} | ||
|
||
static fn_ptr_ty ptrs[3] IA2_SHARED_DATA = { | ||
inline_noop, duplicate_noop, identical_name | ||
}; | ||
|
||
fn_ptr_ty *get_ptrs_in_main(void) { | ||
return ptrs; | ||
} | ||
|
||
Test(static_addr_taken, call_ptrs_in_main) { | ||
for (int i = 0; i < 3; i++) { | ||
ptrs[i](); | ||
} | ||
} | ||
|
||
Test(static_addr_taken, call_ptr_from_lib) { | ||
fn_ptr_ty *lib_ptrs = get_ptrs_in_lib(); | ||
for (int i = 0; i < 3; i++) { | ||
lib_ptrs[i](); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 typesfunc
's signature depends on.