Skip to contentSkip to conversation

improve dedotify()

PATCH New Jan Beulich 1 participant 1 message Jan 11, 2008 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 improve dedotify()

This completely untested patch is intended to be a suggestion only:
Code inspection for an entirely different purpose made me stumble across this, and I think that modifying the string table of an ELF object is a bad idea, since there's nothing disallowing a linker to merge strings inside the table, which would result in this code possibly, but unintentionally screwing up other symbol names. Besides that, the presented alternative is both smaller and faster.

---
 arch/powerpc/kernel/module_64.c |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
arch/powerpc/kernel/module_64.c +4 -6
@@ -154,16 +154,14 @@ static void dedotify_versions(struct mod
 }
 
 /* Undefined symbols which refer to .funcname, hack to funcname */
-static void dedotify(Elf64_Sym *syms, unsigned int numsyms, char *strtab)
+static void dedotify(Elf64_Sym *syms, unsigned int numsyms, const char *strtab)
 {
 	unsigned int i;
 
 	for (i = 1; i < numsyms; i++) {
-		if (syms[i].st_shndx == SHN_UNDEF) {
-			char *name = strtab + syms[i].st_name;
-			if (name[0] == '.')
-				memmove(name, name+1, strlen(name));
-		}
+		if (syms[i].st_shndx == SHN_UNDEF
+		    && strtab[syms[i].st_name] == '.')
+			syms[i].st_name++;
 	}
 }