perf build: Build error in libbpf with EXTRA_CFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -O2"
PATCH 1/1 perf build: Build error in libbpf with EXTRA_CFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -O2"
commit a5b8bd47dcc57 ("bpf tools: Collect eBPF programs from their own sections")
cause a compiler error when building the perf tool in the linux-next tree. I compile it using a FEDORA 28 installation, my gcc compiler version:
gcc (GCC) 8.0.1 20180324 (Red Hat 8.0.1-0.20)
Here is the error message:
[root@p23lp27] # make V=1 EXTRA_CFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -O2" [...]
make -f /home6/tmricht/linux-next/tools/build/Makefile.build
dir=./util/scripting-engines obj=libperflibbpf.c: In function ‘bpf_object__elf_collect’:
libbpf.c:811:15: error: ignoring return value of ‘strerror_r’,
declared with attribute warn_unused_result [-Werror=unused-result]
strerror_r(-err, errmsg, sizeof(errmsg));
^cc1: all warnings being treated as errors
mv: cannot stat './.libbpf.o.tmp': No such file or directory /home6/tmricht/linux-next/tools/build/Makefile.build:96: recipe for target 'libbpf.o' failed
Fix this by using strerror_r return value in pr_warning statement. Also fixes a possible initialization issue.
--- tools/lib/bpf/libbpf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/lib/bpf/libbpf.c +3 -3
@@ -808,9 +808,9 @@ static int bpf_object__elf_collect(struct bpf_object *obj)if (err) {char errmsg[STRERR_BUFSIZE ]; -strerror_r (-err, errmsg,sizeof (errmsg));pr_warning ("failed to alloc program %s (%s): %s" , - name, obj->path, errmsg); + name, obj->path, +strerror_r (-err, errmsg,sizeof (errmsg))); } }else if (sh.sh_type ==SHT_REL ) {void *reloc = obj->efile.reloc;
@@ -2334,7 +2334,7 @@ bpf_perf_event_read_simple(void *mem, unsigned long size,__u64 data_tail = header->data_tail;__u64 data_head = header->data_head;void *base, *begin, *end; -int ret; +int ret =0 ; asmvolatile ("" :::"memory" );/* in real code it should be smp_rmb() */ if (data_head == data_tail)
Signature · 1 line
2.16.4