-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewriter: Redeclare static functions that have their address taken wi…
…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.
- Loading branch information
Showing
7 changed files
with
110 additions
and
19 deletions.
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,13 @@ | ||
define_shared_lib( | ||
SRCS lib.c | ||
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,42 @@ | ||
#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" | ||
|
||
static 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