Skip to content

Commit 17b1f0d

Browse files
vapiersravnborg
authored andcommitted
kallsyms: generalize text region handling
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
1 parent 028f042 commit 17b1f0d

1 file changed

Lines changed: 61 additions & 26 deletions

File tree

‎scripts/kallsyms.c‎

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include <string.h>
2424
#include <ctype.h>
2525

26+
#ifndef ARRAY_SIZE
27+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
28+
#endif
29+
2630
#define KSYM_NAME_LEN 128
2731

2832
struct sym_entry {
@@ -32,10 +36,23 @@ struct sym_entry {
3236
unsigned char *sym;
3337
};
3438

39+
struct text_range {
40+
const char *stext, *etext;
41+
unsigned long long start, end;
42+
};
43+
44+
static unsigned long long _text;
45+
static struct text_range text_ranges[] = {
46+
{ "_stext", "_etext" },
47+
{ "_sinittext", "_einittext" },
48+
{ "_stext_l1", "_etext_l1" }, /* Blackfin on-chip L1 inst SRAM */
49+
{ "_stext_l2", "_etext_l2" }, /* Blackfin on-chip L2 SRAM */
50+
};
51+
#define text_range_text (&text_ranges[0])
52+
#define text_range_inittext (&text_ranges[1])
53+
3554
static struct sym_entry *table;
3655
static unsigned int table_size, table_cnt;
37-
static unsigned long long _text, _stext, _etext, _sinittext, _einittext;
38-
static unsigned long long _stext_l1, _etext_l1, _stext_l2, _etext_l2;
3956
static int all_symbols = 0;
4057
static char symbol_prefix_char = '\0';
4158

@@ -62,6 +79,26 @@ static inline int is_arm_mapping_symbol(const char *str)
6279
&& (str[2] == '\0' || str[2] == '.');
6380
}
6481

82+
static int read_symbol_tr(const char *sym, unsigned long long addr)
83+
{
84+
size_t i;
85+
struct text_range *tr;
86+
87+
for (i = 0; i < ARRAY_SIZE(text_ranges); ++i) {
88+
tr = &text_ranges[i];
89+
90+
if (strcmp(sym, tr->stext) == 0) {
91+
tr->start = addr;
92+
return 0;
93+
} else if (strcmp(sym, tr->etext) == 0) {
94+
tr->end = addr;
95+
return 0;
96+
}
97+
}
98+
99+
return 1;
100+
}
101+
65102
static int read_symbol(FILE *in, struct sym_entry *s)
66103
{
67104
char str[500];
@@ -85,22 +122,8 @@ static int read_symbol(FILE *in, struct sym_entry *s)
85122
/* Ignore most absolute/undefined (?) symbols. */
86123
if (strcmp(sym, "_text") == 0)
87124
_text = s->addr;
88-
else if (strcmp(sym, "_stext") == 0)
89-
_stext = s->addr;
90-
else if (strcmp(sym, "_etext") == 0)
91-
_etext = s->addr;
92-
else if (strcmp(sym, "_sinittext") == 0)
93-
_sinittext = s->addr;
94-
else if (strcmp(sym, "_einittext") == 0)
95-
_einittext = s->addr;
96-
else if (strcmp(sym, "_stext_l1") == 0)
97-
_stext_l1 = s->addr;
98-
else if (strcmp(sym, "_etext_l1") == 0)
99-
_etext_l1 = s->addr;
100-
else if (strcmp(sym, "_stext_l2") == 0)
101-
_stext_l2 = s->addr;
102-
else if (strcmp(sym, "_etext_l2") == 0)
103-
_etext_l2 = s->addr;
125+
else if (read_symbol_tr(sym, s->addr) == 0)
126+
/* nothing to do */;
104127
else if (toupper(stype) == 'A')
105128
{
106129
/* Keep these useful absolute symbols */
@@ -136,6 +159,21 @@ static int read_symbol(FILE *in, struct sym_entry *s)
136159
return 0;
137160
}
138161

162+
static int symbol_valid_tr(struct sym_entry *s)
163+
{
164+
size_t i;
165+
struct text_range *tr;
166+
167+
for (i = 0; i < ARRAY_SIZE(text_ranges); ++i) {
168+
tr = &text_ranges[i];
169+
170+
if (s->addr >= tr->start && s->addr < tr->end)
171+
return 0;
172+
}
173+
174+
return 1;
175+
}
176+
139177
static int symbol_valid(struct sym_entry *s)
140178
{
141179
/* Symbols which vary between passes. Passes 1 and 2 must have
@@ -165,21 +203,18 @@ static int symbol_valid(struct sym_entry *s)
165203
/* if --all-symbols is not specified, then symbols outside the text
166204
* and inittext sections are discarded */
167205
if (!all_symbols) {
168-
if ((s->addr < _stext || s->addr > _etext)
169-
&& (s->addr < _sinittext || s->addr > _einittext)
170-
&& (s->addr < _stext_l1 || s->addr > _etext_l1)
171-
&& (s->addr < _stext_l2 || s->addr > _etext_l2))
206+
if (symbol_valid_tr(s) == 0)
172207
return 0;
173208
/* Corner case. Discard any symbols with the same value as
174209
* _etext _einittext; they can move between pass 1 and 2 when
175210
* the kallsyms data are added. If these symbols move then
176211
* they may get dropped in pass 2, which breaks the kallsyms
177212
* rules.
178213
*/
179-
if ((s->addr == _etext &&
180-
strcmp((char *)s->sym + offset, "_etext")) ||
181-
(s->addr == _einittext &&
182-
strcmp((char *)s->sym + offset, "_einittext")))
214+
if ((s->addr == text_range_text->end &&
215+
strcmp((char *)s->sym + offset, text_range_text->etext)) ||
216+
(s->addr == text_range_inittext->end &&
217+
strcmp((char *)s->sym + offset, text_range_inittext->etext)))
183218
return 0;
184219
}
185220

0 commit comments

Comments
 (0)