Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753516AbbFCVwy (ORCPT ); Wed, 3 Jun 2015 17:52:54 -0400 Received: from mail.kernel.org ([198.145.29.136]:58086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751298AbbFCVwp (ORCPT ); Wed, 3 Jun 2015 17:52:45 -0400 Date: Wed, 3 Jun 2015 18:52:40 -0300 From: Arnaldo Carvalho de Melo To: Wang Nan Cc: namhyung@kernel.org, alexei.starovoitov@gmail.com, masami.hiramatsu.pt@hitachi.com, paulus@samba.org, a.p.zijlstra@chello.nl, mingo@redhat.com, jolsa@kernel.org, dsahern@gmail.com, daniel@iogearbox.net, brendan.d.gregg@gmail.com, lizefan@huawei.com, hekuang@huawei.com, xiakaixu@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com Subject: Re: [RFC PATCH v5 07/30] bpf tools: Check endianess and make libbpf fail early Message-ID: <20150603215240.GE32707@kernel.org> References: <1433144296-74992-1-git-send-email-wangnan0@huawei.com> <1433144296-74992-8-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1433144296-74992-8-git-send-email-wangnan0@huawei.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2707 Lines: 93 Em Mon, Jun 01, 2015 at 07:37:53AM +0000, Wang Nan escreveu: > Check endianess according to EHDR. Code is taken from > tools/perf/util/symbol-elf.c. > > Libbpf doesn't magically convert missmatched endianess. See discussion > on https://lkml.org/lkml/2015/5/18/650 that, even if we swap Please don't use URLs like this, I tried accessing this link and it seems lkml.org is not accessible now :-\ Simply avoid having URLs like this, but if you insist, then follow the Link: standard and use: http://lkml.kernel.org/r/MESSAGE-ID This way I can click on it to redirect me to some archive and if it still doesn't work, then I can google for that message-id, but the way you did I can't even google for the subject of that message :-\ BTW: this is what I get for lkml.org now: 504 Gateway Time-out nginx/1.4.6 (Ubuntu) - Arnaldo > eBPF instructions to correct byte order, we are unable to deal with > endianess in code logical generated by LLVM. > > Therefore, libbpf should simply reject missmatched ELF object, and let > LLVM to create good code. > > Signed-off-by: Wang Nan > Acked-by: Alexei Starovoitov > --- > tools/lib/bpf/libbpf.c | 30 ++++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 0824822..5d56c40 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -166,6 +166,34 @@ errout: > return err; > } > > +static int > +bpf_object__check_endianess(struct bpf_object *obj) > +{ > + static unsigned int const endian = 1; > + > + switch (obj->efile.ehdr.e_ident[EI_DATA]) { > + case ELFDATA2LSB: > + /* We are big endian, BPF obj is little endian. */ > + if (*(unsigned char const *)&endian != 1) > + goto mismatch; > + break; > + > + case ELFDATA2MSB: > + /* We are little endian, BPF obj is big endian. */ > + if (*(unsigned char const *)&endian != 0) > + goto mismatch; > + break; > + default: > + return -EINVAL; > + } > + > + return 0; > + > +mismatch: > + pr_warning("Error: endianess mismatch.\n"); > + return -EINVAL; > +} > + > struct bpf_object *bpf_object__open(const char *path) > { > struct bpf_object *obj; > @@ -187,6 +215,8 @@ struct bpf_object *bpf_object__open(const char *path) > > if (bpf_object__elf_init(obj)) > goto out; > + if (bpf_object__check_endianess(obj)) > + goto out; > > bpf_object__elf_finish(obj); > return obj; > -- > 1.8.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/