]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - scripts/mod/modpost.c
module/retpoline: Warn about missing retpoline in module
[linux.git] / scripts / mod / modpost.c
index b920d186ad4a9abad1ed5557c7504afd96b2548f..54deaa1066cf04a5df710695ed6fa36a7036f9ef 100644 (file)
@@ -47,6 +47,12 @@ enum export {
        export_unused_gpl, export_gpl_future, export_unknown
 };
 
+/* In kernel, this size is defined in linux/module.h;
+ * here we use Elf_Addr instead of long for covering cross-compile
+ */
+
+#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
+
 #define PRINTF __attribute__ ((format (printf, 1, 2)))
 
 PRINTF void fatal(const char *fmt, ...)
@@ -2111,6 +2117,23 @@ static void check_exports(struct module *mod)
        }
 }
 
+static int check_modname_len(struct module *mod)
+{
+       const char *mod_name;
+
+       mod_name = strrchr(mod->name, '/');
+       if (mod_name == NULL)
+               mod_name = mod->name;
+       else
+               mod_name++;
+       if (strlen(mod_name) >= MODULE_NAME_LEN) {
+               merror("module name is too long [%s.ko]\n", mod->name);
+               return 1;
+       }
+
+       return 0;
+}
+
 /**
  * Header for the generated file
  **/
@@ -2142,6 +2165,14 @@ static void add_intree_flag(struct buffer *b, int is_intree)
                buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n");
 }
 
+/* Cannot check for assembler */
+static void add_retpoline(struct buffer *b)
+{
+       buf_printf(b, "\n#ifdef RETPOLINE\n");
+       buf_printf(b, "MODULE_INFO(retpoline, \"Y\");\n");
+       buf_printf(b, "#endif\n");
+}
+
 static void add_staging_flag(struct buffer *b, const char *name)
 {
        static const char *staging_dir = "drivers/staging";
@@ -2150,11 +2181,6 @@ static void add_staging_flag(struct buffer *b, const char *name)
                buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
 }
 
-/* In kernel, this size is defined in linux/module.h;
- * here we use Elf_Addr instead of long for covering cross-compile
- */
-#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
-
 /**
  * Record CRCs for unresolved symbols
  **/
@@ -2485,8 +2511,10 @@ int main(int argc, char **argv)
 
                buf.pos = 0;
 
+               err |= check_modname_len(mod);
                add_header(&buf, mod);
                add_intree_flag(&buf, !external_module);
+               add_retpoline(&buf);
                add_staging_flag(&buf, mod->name);
                err |= add_versions(&buf, mod);
                add_depends(&buf, mod, modules);