From 1ef87b26fd268b529b3568f3625d9eb10753a1a8 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Wed, 16 Jun 2021 21:07:22 -0300 Subject: [PATCH] Revert "btf_encoder: Reduce the size of encode_cu() by moving function encoding to separate method" This reverts commit de3a7f912559433c271e66db2a5510cf1caf93b0. Andrii reports that this cset is breaking the CI, as reported at: https://travis-ci.com/github/libbpf/libbpf/jobs/514329152 So revert it while investigation about the root cause continues. Reported-by: Andrii Nakryiko Signed-off-by: Arnaldo Carvalho de Melo --- btf_encoder.c | 94 +++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 639518a..1b0e583 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -1140,55 +1140,6 @@ static bool has_arg_names(struct cu *cu, struct ftype *ftype) return true; } -static int btf_encoder__encode_cu_functions(struct btf_encoder *encoder, struct cu *cu, uint32_t type_id_off) -{ - struct function *fn; - uint32_t core_id; - - cu__for_each_function(cu, core_id, fn) { - int btf_fnproto_id, btf_fn_id; - const char *name; - - /* - * Skip functions that: - * - are marked as declarations - * - do not have full argument names - * - are not in ftrace list (if it's available) - * - are not external (in case ftrace filter is not available) - */ - if (fn->declaration) - continue; - if (!has_arg_names(cu, &fn->proto)) - continue; - if (encoder->functions.cnt) { - struct elf_function *func; - const char *name; - - name = function__name(fn, cu); - if (!name) - continue; - - func = btf_encoder__find_function(encoder, name); - if (!func || func->generated) - continue; - func->generated = true; - } else { - if (!fn->external) - continue; - } - - btf_fnproto_id = btf_encoder__add_func_proto(encoder, cu, &fn->proto, type_id_off); - name = dwarves__active_loader->strings__ptr(cu, fn->name); - btf_fn_id = btf_encoder__add_ref_type(encoder, BTF_KIND_FUNC, btf_fnproto_id, name, false); - if (btf_fnproto_id < 0 || btf_fn_id < 0) { - printf("error: failed to encode function '%s'\n", function__name(fn, cu)); - return -1; - } - } - - return 0; -} - static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder, struct cu *cu, uint32_t type_id_off) { uint32_t core_id; @@ -1405,6 +1356,7 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu) { uint32_t type_id_off = btf__get_nr_types(encoder->btf); uint32_t core_id; + struct function *fn; struct tag *pos; int err = 0; @@ -1440,9 +1392,49 @@ int btf_encoder__encode_cu(struct btf_encoder *encoder, struct cu *cu) encoder->has_index_type = true; } - err = btf_encoder__encode_cu_functions(encoder, cu, type_id_off); + cu__for_each_function(cu, core_id, fn) { + int btf_fnproto_id, btf_fn_id; + const char *name; - if (err != 0 && !encoder->skip_encoding_vars) + /* + * Skip functions that: + * - are marked as declarations + * - do not have full argument names + * - are not in ftrace list (if it's available) + * - are not external (in case ftrace filter is not available) + */ + if (fn->declaration) + continue; + if (!has_arg_names(cu, &fn->proto)) + continue; + if (encoder->functions.cnt) { + struct elf_function *func; + const char *name; + + name = function__name(fn, cu); + if (!name) + continue; + + func = btf_encoder__find_function(encoder, name); + if (!func || func->generated) + continue; + func->generated = true; + } else { + if (!fn->external) + continue; + } + + btf_fnproto_id = btf_encoder__add_func_proto(encoder, cu, &fn->proto, type_id_off); + name = dwarves__active_loader->strings__ptr(cu, fn->name); + btf_fn_id = btf_encoder__add_ref_type(encoder, BTF_KIND_FUNC, btf_fnproto_id, name, false); + if (btf_fnproto_id < 0 || btf_fn_id < 0) { + err = -1; + printf("error: failed to encode function '%s'\n", function__name(fn, cu)); + goto out; + } + } + + if (!encoder->skip_encoding_vars) err = btf_encoder__encode_cu_variables(encoder, cu, type_id_off); out: return err;