#include <ctype.h>
 #include <string.h>
 #include <limits.h>
-#include <stdbool.h>
 #include <errno.h>
 #include "modpost.h"
 #include "../../include/linux/license.h"
                error_occurred = true;
 }
 
-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)
                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;
 }
                /* 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);
        }
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
        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,
 
        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);