fix a or logical error

This commit is contained in:
fanfuqiang 2018-12-02 23:27:38 +08:00
parent cacbb665ea
commit 53c93270ff
5 changed files with 1138 additions and 33 deletions

View File

@ -9,7 +9,8 @@ CFLAGS = -g3 -O0 -std=gnu++98 -ggdb -fvisibility=hidden -fno-rtti \
-fno-exceptions -fPIC -c
HEADER = -I`$(CC) -print-file-name=plugin`/include \
-I`$(CC) -print-file-name=plugin`/include/c-family \
-I..
-I..
# -I/usr/include/c++/7.3.0 -I/usr/include/x86_64-linux-gnu/c++/7
#HEADER = -I/usr/lib/gcc/x86_64-linux-gnu/4.8/plugin/include \
-I../../gcc-plugins
RAP = rap_plugin.so # target lib

View File

@ -0,0 +1,14 @@
/* Writed by David fuqiang Fan <feqin1023@gmail.com> &
Shawn C[a.k.a "citypw"] <citypw@gmail.com> members of HardenedLinux.
The code of this file try to make some optimizationsfor PaX RAP.
Supply the API for RAP.
Contains function api wrappers conquer different GCC versions.
Licensed under the GPL v2. */
#if BUILDING_GCC_VERSION >= 7000
#define cfi_hash_set

View File

@ -18,6 +18,12 @@
#include "bitmap.h"
#include "gimple-pretty-print.h"
#if BUILDING_GCC_VERSION < 7000
#include "pointer-set.h"
#else
#include "hash-set.h"
#include "hash-map.h"
#endif
/* There are many optimization methrod can do for RAP.
From simple to complex and aside with the gcc internal work stage.
@ -47,8 +53,18 @@ int rap_opt_statistics_data;
/* Contain all the sensitive functions which maybe the targets of ROP.
so all of these functons should compute and output the function hash. */
static bitmap sensi_funcs;
#if BUILDING_GCC_VERSION < 7000
/* Contains the type database which are pointer analysis can not sloved */
static struct pointer_set_t *sensi_func_types;
#else
/* gcc has change the struct gimple base type.!!! */
#define gimple gimple*
static hash_set<tree> *sensi_func_types;
#endif
/* Every fucntion has only one catch basic block. */
//static basic_block the_cfi_catch_bb_for_cfun;
//
@ -342,8 +358,7 @@ hl_gather_gate ()
//#define PROPERTIES_REQUIRED PROP_gimple_any
//#define PROPERTIES_PROVIDED PROP_gimple_lcf
#define TODO_FLAGS_FINISH \
TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | \
TODO_remove_unused_locals | TODO_verify_flow
TODO_verify_ssa | TODO_verify_stmts | TODO_verify_flow
#include "gcc-generate-simple_ipa-pass.h"
#undef PASS_NAME
@ -356,6 +371,8 @@ is_rap_function_maybe_roped (tree f)
{
if (! is_rap_function_may_be_aliased (f))
return 0;
// for test.
return 1;
/* Ask the oracle for help */
if (0 == cfi_gcc_optimize_level)
/* Function is_rap_function_may_be_aliased() must be failed we arive here,
@ -962,7 +979,6 @@ hl_cfi_gate ()
//#define PROPERTIES_PROVIDED PROP_gimple_lcf
#define TODO_FLAGS_FINISH \
TODO_verify_ssa | TODO_verify_stmts | TODO_verify_flow | \
TODO_dump_func | TODO_remove_unused_locals | TODO_cleanup_cfg | \
TODO_rebuild_cgraph_edges
TODO_cleanup_cfg | TODO_rebuild_cgraph_edges
#include "gcc-generate-simple_ipa-pass.h"
#undef PASS_NAME

View File

@ -202,7 +202,7 @@ static void rap_begin_function(tree decl)
/* We do not have any risk, we do not need the hash key before the function. */
if (0 == imprecise_rap_hash.hash
&&
||
! is_rap_function_maybe_roped (decl)) {
return;
}
@ -546,13 +546,13 @@ static bool rap_version_check(struct plugin_gcc_version *gcc_version, struct plu
{
if (!gcc_version || !plugin_version)
return false;
#if 0
#if BUILDING_GCC_VERSION >= 5000
if (strncmp(gcc_version->basever, plugin_version->basever, 4))
#else
if (strcmp(gcc_version->basever, plugin_version->basever))
#endif
return false;
#if 0
if (strcmp(gcc_version->datestamp, plugin_version->datestamp))
return false;
if (strcmp(gcc_version->devphase, plugin_version->devphase))
@ -808,9 +808,13 @@ __visible int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gc
if (!enable_type_ret)
rap_fptr_pass_info.reference_pass_name = "optimized";
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &hl_gather_pass_info);
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &hl_cfi_pass_info);
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &rap_fptr_pass_info);
if (require_call_hl_gather)
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &hl_gather_pass_info);
//
if (require_call_hl_cfi)
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &hl_cfi_pass_info);
else
register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &rap_fptr_pass_info);
}
return 0;

File diff suppressed because it is too large Load Diff