Skip to contentSkip to conversation

btf_encoder: ignore zero-sized ELF symbols

PATCH Applied Andrii Nakryiko 3 participants 3 messages Oct 21, 2020 – Oct 23, 2020 BPF

lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 btf_encoder: ignore zero-sized ELF symbols

It's legal for ELF symbol to have size 0, if it's size is unknown or unspecified. Instead of erroring out, just ignore such symbols, as they can't be a valid per-CPU variable anyways.

---
 btf_encoder.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
btf_encoder.c +4 -8
index 2a6455be4c52..2af1fe447834 100644
@@ -287,6 +287,10 @@ static int find_all_percpu_vars(struct btf_elf *btfe)
 		if (!addr)
 			continue;
 
+		size = elf_sym__size(&sym);
+		if (!size)
+			continue; /* ignore zero-sized symbols */
+
 		sym_name = elf_sym__name(&sym, btfe->symtab);
 		if (!btf_name_valid(sym_name)) {
 			dump_invalid_symbol("Found symbol of invalid name when encoding btf",
@@ -295,14 +299,6 @@ static int find_all_percpu_vars(struct btf_elf *btfe)
 				continue;
 			return -1;
 		}
-		size = elf_sym__size(&sym);
-		if (!size) {
-			dump_invalid_symbol("Found symbol of zero size when encoding btf",
-					    sym_name, btf_elf__verbose, btf_elf__force);
-			if (btf_elf__force)
-				continue;
-			return -1;
-		}
 
 		if (btf_elf__verbose)
 			printf("Found per-CPU symbol '%s' at address 0x%lx\n", sym_name, addr);
Signature · 1 line
2.24.1
Tested-by on v1 1/1
#1 lore raw
Quoted 5 lines · Andrii Nakryiko

It's legal for ELF symbol to have size 0, if it's size is unknown or unspecified. Instead of erroring out, just ignore such symbols, as they can't be a valid per-CPU variable anyways.

Quoted 35 lines
---
  btf_encoder.c | 12 ++++--------
  1 file changed, 4 insertions(+), 8 deletions(-)
btf_encoder.c +4 -8
index 2a6455be4c52..2af1fe447834 100644
@@ -287,6 +287,10 @@ static int find_all_percpu_vars(struct btf_elf *btfe)
  		if (!addr)
  			continue;
 
+		size = elf_sym__size(&sym);
+		if (!size)
+			continue; /* ignore zero-sized symbols */
+
  		sym_name = elf_sym__name(&sym, btfe->symtab);
  		if (!btf_name_valid(sym_name)) {
  			dump_invalid_symbol("Found symbol of invalid name when encoding btf",
@@ -295,14 +299,6 @@ static int find_all_percpu_vars(struct btf_elf *btfe)
  				continue;
  			return -1;
  		}
-		size = elf_sym__size(&sym);
-		if (!size) {
-			dump_invalid_symbol("Found symbol of zero size when encoding btf",
-					    sym_name, btf_elf__verbose, btf_elf__force);
-			if (btf_elf__force)
-				continue;
-			return -1;
-		}
 
  		if (btf_elf__verbose)
  			printf("Found per-CPU symbol '%s' at address 0x%lx\n", sym_name, addr);
Signature · 2 lines
js
suse labs
#2 lore raw

Em Thu, Oct 22, 2020 at 07:19:32AM +0200, Jiri Slaby escreveu:

Quoted 8 lines · Andrii Nakryiko
Quoted 5 lines

It's legal for ELF symbol to have size 0, if it's size is unknown or unspecified. Instead of erroring out, just ignore such symbols, as they can't be a valid per-CPU variable anyways.

thanks applied

Quoted 38 lines
Quoted 33 lines
---
  btf_encoder.c | 12 ++++--------
  1 file changed, 4 insertions(+), 8 deletions(-)
btf_encoder.c +4 -8
index 2a6455be4c52..2af1fe447834 100644
@@ -287,6 +287,10 @@ static int find_all_percpu_vars(struct btf_elf *btfe)
  		if (!addr)
  			continue;
+		size = elf_sym__size(&sym);
+		if (!size)
+			continue; /* ignore zero-sized symbols */
+
  		sym_name = elf_sym__name(&sym, btfe->symtab);
  		if (!btf_name_valid(sym_name)) {
  			dump_invalid_symbol("Found symbol of invalid name when encoding btf",
@@ -295,14 +299,6 @@ static int find_all_percpu_vars(struct btf_elf *btfe)
  				continue;
  			return -1;
  		}
-		size = elf_sym__size(&sym);
-		if (!size) {
-			dump_invalid_symbol("Found symbol of zero size when encoding btf",
-					    sym_name, btf_elf__verbose, btf_elf__force);
-			if (btf_elf__force)
-				continue;
-			return -1;
-		}
  		if (btf_elf__verbose)
  			printf("Found per-CPU symbol '%s' at address 0x%lx\n", sym_name, addr);
 
Signature · 2 lines
js
suse labs
Signature · 1 line
- Arnaldo