|
|
7e752c |
From 9783e8b3de077c2e6399a9aa83f93237690bd744 Mon Sep 17 00:00:00 2001
|
|
|
7e752c |
From: Andrea Claudi <aclaudi@redhat.com>
|
|
|
7e752c |
Date: Thu, 13 Jun 2019 14:37:57 +0200
|
|
|
7e752c |
Subject: [PATCH] bpf: check map symbol type properly with newer llvm compiler
|
|
|
7e752c |
|
|
|
7e752c |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1716361
|
|
|
7e752c |
Upstream Status: iproute2.git commit 7a04dd84a7f93
|
|
|
7e752c |
|
|
|
7e752c |
commit 7a04dd84a7f938f72fcef9efe8383314b0a66274
|
|
|
7e752c |
Author: Yonghong Song <yhs@fb.com>
|
|
|
7e752c |
Date: Mon Oct 29 15:32:03 2018 -0700
|
|
|
7e752c |
|
|
|
7e752c |
bpf: check map symbol type properly with newer llvm compiler
|
|
|
7e752c |
|
|
|
7e752c |
With llvm 7.0 or earlier, the map symbol type is STT_NOTYPE.
|
|
|
7e752c |
-bash-4.4$ cat t.c
|
|
|
7e752c |
__attribute__((section("maps"))) int g;
|
|
|
7e752c |
-bash-4.4$ clang -target bpf -O2 -c t.c
|
|
|
7e752c |
-bash-4.4$ readelf -s t.o
|
|
|
7e752c |
|
|
|
7e752c |
Symbol table '.symtab' contains 2 entries:
|
|
|
7e752c |
Num: Value Size Type Bind Vis Ndx Name
|
|
|
7e752c |
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
|
|
|
7e752c |
1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 3 g
|
|
|
7e752c |
|
|
|
7e752c |
The following llvm commit enables BPF target to generate
|
|
|
7e752c |
proper symbol type and size.
|
|
|
7e752c |
commit bf6ec206615b9718869d48b4e5400d0c6e3638dd
|
|
|
7e752c |
Author: Yonghong Song <yhs@fb.com>
|
|
|
7e752c |
Date: Wed Sep 19 16:04:13 2018 +0000
|
|
|
7e752c |
|
|
|
7e752c |
[bpf] Symbol sizes and types in object file
|
|
|
7e752c |
|
|
|
7e752c |
Clang-compiled object files currently don't include the symbol sizes and
|
|
|
7e752c |
types. Some tools however need that information. For example, ctfconvert
|
|
|
7e752c |
uses that information to generate FreeBSD's CTF representation from ELF
|
|
|
7e752c |
files.
|
|
|
7e752c |
With this patch, symbol sizes and types are included in object files.
|
|
|
7e752c |
|
|
|
7e752c |
Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
|
|
|
7e752c |
Reported-by: Yutaro Hayakawa <yhayakawa3720@gmail.com>
|
|
|
7e752c |
|
|
|
7e752c |
Hence, for llvm 8.0.0 (currently trunk), symbol type will be not NOTYPE, but OBJECT.
|
|
|
7e752c |
-bash-4.4$ clang -target bpf -O2 -c t.c
|
|
|
7e752c |
-bash-4.4$ readelf -s t.o
|
|
|
7e752c |
|
|
|
7e752c |
Symbol table '.symtab' contains 3 entries:
|
|
|
7e752c |
Num: Value Size Type Bind Vis Ndx Name
|
|
|
7e752c |
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
|
|
|
7e752c |
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS t.c
|
|
|
7e752c |
2: 0000000000000000 4 OBJECT GLOBAL DEFAULT 3 g
|
|
|
7e752c |
|
|
|
7e752c |
This patch makes sure bpf library accepts both NOTYPE and OBJECT types
|
|
|
7e752c |
of global map symbols.
|
|
|
7e752c |
|
|
|
7e752c |
Signed-off-by: Yonghong Song <yhs@fb.com>
|
|
|
7e752c |
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
|
|
|
7e752c |
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
|
|
|
7e752c |
---
|
|
|
7e752c |
lib/bpf.c | 12 +++++++++---
|
|
|
7e752c |
1 file changed, 9 insertions(+), 3 deletions(-)
|
|
|
7e752c |
|
|
|
7e752c |
diff --git a/lib/bpf.c b/lib/bpf.c
|
|
|
7e752c |
index d093d0bd86eae..45f279fa4a416 100644
|
|
|
7e752c |
--- a/lib/bpf.c
|
|
|
7e752c |
+++ b/lib/bpf.c
|
|
|
7e752c |
@@ -1758,11 +1758,13 @@ static const char *bpf_map_fetch_name(struct bpf_elf_ctx *ctx, int which)
|
|
|
7e752c |
int i;
|
|
|
7e752c |
|
|
|
7e752c |
for (i = 0; i < ctx->sym_num; i++) {
|
|
|
7e752c |
+ int type = GELF_ST_TYPE(sym.st_info);
|
|
|
7e752c |
+
|
|
|
7e752c |
if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym)
|
|
|
7e752c |
continue;
|
|
|
7e752c |
|
|
|
7e752c |
if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL ||
|
|
|
7e752c |
- GELF_ST_TYPE(sym.st_info) != STT_NOTYPE ||
|
|
|
7e752c |
+ (type != STT_NOTYPE && type != STT_OBJECT) ||
|
|
|
7e752c |
sym.st_shndx != ctx->sec_maps ||
|
|
|
7e752c |
sym.st_value / ctx->map_len != which)
|
|
|
7e752c |
continue;
|
|
|
7e752c |
@@ -1849,11 +1851,13 @@ static int bpf_map_num_sym(struct bpf_elf_ctx *ctx)
|
|
|
7e752c |
GElf_Sym sym;
|
|
|
7e752c |
|
|
|
7e752c |
for (i = 0; i < ctx->sym_num; i++) {
|
|
|
7e752c |
+ int type = GELF_ST_TYPE(sym.st_info);
|
|
|
7e752c |
+
|
|
|
7e752c |
if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym)
|
|
|
7e752c |
continue;
|
|
|
7e752c |
|
|
|
7e752c |
if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL ||
|
|
|
7e752c |
- GELF_ST_TYPE(sym.st_info) != STT_NOTYPE ||
|
|
|
7e752c |
+ (type != STT_NOTYPE && type != STT_OBJECT) ||
|
|
|
7e752c |
sym.st_shndx != ctx->sec_maps)
|
|
|
7e752c |
continue;
|
|
|
7e752c |
num++;
|
|
|
7e752c |
@@ -1927,10 +1931,12 @@ static int bpf_map_verify_all_offs(struct bpf_elf_ctx *ctx, int end)
|
|
|
7e752c |
* the table again.
|
|
|
7e752c |
*/
|
|
|
7e752c |
for (i = 0; i < ctx->sym_num; i++) {
|
|
|
7e752c |
+ int type = GELF_ST_TYPE(sym.st_info);
|
|
|
7e752c |
+
|
|
|
7e752c |
if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym)
|
|
|
7e752c |
continue;
|
|
|
7e752c |
if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL ||
|
|
|
7e752c |
- GELF_ST_TYPE(sym.st_info) != STT_NOTYPE ||
|
|
|
7e752c |
+ (type != STT_NOTYPE && type != STT_OBJECT) ||
|
|
|
7e752c |
sym.st_shndx != ctx->sec_maps)
|
|
|
7e752c |
continue;
|
|
|
7e752c |
if (sym.st_value == off)
|
|
|
7e752c |
--
|
|
|
7e752c |
2.20.1
|
|
|
7e752c |
|