@@ -37,7 +37,6 @@ struct elf_function {
bool generated;
};
-#define MAX_VAR_CNT 4096
#define MAX_ELF_SEC_CNT 128
struct var_info {
@@ -75,8 +74,9 @@ struct btf_encoder {
struct elf_secinfo secinfo[MAX_ELF_SEC_CNT];
size_t seccnt;
struct {
- struct var_info vars[MAX_VAR_CNT];
+ struct var_info *vars;
int var_cnt;
+ int var_alloc;
uint32_t percpu_shndx;
} variables;
struct {
@@ -1206,6 +1206,15 @@ static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym
if (elf_sym__type(sym) != STT_OBJECT)
return 0;
+ if (encoder->variables.var_cnt == encoder->variables.var_alloc) {
+ struct var_info *new;
+ encoder->variables.var_alloc = max(1000, encoder->variables.var_alloc * 3 / 2);
+ new = realloc(encoder->variables.vars, encoder->variables.var_alloc * sizeof(*new));
+ if (!new)
+ return -1;
+ encoder->variables.vars = new;
+ }
+
addr = elf_sym__value(sym);
size = elf_sym__size(sym);
@@ -1232,11 +1241,6 @@ static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym
addr += encoder->secinfo[sym->st_shndx].addr;
}
- if (encoder->variables.var_cnt == MAX_VAR_CNT) {
- fprintf(stderr, "Reached the limit of per-CPU variables: %d\n",
- MAX_VAR_CNT);
- return -1;
- }
encoder->variables.vars[encoder->variables.var_cnt].addr = addr;
encoder->variables.vars[encoder->variables.var_cnt].sz = size;
encoder->variables.vars[encoder->variables.var_cnt].name = sym_name;
@@ -1520,6 +1524,10 @@ void btf_encoder__delete(struct btf_encoder *encoder)
encoder->btf = NULL;
elf_symtab__delete(encoder->symtab);
+ encoder->variables.var_cnt = encoder->variables.var_alloc = 0;
+ free(encoder->variables.vars);
+ encoder->variables.vars = NULL;
+
encoder->functions.allocated = encoder->functions.cnt = 0;
free(encoder->functions.entries);
encoder->functions.entries = NULL;
To collect all variables, we need a dynamically allocated array to scale with any amount. Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com> --- btf_encoder.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)