Skip to content

Commit

Permalink
gcc-plugins: Use dynamic initializers
Browse files Browse the repository at this point in the history
GCC 8 changed the order of some fields and is very picky about ordering
in static initializers, so instead just move to dynamic initializers,
and drop the redundant already-zero field assignments.

Suggested-by: Valdis Kletnieks <[email protected]>
Signed-off-by: Kees Cook <[email protected]>
  • Loading branch information
kees committed Feb 6, 2018
1 parent 80d1724 commit b867291
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 78 deletions.
17 changes: 5 additions & 12 deletions scripts/gcc-plugins/latent_entropy_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,14 @@ static tree handle_latent_entropy_attribute(tree *node, tree name,
return NULL_TREE;
}

static struct attribute_spec latent_entropy_attr = {
.name = "latent_entropy",
.min_length = 0,
.max_length = 0,
.decl_required = true,
.type_required = false,
.function_type_required = false,
.handler = handle_latent_entropy_attribute,
#if BUILDING_GCC_VERSION >= 4007
.affects_type_identity = false
#endif
};
static struct attribute_spec latent_entropy_attr = { };

static void register_attributes(void *event_data __unused, void *data __unused)
{
latent_entropy_attr.name = "latent_entropy";
latent_entropy_attr.decl_required = true;
latent_entropy_attr.handler = handle_latent_entropy_attribute;

register_attribute(&latent_entropy_attr);
}

Expand Down
75 changes: 21 additions & 54 deletions scripts/gcc-plugins/randomize_layout_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,68 +580,35 @@ static void finish_type(void *event_data, void *data)
return;
}

static struct attribute_spec randomize_layout_attr = {
.name = "randomize_layout",
// related to args
.min_length = 0,
.max_length = 0,
.decl_required = false,
// need type declaration
.type_required = true,
.function_type_required = false,
.handler = handle_randomize_layout_attr,
#if BUILDING_GCC_VERSION >= 4007
.affects_type_identity = true
#endif
};
static struct attribute_spec randomize_layout_attr = { };
static struct attribute_spec no_randomize_layout_attr = { };
static struct attribute_spec randomize_considered_attr = { };
static struct attribute_spec randomize_performed_attr = { };

static struct attribute_spec no_randomize_layout_attr = {
.name = "no_randomize_layout",
// related to args
.min_length = 0,
.max_length = 0,
.decl_required = false,
// need type declaration
.type_required = true,
.function_type_required = false,
.handler = handle_randomize_layout_attr,
static void register_attributes(void *event_data, void *data)
{
randomize_layout_attr.name = "randomize_layout";
randomize_layout_attr.type_required = true;
randomize_layout_attr.handler = handle_randomize_layout_attr;
#if BUILDING_GCC_VERSION >= 4007
.affects_type_identity = true
randomize_layout_attr.affects_type_identity = true;
#endif
};

static struct attribute_spec randomize_considered_attr = {
.name = "randomize_considered",
// related to args
.min_length = 0,
.max_length = 0,
.decl_required = false,
// need type declaration
.type_required = true,
.function_type_required = false,
.handler = handle_randomize_considered_attr,
no_randomize_layout_attr.name = "no_randomize_layout";
no_randomize_layout_attr.type_required = true;
no_randomize_layout_attr.handler = handle_randomize_layout_attr;
#if BUILDING_GCC_VERSION >= 4007
.affects_type_identity = false
no_randomize_layout_attr.affects_type_identity = true;
#endif
};

static struct attribute_spec randomize_performed_attr = {
.name = "randomize_performed",
// related to args
.min_length = 0,
.max_length = 0,
.decl_required = false,
// need type declaration
.type_required = true,
.function_type_required = false,
.handler = handle_randomize_performed_attr,
#if BUILDING_GCC_VERSION >= 4007
.affects_type_identity = false
#endif
};
randomize_considered_attr.name = "randomize_considered";
randomize_considered_attr.type_required = true;
randomize_considered_attr.handler = handle_randomize_considered_attr;

randomize_performed_attr.name = "randomize_performed";
randomize_performed_attr.type_required = true;
randomize_performed_attr.handler = handle_randomize_performed_attr;

static void register_attributes(void *event_data, void *data)
{
register_attribute(&randomize_layout_attr);
register_attribute(&no_randomize_layout_attr);
register_attribute(&randomize_considered_attr);
Expand Down
19 changes: 7 additions & 12 deletions scripts/gcc-plugins/structleak_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,16 @@ static tree handle_user_attribute(tree *node, tree name, tree args, int flags, b
return NULL_TREE;
}

static struct attribute_spec user_attr = {
.name = "user",
.min_length = 0,
.max_length = 0,
.decl_required = false,
.type_required = false,
.function_type_required = false,
.handler = handle_user_attribute,
#if BUILDING_GCC_VERSION >= 4007
.affects_type_identity = true
#endif
};
static struct attribute_spec user_attr = { };

static void register_attributes(void *event_data, void *data)
{
user_attr.name = "user";
user_attr.handler = handle_user_attribute;
#if BUILDING_GCC_VERSION >= 4007
user_attr.affects_type_identity = true;
#endif

register_attribute(&user_attr);
}

Expand Down

0 comments on commit b867291

Please sign in to comment.