diff options
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index b1f3ab4b39b3..da942ab2f06a 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
@@ -1113,7 +1113,7 @@ static void bpf_object__sanitize_btf_ext(struct bpf_object *obj) | |||
1113 | } | 1113 | } |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | static int bpf_object__load_btf(struct bpf_object *obj, | 1116 | static int bpf_object__init_btf(struct bpf_object *obj, |
1117 | Elf_Data *btf_data, | 1117 | Elf_Data *btf_data, |
1118 | Elf_Data *btf_ext_data) | 1118 | Elf_Data *btf_ext_data) |
1119 | { | 1119 | { |
@@ -1132,13 +1132,6 @@ static int bpf_object__load_btf(struct bpf_object *obj, | |||
1132 | BTF_ELF_SEC, err); | 1132 | BTF_ELF_SEC, err); |
1133 | goto out; | 1133 | goto out; |
1134 | } | 1134 | } |
1135 | bpf_object__sanitize_btf(obj); | ||
1136 | err = btf__load(obj->btf); | ||
1137 | if (err) { | ||
1138 | pr_warning("Error loading %s into kernel: %d.\n", | ||
1139 | BTF_ELF_SEC, err); | ||
1140 | goto out; | ||
1141 | } | ||
1142 | } | 1135 | } |
1143 | if (btf_ext_data) { | 1136 | if (btf_ext_data) { |
1144 | if (!obj->btf) { | 1137 | if (!obj->btf) { |
@@ -1154,7 +1147,6 @@ static int bpf_object__load_btf(struct bpf_object *obj, | |||
1154 | obj->btf_ext = NULL; | 1147 | obj->btf_ext = NULL; |
1155 | goto out; | 1148 | goto out; |
1156 | } | 1149 | } |
1157 | bpf_object__sanitize_btf_ext(obj); | ||
1158 | } | 1150 | } |
1159 | out: | 1151 | out: |
1160 | if (err || IS_ERR(obj->btf)) { | 1152 | if (err || IS_ERR(obj->btf)) { |
@@ -1165,6 +1157,26 @@ out: | |||
1165 | return 0; | 1157 | return 0; |
1166 | } | 1158 | } |
1167 | 1159 | ||
1160 | static int bpf_object__sanitize_and_load_btf(struct bpf_object *obj) | ||
1161 | { | ||
1162 | int err = 0; | ||
1163 | |||
1164 | if (!obj->btf) | ||
1165 | return 0; | ||
1166 | |||
1167 | bpf_object__sanitize_btf(obj); | ||
1168 | bpf_object__sanitize_btf_ext(obj); | ||
1169 | |||
1170 | err = btf__load(obj->btf); | ||
1171 | if (err) { | ||
1172 | pr_warning("Error loading %s into kernel: %d.\n", | ||
1173 | BTF_ELF_SEC, err); | ||
1174 | btf__free(obj->btf); | ||
1175 | obj->btf = NULL; | ||
1176 | } | ||
1177 | return 0; | ||
1178 | } | ||
1179 | |||
1168 | static int bpf_object__elf_collect(struct bpf_object *obj, int flags) | 1180 | static int bpf_object__elf_collect(struct bpf_object *obj, int flags) |
1169 | { | 1181 | { |
1170 | Elf *elf = obj->efile.elf; | 1182 | Elf *elf = obj->efile.elf; |
@@ -1296,10 +1308,12 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags) | |||
1296 | pr_warning("Corrupted ELF file: index of strtab invalid\n"); | 1308 | pr_warning("Corrupted ELF file: index of strtab invalid\n"); |
1297 | return -LIBBPF_ERRNO__FORMAT; | 1309 | return -LIBBPF_ERRNO__FORMAT; |
1298 | } | 1310 | } |
1299 | err = bpf_object__load_btf(obj, btf_data, btf_ext_data); | 1311 | err = bpf_object__init_btf(obj, btf_data, btf_ext_data); |
1300 | if (!err) | 1312 | if (!err) |
1301 | err = bpf_object__init_maps(obj, flags); | 1313 | err = bpf_object__init_maps(obj, flags); |
1302 | if (!err) | 1314 | if (!err) |
1315 | err = bpf_object__sanitize_and_load_btf(obj); | ||
1316 | if (!err) | ||
1303 | err = bpf_object__init_prog_names(obj); | 1317 | err = bpf_object__init_prog_names(obj); |
1304 | return err; | 1318 | return err; |
1305 | } | 1319 | } |