From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755422AbbCRJGp (ORCPT ); Wed, 18 Mar 2015 05:06:45 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:27970 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753594AbbCRJGm (ORCPT ); Wed, 18 Mar 2015 05:06:42 -0400 Date: Wed, 18 Mar 2015 10:08:25 +0100 From: Quentin Casasnovas To: Quentin Casasnovas , Rusty Russell , Michal Marek Cc: lkml , Oleg Nesterov , Borislav Petkov , Linus Torvalds Subject: Re: [PATCH 3/7] modpost: add handler function pointer to sectioncheck. Message-ID: <20150318090825.GH19131@chrystal.uk.oracle.com> References: <1426596002-26128-1-git-send-email-quentin.casasnovas@oracle.com> <1426596002-26128-4-git-send-email-quentin.casasnovas@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1426596002-26128-4-git-send-email-quentin.casasnovas@oracle.com> User-Agent: Mutt/1.5.22 (2013-10-16) X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding Rusty and Michal to CC. On Tue, Mar 17, 2015 at 01:39:58PM +0100, Quentin Casasnovas wrote: > This will be useful when we want to have special handlers which need to go > through more hops to print useful information to the user. > > Signed-off-by: Quentin Casasnovas > --- > scripts/mod/modpost.c | 68 +++++++++++++++++++++++++++++++-------------------- > 1 file changed, 42 insertions(+), 26 deletions(-) > > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c > index 8cef46b..0f48f8b 100644 > --- a/scripts/mod/modpost.c > +++ b/scripts/mod/modpost.c > @@ -930,6 +930,10 @@ struct sectioncheck { > const char *good_tosec[20]; > enum mismatch mismatch; > const char *symbol_white_list[20]; > + void (*handler)(const char *modname, struct elf_info *elf, > + const struct sectioncheck* const mismatch, > + Elf_Rela *r, Elf_Sym *sym, const char *fromsec); > + > }; > > static const struct sectioncheck sectioncheck[] = { > @@ -1417,37 +1421,49 @@ static void report_sec_mismatch(const char *modname, > fprintf(stderr, "\n"); > } > > -static void check_section_mismatch(const char *modname, struct elf_info *elf, > - Elf_Rela *r, Elf_Sym *sym, const char *fromsec) > +static void default_mismatch_handler(const char *modname, struct elf_info *elf, > + const struct sectioncheck* const mismatch, > + Elf_Rela *r, Elf_Sym *sym, const char *fromsec) > { > const char *tosec; > - const struct sectioncheck *mismatch; > + Elf_Sym *to; > + Elf_Sym *from; > + const char *tosym; > + const char *fromsym; > > tosec = sec_name(elf, get_secindex(elf, sym)); > - mismatch = section_mismatch(fromsec, tosec); > + from = find_elf_symbol2(elf, r->r_offset, fromsec); > + fromsym = sym_name(elf, from); > + to = find_elf_symbol(elf, r->r_addend, sym); > + tosym = sym_name(elf, to); > + > + if (!strncmp(fromsym, "reference___initcall", > + sizeof("reference___initcall")-1)) > + return; > + > + /* check whitelist - we may ignore it */ > + if (secref_whitelist(mismatch, > + fromsec, fromsym, tosec, tosym)) { > + report_sec_mismatch(modname, mismatch, > + fromsec, r->r_offset, fromsym, > + is_function(from), tosec, tosym, > + is_function(to)); > + } > +} > + > +static void check_section_mismatch(const char *modname, struct elf_info *elf, > + Elf_Rela *r, Elf_Sym *sym, const char *fromsec) > +{ > + const char *tosec = sec_name(elf, get_secindex(elf, sym));; > + const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec); > + > if (mismatch) { > - Elf_Sym *to; > - Elf_Sym *from; > - const char *tosym; > - const char *fromsym; > - > - from = find_elf_symbol2(elf, r->r_offset, fromsec); > - fromsym = sym_name(elf, from); > - to = find_elf_symbol(elf, r->r_addend, sym); > - tosym = sym_name(elf, to); > - > - if (!strncmp(fromsym, "reference___initcall", > - sizeof("reference___initcall")-1)) > - return; > - > - /* check whitelist - we may ignore it */ > - if (secref_whitelist(mismatch, > - fromsec, fromsym, tosec, tosym)) { > - report_sec_mismatch(modname, mismatch, > - fromsec, r->r_offset, fromsym, > - is_function(from), tosec, tosym, > - is_function(to)); > - } > + if (mismatch->handler) > + mismatch->handler(modname, elf, mismatch, > + r, sym, fromsec); > + else > + default_mismatch_handler(modname, elf, mismatch, > + r, sym, fromsec); > } > } > > -- > 2.0.5 >