Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp381176pxu; Tue, 1 Dec 2020 13:42:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJytoWi0b5K/txqVsVWR4dBbLiJ1Q3nrZZ84rsR+Ffrl3fWaf+QIKJTqejmrMbvEjpBQRmg1 X-Received: by 2002:a17:907:3e23:: with SMTP id hp35mr5143097ejc.254.1606858931033; Tue, 01 Dec 2020 13:42:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606858931; cv=none; d=google.com; s=arc-20160816; b=gn0OAkjlIH72aTxn0SYnMlh4dDKzF4CRPnHaLdcfXZdNdnJ7SytsMME6D1E+Q0wuJk 6UXqH8j/Jka7J+ogP0nVGkpnAAMANh4DrqR91FODbKwKbCxMc0foBnEunMPxbonk2t8W EVCyxTNqqrbJCoVUWrjM0f9iRXlPna21O5Ykw3HPSqJiuQYVPED/F9qBK2ykCLQdD3S9 PmLN6O3i/6L3hol1uRHf79QrQaaWujnH7W/bqrMpkRB17A09JcFLK4TxWadds9UhKrba szMr9UyP1+AiJnqlNzipAIX5ngilRh/7zSia1G6ZDe37vchbl2TkexpK4BKPM1i72M2a S3+Q== 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=baTa63xSC0ZZvL8LmEJ0rysXSGBclqJkA0eq2XdQYu4=; b=dOGwEWfjv2UotWANn/SBI7Ik1XaJfrKa8fXKlULtlHPlwAVUvkqQ1zXSv+sicOte6G TYEkMr1wnRXmlQjvsTuq1Z915XujZ2qAJjeQKhcXgAXbxGkWlFzO8yI/KfCcoIUnf2UR 7GloOA2nKYTp381XAZ0TJkLDhIdgrxJm91WU8XzjS1ZQb2Br9uwM2R7ehCt1FidTjoSm g3NS1rSHuxSFf4riPww8GMcuU1mMAyOmVzHlA1e/Eu7EvzF3dKPoQ7tJEIZh0h/nFWtV 24hc2ze3aKe//fRCd8BMqb1Wr960zbr0NwprieeF8+zv3ubju4NZQ+sunoMiD9bf30/F y3RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uSKl5Hyg; 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 lw27si800263ejb.35.2020.12.01.13.41.48; Tue, 01 Dec 2020 13:42:11 -0800 (PST) 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=uSKl5Hyg; 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 S2388536AbgLAVjJ (ORCPT + 99 others); Tue, 1 Dec 2020 16:39:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730057AbgLAVjI (ORCPT ); Tue, 1 Dec 2020 16:39:08 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E78ADC094250 for ; Tue, 1 Dec 2020 13:37:35 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id h9so4046969ybj.10 for ; Tue, 01 Dec 2020 13:37:35 -0800 (PST) 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=baTa63xSC0ZZvL8LmEJ0rysXSGBclqJkA0eq2XdQYu4=; b=uSKl5HygxSFku3YpTdgH92zmKIE08ozZOIdku0rdE1QVetGDukAW5zNct8DUP027uw URWQdtClz2Lqmykr7qURlRRoi54XeEUu1RNFyDxIDeMUvpG0iHYLlEVkKi2WrwC16Mag xqCGvMXwV9ADAX0kd9iwYYuz8KAJgAR0vAiOyZY3HFSRXyr3ecyoAG3asfhKd5xnA56j C0uauidumM11pi4Ni2mqK2sj3jEgFKCHCeIHT8eOoI3Oj7Se9gobAyg97sPy9VAmfmeW k2WyX9FDP9jnedQUelDpCgdiXGQAEN9BsBj4WsylG4Z2JMb6iSYkZx7yItSsSxiRphQJ 57Wg== 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=baTa63xSC0ZZvL8LmEJ0rysXSGBclqJkA0eq2XdQYu4=; b=MbF8USAWod4GP/V1zuigUfHVWm7CL5jxrhzIc33fpjV+x1QnCZyqgJU8uoY25gaazL h30xVbFruA7zHYfp4UQYbwLEjrTmc/jgr3FbOSMZPIu50y+/02j8D5WcPFwxjWrFanz5 9H6bwPb3if8Vl1rNOZfiR4M4EHT48vkuVdOpUsnLBGj92Gf/5xXT0mNd4ajgPyZJHpVW wkcWhuE+/wwmzH9FxDMs4AsGCcAViZWrx9jxKetgKelabNt3Jf6S5CdjuL/Bcw4jh/TV moED4s+UIvxLPzHHZDZK5qgWHlYmug3xAgQEu+qnlmU9y5CtH9KvTr/z3C8B+EzBcbdk eiwA== X-Gm-Message-State: AOAM5308TH3CJjJ5zQBkBLnIugEaedjkotIvBn6qtqUmt9RAGE4WKXy2 hdih/DUzrJbfEmQMqUls6L+fpGVtq5Ag5XkIx/s= 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:a25:8401:: with SMTP id u1mr9324352ybk.96.1606858655207; Tue, 01 Dec 2020 13:37:35 -0800 (PST) Date: Tue, 1 Dec 2020 13:37:01 -0800 In-Reply-To: <20201201213707.541432-1-samitolvanen@google.com> Message-Id: <20201201213707.541432-11-samitolvanen@google.com> Mime-Version: 1.0 References: <20201201213707.541432-1-samitolvanen@google.com> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog Subject: [PATCH v8 10/16] modpost: lto: strip .lto from module names From: Sami Tolvanen To: Masahiro Yamada , Steven Rostedt , Will Deacon Cc: Josh Poimboeuf , 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, 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 f882ce0d9327..ebb15cc3f262 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.29.2.576.ga3fc446d84-goog