Skip to contentSkip to conversation

Weak symbols in modules and versioned symbols

PATCH In review Petr Vandrovec 2 participants 2 messages Oct 13, 2004 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Weak symbols in modules and versioned symbols

Hello,
is there some reason why to not apply patch below? Without patch below
I'm getting

vmmon: no version for "sys_ioctl" found: kernel tainted.

when loading vmmon into kernel which exports sys_ioctl (and vmmon uses weak import for sys_ioctl because I'm not able to determine sys_ioctl availablilty for modules at build time) and no error when loading it into the kernel which does not export sys_ioctl to modules.

With added CRCs it also looks safer to me: I do not want just
random sys_ioctl; I need sys_ioctl with signature 0xABCDEFGH.
Thanks,
Petr Vandrovec

scripts/mod/modpost.c +9 -5
diff -urdN linux/scripts/mod/modpost.c linux/scripts/mod/modpost.c
@@ -102,6 +102,7 @@
 	struct module *module;
 	unsigned int crc;
 	int crc_valid;
+	unsigned int weak:1;
 	char name[0];
 };
 
@@ -124,12 +125,13 @@
  * the list of unresolved symbols per module */
 
 struct symbol *
-alloc_symbol(const char *name, struct symbol *next)
+alloc_symbol(const char *name, unsigned int weak, struct symbol *next)
 {
 	struct symbol *s = NOFAIL(malloc(sizeof(*s) + strlen(name) + 1));
 
 	memset(s, 0, sizeof(*s));
 	strcpy(s->name, name);
+	s->weak = weak;
 	s->next = next;
 	return s;
 }
@@ -143,7 +145,7 @@
 	struct symbol *new;
 
 	hash = tdb_hash(name) % SYMBOL_HASH_SIZE;
-	new = symbolhash[hash] = alloc_symbol(name, symbolhash[hash]);
+	new = symbolhash[hash] = alloc_symbol(name, 0, symbolhash[hash]);
 	new->module = module;
 	if (crc) {
 		new->crc = *crc;
@@ -347,7 +349,8 @@
 		break;
 	case SHN_UNDEF:
 		/* undefined symbol */
-		if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL)
+		if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL &&
+		    ELF_ST_BIND(sym->st_info) != STB_WEAK)
 			break;
 		/* ignore global offset table */
 		if (strcmp(symname, "_GLOBAL_OFFSET_TABLE_") == 0)
@@ -368,6 +371,7 @@
 			   strlen(MODULE_SYMBOL_PREFIX)) == 0)
 			mod->unres = alloc_symbol(symname +
 						  strlen(MODULE_SYMBOL_PREFIX),
+						  ELF_ST_BIND(sym->st_info) == STB_WEAK,
 						  mod->unres);
 		break;
 	default:
@@ -433,7 +437,7 @@
 	 * the automatic versioning doesn't pick it up, but it's really
 	 * important anyhow */
 	if (modversions)
-		mod->unres = alloc_symbol("struct_module", mod->unres);
+		mod->unres = alloc_symbol("struct_module", 0, mod->unres);
 }
 
 #define SZ 500
@@ -505,7 +509,7 @@
 	for (s = mod->unres; s; s = s->next) {
 		exp = find_symbol(s->name);
 		if (!exp || exp->module == mod) {
-			if (have_vmlinux)
+			if (have_vmlinux && !s->weak)
 				fprintf(stderr, "*** Warning: \"%s\" [%s.ko] "
 				"undefined!\n",	s->name, mod->name);
 			continue;
#1 lore raw
Quoted 5 lines · Petr Vandrovec

Hello,
is there some reason why to not apply patch below? Without patch below
I'm getting

vmmon: no version for "sys_ioctl" found: kernel tainted.

Sure, patch seems fine to me. I guess you're the first one to use weak symbols in a module. In fact, I think PPC64 might barf on them anyway.

Please ensure you've read Documentation/SubmittingPatches line 262 onwards "11) Sign your work" and resend to me off-line.

Thanks!
Rusty.

Signature · 1 line
Anyone who quotes me in their signature is an idiot -- Rusty Russell