Skip to content

Commit 8cbce37

Browse files
Frantisek Hrbatatorvalds
authored andcommitted
gcov: move gcov structs definitions to a gcc version specific file
Since also the gcov structures(gcov_info, gcov_fn_info, gcov_ctr_info) can change between gcc releases, as shown in gcc 4.7, they cannot be defined in a common header and need to be moved to a specific gcc implemention file. This also requires to make the gcov_info structure opaque for the common code and to introduce simple helpers for accessing data inside gcov_info. Signed-off-by: Frantisek Hrbata <fhrbata@redhat.com> Cc: Jan Stancek <jstancek@redhat.com> Cc: Kees Cook <keescook@chromium.org> Acked-by: Peter Oberparleiter <peter.oberparleiter@de.ibm.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Andy Gospodarek <agospoda@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0d20633 commit 8cbce37

4 files changed

Lines changed: 153 additions & 80 deletions

File tree

‎kernel/gcov/base.c‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <linux/mutex.h>
2121
#include "gcov.h"
2222

23-
static struct gcov_info *gcov_info_head;
2423
static int gcov_events_enabled;
2524
static DEFINE_MUTEX(gcov_lock);
2625

@@ -34,7 +33,7 @@ void __gcov_init(struct gcov_info *info)
3433

3534
mutex_lock(&gcov_lock);
3635
if (gcov_version == 0) {
37-
gcov_version = info->version;
36+
gcov_version = gcov_info_version(info);
3837
/*
3938
* Printing gcc's version magic may prove useful for debugging
4039
* incompatibility reports.
@@ -45,8 +44,7 @@ void __gcov_init(struct gcov_info *info)
4544
* Add new profiling data structure to list and inform event
4645
* listener.
4746
*/
48-
info->next = gcov_info_head;
49-
gcov_info_head = info;
47+
gcov_info_link(info);
5048
if (gcov_events_enabled)
5149
gcov_event(GCOV_ADD, info);
5250
mutex_unlock(&gcov_lock);
@@ -91,13 +89,15 @@ EXPORT_SYMBOL(__gcov_merge_delta);
9189
*/
9290
void gcov_enable_events(void)
9391
{
94-
struct gcov_info *info;
92+
struct gcov_info *info = NULL;
9593

9694
mutex_lock(&gcov_lock);
9795
gcov_events_enabled = 1;
96+
9897
/* Perform event callback for previously registered entries. */
99-
for (info = gcov_info_head; info; info = info->next)
98+
while ((info = gcov_info_next(info)))
10099
gcov_event(GCOV_ADD, info);
100+
101101
mutex_unlock(&gcov_lock);
102102
}
103103

@@ -112,25 +112,23 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
112112
void *data)
113113
{
114114
struct module *mod = data;
115-
struct gcov_info *info;
116-
struct gcov_info *prev;
115+
struct gcov_info *info = NULL;
116+
struct gcov_info *prev = NULL;
117117

118118
if (event != MODULE_STATE_GOING)
119119
return NOTIFY_OK;
120120
mutex_lock(&gcov_lock);
121-
prev = NULL;
121+
122122
/* Remove entries located in module from linked list. */
123-
for (info = gcov_info_head; info; info = info->next) {
123+
while ((info = gcov_info_next(info))) {
124124
if (within(info, mod->module_core, mod->core_size)) {
125-
if (prev)
126-
prev->next = info->next;
127-
else
128-
gcov_info_head = info->next;
125+
gcov_info_unlink(prev, info);
129126
if (gcov_events_enabled)
130127
gcov_event(GCOV_REMOVE, info);
131128
} else
132129
prev = info;
133130
}
131+
134132
mutex_unlock(&gcov_lock);
135133

136134
return NOTIFY_OK;

‎kernel/gcov/fs.c‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static struct gcov_node *get_node_by_name(const char *name)
242242

243243
list_for_each_entry(node, &all_head, all) {
244244
info = get_node_info(node);
245-
if (info && (strcmp(info->filename, name) == 0))
245+
if (info && (strcmp(gcov_info_filename(info), name) == 0))
246246
return node;
247247
}
248248

@@ -279,7 +279,7 @@ static ssize_t gcov_seq_write(struct file *file, const char __user *addr,
279279
seq = file->private_data;
280280
info = gcov_iter_get_info(seq->private);
281281
mutex_lock(&node_lock);
282-
node = get_node_by_name(info->filename);
282+
node = get_node_by_name(gcov_info_filename(info));
283283
if (node) {
284284
/* Reset counts or remove node for unloaded modules. */
285285
if (node->num_loaded == 0)
@@ -376,8 +376,9 @@ static void add_links(struct gcov_node *node, struct dentry *parent)
376376
if (!node->links)
377377
return;
378378
for (i = 0; i < num; i++) {
379-
target = get_link_target(get_node_info(node)->filename,
380-
&gcov_link[i]);
379+
target = get_link_target(
380+
gcov_info_filename(get_node_info(node)),
381+
&gcov_link[i]);
381382
if (!target)
382383
goto out_err;
383384
basename = strrchr(target, '/');
@@ -576,7 +577,7 @@ static void add_node(struct gcov_info *info)
576577
struct gcov_node *parent;
577578
struct gcov_node *node;
578579

579-
filename = kstrdup(info->filename, GFP_KERNEL);
580+
filename = kstrdup(gcov_info_filename(info), GFP_KERNEL);
580581
if (!filename)
581582
return;
582583
parent = &root_node;
@@ -631,7 +632,7 @@ static void add_info(struct gcov_node *node, struct gcov_info *info)
631632
loaded_info = kcalloc(num + 1, sizeof(struct gcov_info *), GFP_KERNEL);
632633
if (!loaded_info) {
633634
pr_warning("could not add '%s' (out of memory)\n",
634-
info->filename);
635+
gcov_info_filename(info));
635636
return;
636637
}
637638
memcpy(loaded_info, node->loaded_info,
@@ -645,7 +646,8 @@ static void add_info(struct gcov_node *node, struct gcov_info *info)
645646
*/
646647
if (!gcov_info_is_compatible(node->unloaded_info, info)) {
647648
pr_warning("discarding saved data for %s "
648-
"(incompatible version)\n", info->filename);
649+
"(incompatible version)\n",
650+
gcov_info_filename(info));
649651
gcov_info_free(node->unloaded_info);
650652
node->unloaded_info = NULL;
651653
}
@@ -656,7 +658,7 @@ static void add_info(struct gcov_node *node, struct gcov_info *info)
656658
*/
657659
if (!gcov_info_is_compatible(node->loaded_info[0], info)) {
658660
pr_warning("could not add '%s' (incompatible "
659-
"version)\n", info->filename);
661+
"version)\n", gcov_info_filename(info));
660662
kfree(loaded_info);
661663
return;
662664
}
@@ -692,7 +694,8 @@ static void save_info(struct gcov_node *node, struct gcov_info *info)
692694
node->unloaded_info = gcov_info_dup(info);
693695
if (!node->unloaded_info) {
694696
pr_warning("could not save data for '%s' "
695-
"(out of memory)\n", info->filename);
697+
"(out of memory)\n",
698+
gcov_info_filename(info));
696699
}
697700
}
698701
}
@@ -708,7 +711,7 @@ static void remove_info(struct gcov_node *node, struct gcov_info *info)
708711
i = get_info_index(node, info);
709712
if (i < 0) {
710713
pr_warning("could not remove '%s' (not found)\n",
711-
info->filename);
714+
gcov_info_filename(info));
712715
return;
713716
}
714717
if (gcov_persist)
@@ -735,7 +738,7 @@ void gcov_event(enum gcov_action action, struct gcov_info *info)
735738
struct gcov_node *node;
736739

737740
mutex_lock(&node_lock);
738-
node = get_node_by_name(info->filename);
741+
node = get_node_by_name(gcov_info_filename(info));
739742
switch (action) {
740743
case GCOV_ADD:
741744
if (node)
@@ -748,7 +751,7 @@ void gcov_event(enum gcov_action action, struct gcov_info *info)
748751
remove_info(node, info);
749752
else {
750753
pr_warning("could not remove '%s' (not found)\n",
751-
info->filename);
754+
gcov_info_filename(info));
752755
}
753756
break;
754757
}

‎kernel/gcov/gcc_3_4.c‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,121 @@
2121
#include <linux/vmalloc.h>
2222
#include "gcov.h"
2323

24+
#define GCOV_COUNTERS 5
25+
26+
static struct gcov_info *gcov_info_head;
27+
28+
/**
29+
* struct gcov_fn_info - profiling meta data per function
30+
* @ident: object file-unique function identifier
31+
* @checksum: function checksum
32+
* @n_ctrs: number of values per counter type belonging to this function
33+
*
34+
* This data is generated by gcc during compilation and doesn't change
35+
* at run-time.
36+
*/
37+
struct gcov_fn_info {
38+
unsigned int ident;
39+
unsigned int checksum;
40+
unsigned int n_ctrs[0];
41+
};
42+
43+
/**
44+
* struct gcov_ctr_info - profiling data per counter type
45+
* @num: number of counter values for this type
46+
* @values: array of counter values for this type
47+
* @merge: merge function for counter values of this type (unused)
48+
*
49+
* This data is generated by gcc during compilation and doesn't change
50+
* at run-time with the exception of the values array.
51+
*/
52+
struct gcov_ctr_info {
53+
unsigned int num;
54+
gcov_type *values;
55+
void (*merge)(gcov_type *, unsigned int);
56+
};
57+
58+
/**
59+
* struct gcov_info - profiling data per object file
60+
* @version: gcov version magic indicating the gcc version used for compilation
61+
* @next: list head for a singly-linked list
62+
* @stamp: time stamp
63+
* @filename: name of the associated gcov data file
64+
* @n_functions: number of instrumented functions
65+
* @functions: function data
66+
* @ctr_mask: mask specifying which counter types are active
67+
* @counts: counter data per counter type
68+
*
69+
* This data is generated by gcc during compilation and doesn't change
70+
* at run-time with the exception of the next pointer.
71+
*/
72+
struct gcov_info {
73+
unsigned int version;
74+
struct gcov_info *next;
75+
unsigned int stamp;
76+
const char *filename;
77+
unsigned int n_functions;
78+
const struct gcov_fn_info *functions;
79+
unsigned int ctr_mask;
80+
struct gcov_ctr_info counts[0];
81+
};
82+
83+
/**
84+
* gcov_info_filename - return info filename
85+
* @info: profiling data set
86+
*/
87+
const char *gcov_info_filename(struct gcov_info *info)
88+
{
89+
return info->filename;
90+
}
91+
92+
/**
93+
* gcov_info_version - return info version
94+
* @info: profiling data set
95+
*/
96+
unsigned int gcov_info_version(struct gcov_info *info)
97+
{
98+
return info->version;
99+
}
100+
101+
/**
102+
* gcov_info_next - return next profiling data set
103+
* @info: profiling data set
104+
*
105+
* Returns next gcov_info following @info or first gcov_info in the chain if
106+
* @info is %NULL.
107+
*/
108+
struct gcov_info *gcov_info_next(struct gcov_info *info)
109+
{
110+
if (!info)
111+
return gcov_info_head;
112+
113+
return info->next;
114+
}
115+
116+
/**
117+
* gcov_info_link - link/add profiling data set to the list
118+
* @info: profiling data set
119+
*/
120+
void gcov_info_link(struct gcov_info *info)
121+
{
122+
info->next = gcov_info_head;
123+
gcov_info_head = info;
124+
}
125+
126+
/**
127+
* gcov_info_unlink - unlink/remove profiling data set from the list
128+
* @prev: previous profiling data set
129+
* @info: profiling data set
130+
*/
131+
void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info)
132+
{
133+
if (prev)
134+
prev->next = info->next;
135+
else
136+
gcov_info_head = info->next;
137+
}
138+
24139
/* Symbolic links to be created for each profiling data file. */
25140
const struct gcov_link gcov_link[] = {
26141
{ OBJ_TREE, "gcno" }, /* Link to .gcno file in $(objtree). */

‎kernel/gcov/gcov.h‎

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
* gcc and need to be kept as close to the original definition as possible to
2222
* remain compatible.
2323
*/
24-
#define GCOV_COUNTERS 5
2524
#define GCOV_DATA_MAGIC ((unsigned int) 0x67636461)
2625
#define GCOV_TAG_FUNCTION ((unsigned int) 0x01000000)
2726
#define GCOV_TAG_COUNTER_BASE ((unsigned int) 0x01a10000)
@@ -34,60 +33,18 @@ typedef long gcov_type;
3433
typedef long long gcov_type;
3534
#endif
3635

37-
/**
38-
* struct gcov_fn_info - profiling meta data per function
39-
* @ident: object file-unique function identifier
40-
* @checksum: function checksum
41-
* @n_ctrs: number of values per counter type belonging to this function
42-
*
43-
* This data is generated by gcc during compilation and doesn't change
44-
* at run-time.
45-
*/
46-
struct gcov_fn_info {
47-
unsigned int ident;
48-
unsigned int checksum;
49-
unsigned int n_ctrs[0];
50-
};
51-
52-
/**
53-
* struct gcov_ctr_info - profiling data per counter type
54-
* @num: number of counter values for this type
55-
* @values: array of counter values for this type
56-
* @merge: merge function for counter values of this type (unused)
57-
*
58-
* This data is generated by gcc during compilation and doesn't change
59-
* at run-time with the exception of the values array.
60-
*/
61-
struct gcov_ctr_info {
62-
unsigned int num;
63-
gcov_type *values;
64-
void (*merge)(gcov_type *, unsigned int);
65-
};
36+
/* Opaque gcov_info. The gcov structures can change as for example in gcc 4.7 so
37+
* we cannot use full definition here and they need to be placed in gcc specific
38+
* implementation of gcov. This also means no direct access to the members in
39+
* generic code and usage of the interface below.*/
40+
struct gcov_info;
6641

67-
/**
68-
* struct gcov_info - profiling data per object file
69-
* @version: gcov version magic indicating the gcc version used for compilation
70-
* @next: list head for a singly-linked list
71-
* @stamp: time stamp
72-
* @filename: name of the associated gcov data file
73-
* @n_functions: number of instrumented functions
74-
* @functions: function data
75-
* @ctr_mask: mask specifying which counter types are active
76-
* @counts: counter data per counter type
77-
*
78-
* This data is generated by gcc during compilation and doesn't change
79-
* at run-time with the exception of the next pointer.
80-
*/
81-
struct gcov_info {
82-
unsigned int version;
83-
struct gcov_info *next;
84-
unsigned int stamp;
85-
const char *filename;
86-
unsigned int n_functions;
87-
const struct gcov_fn_info *functions;
88-
unsigned int ctr_mask;
89-
struct gcov_ctr_info counts[0];
90-
};
42+
/* Interface to access gcov_info data */
43+
const char *gcov_info_filename(struct gcov_info *info);
44+
unsigned int gcov_info_version(struct gcov_info *info);
45+
struct gcov_info *gcov_info_next(struct gcov_info *info);
46+
void gcov_info_link(struct gcov_info *info);
47+
void gcov_info_unlink(struct gcov_info *prev, struct gcov_info *info);
9148

9249
/* Base interface. */
9350
enum gcov_action {

0 commit comments

Comments
 (0)