Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp673330pxb; Wed, 18 Nov 2020 14:11:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbb6QfopNk3kgnZO77aSXPXU2R4TImGnfhJltQZID9DxnWQ6C5JYPjW4bsrAFX3J0jAI90 X-Received: by 2002:a17:906:b150:: with SMTP id bt16mr26434900ejb.257.1605737476932; Wed, 18 Nov 2020 14:11:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605737476; cv=none; d=google.com; s=arc-20160816; b=rOj+M5NrUnOKUVx5KU6Ip3rGuQZHS+86ZgjdH2InoOERhSYTbhIuk0qVi6CfkTov/N mO7KJSeo6W0KNCowiV03QaiKQVQhyu3g0832krUB9ViAvB1UKIH4p8sAaQVNfi4Z69G6 fMVhMOuSlqnSm/ELD4RiKvseIjrvEhiz3OuDeFLJZ0ATmUAXX+CIBLfiIobjNLZXyEcu kQyBiw6iKCzMImI6Y4J6A/8jpyIHJ7fUOoMmpQUGuPduXlTex/Y3CR5oUUhxHy/qlsXM C6AmIgSuCM3s3E54VzxGz3XlFTxLbiLfqDpnaYXqXMZI0GAtCGXRV8XhslCz2MtulAmP BQXw== 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=viQfWSBnWWQkhdsfshg6wjQjXkrLrUdatQTDtGtOjLo=; b=RqX3u+ejONHK4GHEsUiekmkcqpM/Y6Aoqjr/RjOr4Saw+j4yRnyCu79evq/n34Cf9k bCH+rrcXZGZdqte+WfBkUKM1EDxuPBEEyJM7YYYSlmhnu6mtEKjReNppyPeV/zSDxCyV V5X+okG7wm+s+Y73eCklRVVmPp8j+PMa53sGfYr12aSgfS58lk9S02G0zTrG2Ewlqktc ifkOGVFDr5H8J+ddIqCTc2uGShdUyAtIHgJNwSP8K/gqj+uy/8p5FvQOHCoC2eVdaJYH e1t84VJ062L/T2RKQiPz2vB79ttf2QLzkySoHchZEwG/8M11yaMO/ZUn3fIptJ567x4p cDxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=dbW3OmpX; 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 bc3si5838145edb.258.2020.11.18.14.10.54; Wed, 18 Nov 2020 14:11:16 -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=dbW3OmpX; 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 S1727431AbgKRWH6 (ORCPT + 99 others); Wed, 18 Nov 2020 17:07:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727372AbgKRWH4 (ORCPT ); Wed, 18 Nov 2020 17:07:56 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B69CC061A48 for ; Wed, 18 Nov 2020 14:07:56 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id e142so4531144ybf.16 for ; Wed, 18 Nov 2020 14:07:56 -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=viQfWSBnWWQkhdsfshg6wjQjXkrLrUdatQTDtGtOjLo=; b=dbW3OmpXPLinNMGxA3qqhmIvkxGOzMc7C/RLfKw2PW/qdCHjGaq5Rs1hCGsIzYh/jX cUO3w+ryPubJXJGol/AuBCcRFfqimlfssxX4y6J+iwik+/cszhw9jew2aOb9Lmdvu7q3 qieIDuh+CLwus3Se4ineY0Vi/kyTjXVxXyZ5lorAi2Hmy7HlCWwt7n7Fopjj6RXhZLX7 kv5Z35uHWmDhqECCVyNr9OPFyUHAODR3hYTPnvLnPLJZNbu1ZVXJIfgazGluz4pgyU8J qMfDZ+fkDzZG6An4ZATuVPNoDZGPBmol5zRBPXVr5pn1bl81Wq0RE3gdh/WU/xznOT8P KR2w== 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=viQfWSBnWWQkhdsfshg6wjQjXkrLrUdatQTDtGtOjLo=; b=IgkzUSiOLc43L4mLX+Ld0Sy8qhQNjO64fxJvX/7POoFzr32EkEeXkapDN+IG68UjAN HSJFGWVG4ar5etYZ1E7s9CAPmaQU+87KtxpGEQGRuVDOOMEsFku0M4j1S/FuOfGSptjk 0+tJwXpvs8nQ22glPSo0ABd32ms9qQvYrcNWpVRiqk7ZkFh5pWn+dCSIrj4+x3mIgzsX Osn+2z0II3k8X9WdJHsUE03++qu4kBnyBQmaKrMwgYbEUItqVYbmHzWAXrZAxVeeU0po PNOPQIbyS/3CeFZ6+yYfO3Skr3AfY9rBT6RAbD0SD4Fa96pkLmCuBTfo46BpLT+EMQ2Y qRLw== X-Gm-Message-State: AOAM530dxIN9LNGox8EPbOr8vnOSZEw/I9GDLeDWvIgWUdjLEem8T1aJ bifxG07RpydTXdm95dSSruN5T5g6nF25mSQFCyM= 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:9248:: with SMTP id e8mr12067724ybo.223.1605737275399; Wed, 18 Nov 2020 14:07:55 -0800 (PST) Date: Wed, 18 Nov 2020 14:07:24 -0800 In-Reply-To: <20201118220731.925424-1-samitolvanen@google.com> Message-Id: <20201118220731.925424-11-samitolvanen@google.com> Mime-Version: 1.0 References: <20201118220731.925424-1-samitolvanen@google.com> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH v7 10/17] 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.299.gdc1121823c-goog