Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3487536ybc; Thu, 14 Nov 2019 09:49:37 -0800 (PST) X-Google-Smtp-Source: APXvYqzFGnVZ9Qve32umEvpjOfxPIoDPc8Tj55JOgB0psogk7q31RDupLv3vim2Ew5diDaOjm4u8 X-Received: by 2002:a17:907:2070:: with SMTP id qp16mr9737945ejb.115.1573753776931; Thu, 14 Nov 2019 09:49:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573753776; cv=none; d=google.com; s=arc-20160816; b=rL41ZoCAUJQZCgd+7kxLU1TNQB3dLeE7/LzJCwaedGyKyZnYEr5H2N1ngEXUWcI8+Y 1iPV6UEXc7hZO8dDYNdao7SnrfI/GbWcjRrmjt4f22T6dEYA40o7YoVRMSkMzdfLtnHV DED792lYCf2Iqt/68E//M33ZQVujKZc7UpH3lracOLINE6YRvr30ooB481eNJZJ0WSuX hNhMJsdR3yA5B6vBdRYwGcn0re2qL+fzPv9Lii72nVZv3caJdNdiaR28pki58NhKCM8Q WmyXBVkJNELGNR1ncVi/fo++Ce4SnCqAV9c8Yl5sFI2/oNP2QGIarNh7axS4T/NTfAoh YaXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature:dkim-filter; bh=BcA9yFsMlJst8ZzmTrIRKKCI279WdiORVkP8tMP3V6o=; b=hY6CuHlxtAtKQU8cr4xUQtQwbJXdDbpvXVu03UIGC09nGBpd/0wJX8VcbabQqTDTSy xf5xdHLD/PKOJ4gBX3JubY5p5YZw973+7NEu41bfFVPTDxBrabED+14bpM/XwCibpS+o GqKexkB6te68+0vPmJmOjBae/DI9DyQpyP1uwUVpqLBlQ41DwiRi9ypxumcoOKZGfv4B XBy9FkYIGGrjdMhVQ4QPblsbpyZaURjAA/TSrvWbZ0EY3G8sjy6azbzLqlkCnvSyHWGz yEwVyVoFRhxytwwJWhuAcQtnwxIf6pdSL+waar+Cd9ea3h39IbdpBpoThljLHZFqItnr A9kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ESvySBPf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10si4471911eda.284.2019.11.14.09.49.11; Thu, 14 Nov 2019 09:49:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ESvySBPf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726655AbfKNRpz (ORCPT + 99 others); Thu, 14 Nov 2019 12:45:55 -0500 Received: from conssluserg-05.nifty.com ([210.131.2.90]:33649 "EHLO conssluserg-05.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726443AbfKNRpz (ORCPT ); Thu, 14 Nov 2019 12:45:55 -0500 Received: from mail-ua1-f46.google.com (mail-ua1-f46.google.com [209.85.222.46]) (authenticated) by conssluserg-05.nifty.com with ESMTP id xAEHjeI1025064; Fri, 15 Nov 2019 02:45:40 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-05.nifty.com xAEHjeI1025064 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1573753541; bh=BcA9yFsMlJst8ZzmTrIRKKCI279WdiORVkP8tMP3V6o=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ESvySBPfR6cYtXxIYJZgL9uqvX/ZsiPk08ydHM1nywiRoM0BezB08/Ijq+smlfbzn gtl9NMA7v6e6XK0CxuZe3fbKyDgCOJmo9Slv5p9fa0xyyE6Cf7y5Vx+8cv4e0SST8b 8x5xSeygLug4wH/gx1tmVqenFMDmfj5/2EtsKCcs6VYWEOzzr8VwJ2lD29y/69ayUb x8fYqv7D4N8vcq6LX2YOWWniTuRC5zJn1teGWibT6gjyps7SdUJ1eHRaG4P8IReklT Ao7BpXpel4rrIJwxCyTJcA224yXJCSHo4QSJx7/PWqt6sPgC4XGF9mGDhw7bapogZi qzBTHU9XLmEng== X-Nifty-SrcIP: [209.85.222.46] Received: by mail-ua1-f46.google.com with SMTP id o9so2143769uat.8; Thu, 14 Nov 2019 09:45:40 -0800 (PST) X-Gm-Message-State: APjAAAVNPl/2VLXcaElEMqnF4Ay/dmcKB2Bloxb5K5BkWyCybVSel/03 IbhnqV4XC4owEfwlHzIGhhP8xPpxAtW08gl1aAM= X-Received: by 2002:a9f:3015:: with SMTP id h21mr6570412uab.95.1573753539427; Thu, 14 Nov 2019 09:45:39 -0800 (PST) MIME-Version: 1.0 References: <20191114174226.7201-1-yamada.masahiro@socionext.com> In-Reply-To: <20191114174226.7201-1-yamada.masahiro@socionext.com> From: Masahiro Yamada Date: Fri, 15 Nov 2019 02:45:03 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/6] modpost: add a helper to get data pointed by a symbol To: Linux Kbuild mailing list Cc: Michal Marek , Linux Kernel Mailing List , Matthias Maennich Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (+CC: Matthias, who might be interested) On Fri, Nov 15, 2019 at 2:42 AM Masahiro Yamada wrote: > > When CONFIG_MODULE_REL_CRCS is enabled, the value of __crc_* is not > an absolute value, but the address to the CRC data embedded in the > .rodata section. > > Getting the data pointed by the symbol value is somewhat complex. > Split it out into a new helper, sym_get_data(). > > I will reuse it to refactor namespace_from_kstrtabns() in the next > commit. > > Signed-off-by: Masahiro Yamada > --- > > scripts/mod/modpost.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c > index 46d7f695fe7f..cd885573daaf 100644 > --- a/scripts/mod/modpost.c > +++ b/scripts/mod/modpost.c > @@ -308,6 +308,18 @@ static const char *sec_name(struct elf_info *elf, int secindex) > return sech_name(elf, &elf->sechdrs[secindex]); > } > > +static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym) > +{ > + Elf_Shdr *sechdr = &info->sechdrs[sym->st_shndx]; > + unsigned long offset; > + > + offset = sym->st_value; > + if (info->hdr->e_type != ET_REL) > + offset -= sechdr->sh_addr; > + > + return (void *)info->hdr + sechdr->sh_offset + offset; > +} > + > #define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0) > > static enum export export_from_secname(struct elf_info *elf, unsigned int sec) > @@ -697,10 +709,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info, > unsigned int *crcp; > > /* symbol points to the CRC in the ELF object */ > - crcp = (void *)info->hdr + sym->st_value + > - info->sechdrs[sym->st_shndx].sh_offset - > - (info->hdr->e_type != ET_REL ? > - info->sechdrs[sym->st_shndx].sh_addr : 0); > + crcp = sym_get_data(info, sym); > crc = TO_NATIVE(*crcp); > } > sym_update_crc(symname + strlen("__crc_"), mod, crc, > -- > 2.17.1 > -- Best Regards Masahiro Yamada