[PATCH] fix insidious bug with init section identification in the

James Bottomley (James.Bottomley@steeleye.com)
12 Jun 2003 16:09:16 -0500


This is a MIME-formatted message. If you see this text it means that your
E-mail software does not support MIME-formatted messages.

--=_courier-12296-1055452254-0001-2
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

This problem manifests itself nastily on parisc, where the linker seems
to generate large number of elf sections, often one for each non static
function, with names like

.text.<function name>

The problem is that the kernel/module.c uses the following test to
identify init sections:

|| strstr(secstrings + s->sh_name, ".init"))

Which will pass if ".init" is matched anywhere in the elf section name.
Obviously, any parisc sections for functions that begin with "init"
match, and are spuriously dumped into the init code.

The fix that works for me on parisc is just to check the beginning of
the string for ".init". However, I can't find any document that
guarantees this to be correct. On the other hand, no non-init section
will begin with ".init", so the patch should be safe, just may be non
optimal.

James

--=_courier-12296-1055452254-0001-2
Content-Type: text/plain; name="tmp.diff"; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline; filename=tmp.diff

=3D=3D=3D=3D=3D kernel/module.c 1.86 vs edited =3D=3D=3D=3D=3D
--- 1.86/kernel/module.c Wed Jun 11 00:55:09 2003
+++ edited/kernel/module.c Thu Jun 12 15:46:13 2003
@@ -1194,7 +1194,8 @@
if ((s->sh_flags & masks[m][0]) !=3D masks[m][0]
|| (s->sh_flags & masks[m][1])
|| s->sh_entsize !=3D ~0UL
- || strstr(secstrings + s->sh_name, ".init"))
+ || strncmp(secstrings + s->sh_name,
+ ".init", 5) =3D=3D 0)
continue;
s->sh_entsize =3D get_offset(&mod->core_size, s);
DEBUGP("\t%s\n", secstrings + s->sh_name);
@@ -1209,7 +1210,8 @@
if ((s->sh_flags & masks[m][0]) !=3D masks[m][0]
|| (s->sh_flags & masks[m][1])
|| s->sh_entsize !=3D ~0UL
- || !strstr(secstrings + s->sh_name, ".init"))
+ || strncmp(secstrings + s->sh_name,
+ ".init", 5) !=3D 0)
continue;
s->sh_entsize =3D (get_offset(&mod->init_size, s)
| INIT_OFFSET_MASK);
@@ -1413,7 +1415,7 @@
}
#ifndef CONFIG_MODULE_UNLOAD
/* Don't load .exit sections */
- if (strstr(secstrings+sechdrs[i].sh_name, ".exit"))
+ if (strncmp(secstrings+sechdrs[i].sh_name, ".exit", 5) =3D=3D 0)
sechdrs[i].sh_flags &=3D ~(unsigned long)SHF_ALLOC;
#endif
}

--=_courier-12296-1055452254-0001-2--