Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4109593pxk; Tue, 29 Sep 2020 14:49:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpkIfGyUcng5bx/E+H2oxd++UYElgJLbB5coHrwmyJJMyjXkQ2t8po+9WADm4h+cFhR2ui X-Received: by 2002:a17:906:7cb:: with SMTP id m11mr6118171ejc.41.1601416156028; Tue, 29 Sep 2020 14:49:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601416156; cv=none; d=google.com; s=arc-20160816; b=BIwV9uac2IgGoTua939zPniF9WvTDBh7FkMW8RlU8Y61bbEORf01d1DY86za6FSp9Q IXNWkLt4V4MbQ4S/hVDy/F6d1kUkWbo8xW+2DM3c7yfG92S58Gz7M2aznK1NuXP2qGcp 8LMDKWPIh2bqck1eM6hJTiD48q36nmh9nfXE8sCLgcpW2h1zpcxB4ELaJzdoIjbA1KxI R12So5LTlQidm3OZtq1ewgKcbC7YQXywS1nF7Fnla/CtfPXR2g+WaE2cxALtirLYC1kq swJeeRKgtpGo7SD3JXaKYxgomdhO1VbEhsndd6ujSOEsxB1r/AynZySTcLPuy5S5gZm+ 6+oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=xzyA8l2K/c66vMnXDNauqm3QGp8JWTgD7BK0hUJgM/s=; b=BOzpkzbza24WBpwpVD4KyYa3agZAIkeinedkWXvp8Uiyc/kjiNuJQsF+khHJfwdlnN HAnM1B/Ykx9u4mlyR9kSf3lC7bkidvOCCOjA2ytu6VWhQEXekLeRCZ9ncSc0PdUv3+u6 YbhkkB1ANYtq4t51pHBmZDdLa3p+/MffQtqaUrfa4/0PDQI0TPQ6AEybUpg49QC+Av7p nIgHShJVsiQKPkBEEiNXII05sGMfgOoEhbpY9ANB/bneIAGXU6hGTOIjFMdEtp9Kgx9V MuxTG0IuenCG/dLl3z2E40oduoz9/e7Tx1NeD9PKVwYDa7drTzgNy476vzopuV//de4T +jUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kV2nt2jN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b7si3579429edz.159.2020.09.29.14.48.52; Tue, 29 Sep 2020 14:49:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kV2nt2jN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729112AbgI2Vr1 (ORCPT + 99 others); Tue, 29 Sep 2020 17:47:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729011AbgI2VrV (ORCPT ); Tue, 29 Sep 2020 17:47:21 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4DADC0613DE for ; Tue, 29 Sep 2020 14:47:19 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id di5so3360211qvb.13 for ; Tue, 29 Sep 2020 14:47:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=xzyA8l2K/c66vMnXDNauqm3QGp8JWTgD7BK0hUJgM/s=; b=kV2nt2jNowOc+Ncq4P9QWaXm3ia/nj07aeJPueQSzED868lUhqtxFZ1hxqu55/8Wgf apBdj7UdUn9KyeqQFt9SIgKMFl7RJ7ZNx0lpxffVGgoMd7KSs5/u97r9v3LLl7dXzTJj qFNfhSOXW8+KTg/HkLteW68eROKzxZ2NbFFLg+uFERNihuE2IiypRn2TJoufi+atjwzh DPCoIjZFtVOXQiqUTKol6emF8Gazy2GLiAQ1JZpbfGK4GjJmJOPeeUamEFuSC/cH7qLz WzIJBTOKAqoHs+p3l6ZXSvilX+hfClmgUYx0yOT1y4n4DFtsWFxep9nI9QJN944QLvGG JF2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xzyA8l2K/c66vMnXDNauqm3QGp8JWTgD7BK0hUJgM/s=; b=FO9AJv9Ggujcd/FovTwUP4npg8g/1Bitbn96umkcM1Q1arIYGlNIyGKH6zSpA4IG5J lo3cnIYgji/8rF8pqZJ8H+rH3ZzUYYUG9OksfrUz7ofRFWG7liqA77eYHRGK8QxKsddL qW+EG7yiuLCb/5Z61vOMDVjWbeI/2Z5EdkwTtxpjgH6wp93ZfbY4H90rXsCsD7hf4ole qjXoX/yD7+gWg7vsyi3Y5HWak/N2VxFX0g3MVASmQJvwX4fEw+dyE/qe7XriKD2NxI9E O23H/YKoAqYWUFOoANckP7aWc4R0ZRYjsYg6MggYzZDiJep86IkW6Rm+vPvTfwrQ94cn T2cg== X-Gm-Message-State: AOAM533uxEF+PDi4j/zYXQuaYJem4QsY7xac0EHX3JzWOvRMPKit/DYx XTfEg5NLBygMSQ5pR8Fd9AeZfDg4+GGM3C+WCS4= Sender: "samitolvanen via sendgmr" X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:f693:9fff:fef4:1b6d]) (user=samitolvanen job=sendgmr) by 2002:a05:6214:1873:: with SMTP id eh19mr6737362qvb.16.1601416038928; Tue, 29 Sep 2020 14:47:18 -0700 (PDT) Date: Tue, 29 Sep 2020 14:46:22 -0700 In-Reply-To: <20200929214631.3516445-1-samitolvanen@google.com> Message-Id: <20200929214631.3516445-21-samitolvanen@google.com> Mime-Version: 1.0 References: <20200929214631.3516445-1-samitolvanen@google.com> X-Mailer: git-send-email 2.28.0.709.gb0816b6eb0-goog Subject: [PATCH v4 20/29] modpost: lto: strip .lto from module names From: Sami Tolvanen To: Masahiro Yamada , Will Deacon , Steven Rostedt Cc: Peter Zijlstra , Greg Kroah-Hartman , "Paul E. McKenney" , Kees Cook , Nick Desaulniers , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org, Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With LTO, everything is compiled into LLVM bitcode, so we have to link each module into native code before modpost. Kbuild uses the .lto.o suffix for these files, which also ends up in module information. This change strips the unnecessary .lto suffix from the module name. Suggested-by: Bill Wendling Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- scripts/mod/modpost.c | 16 +++++++--------- scripts/mod/modpost.h | 9 +++++++++ scripts/mod/sumversion.c | 6 +++++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 69341b36f271..5a329df55cc3 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include "modpost.h" #include "../../include/linux/license.h" @@ -80,14 +79,6 @@ modpost_log(enum loglevel loglevel, const char *fmt, ...) exit(1); } -static inline bool strends(const char *str, const char *postfix) -{ - if (strlen(str) < strlen(postfix)) - return false; - - return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; -} - void *do_nofail(void *ptr, const char *expr) { if (!ptr) @@ -1984,6 +1975,10 @@ static char *remove_dot(char *s) size_t m = strspn(s + n + 1, "0123456789"); if (m && (s[n + m] == '.' || s[n + m] == 0)) s[n] = 0; + + /* strip trailing .lto */ + if (strends(s, ".lto")) + s[strlen(s) - 4] = '\0'; } return s; } @@ -2007,6 +2002,9 @@ static void read_symbols(const char *modname) /* strip trailing .o */ tmp = NOFAIL(strdup(modname)); tmp[strlen(tmp) - 2] = '\0'; + /* strip trailing .lto */ + if (strends(tmp, ".lto")) + tmp[strlen(tmp) - 4] = '\0'; mod = new_module(tmp); free(tmp); } diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 3aa052722233..fab30d201f9e 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -180,6 +181,14 @@ static inline unsigned int get_secindex(const struct elf_info *info, return info->symtab_shndx_start[sym - info->symtab_start]; } +static inline bool strends(const char *str, const char *postfix) +{ + if (strlen(str) < strlen(postfix)) + return false; + + return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; +} + /* file2alias.c */ extern unsigned int cross_build; void handle_moddevtable(struct module *mod, struct elf_info *info, diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c index d587f40f1117..760e6baa7eda 100644 --- a/scripts/mod/sumversion.c +++ b/scripts/mod/sumversion.c @@ -391,10 +391,14 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen) struct md4_ctx md; char *fname; char filelist[PATH_MAX + 1]; + int postfix_len = 1; + + if (strends(modname, ".lto.o")) + postfix_len = 5; /* objects for a module are listed in the first line of *.mod file. */ snprintf(filelist, sizeof(filelist), "%.*smod", - (int)strlen(modname) - 1, modname); + (int)strlen(modname) - postfix_len, modname); buf = read_text_file(filelist); -- 2.28.0.709.gb0816b6eb0-goog