[BusyBox] Re: BusyBox insmod problem. Global variables badly initialized.

Magnus Damm damm at opensource.se
Wed May 8 08:34:03 UTC 2002


Hi all,

I based my ppc-implementation of insmod on modutils-2.3.16.

I've never experienced any problems on my mpc8xx-based targets.
But I use a 2.2-kernel. 

I diffed the file modutils/obj/obj_ppc.c between 2.3.16 and 2.4.16,
and they seem to use a section called "__ftr_fixup" as arch_data.
The busybox implementation only looks for ARCHDATA_SEC_NAME, ie
"__archdata".
Maybe adding a search for "__ftr_fixup" is something...
But modutils/obj/obj_mips.c looks for a section called "__dbe_table" and
that's not present in the busybox insmod either, so maybe both are wrong 
or I'm way off.

See the attached diff for more info.

I don't have any board handy for testing now, so this
is just a guess...

Hope this helps /

Magnus


Goddeeris Frederic wrote:
> 
> Hi,
> 
> Currently I just avoid the problem and did not put any effort yet in trying
> to find the problem.
> 
> I presume that the busybox version of insmod resembles a lot to the original
> insmod. Perhaps it is not so difficult to find the difference...
> 
> Thanks,
> Frederic
> 
> -----Original Message-----
> From: Matthias Fuchs [mailto:matthias.fuchs at esd-electronics.com]
> Sent: woensdag 8 mei 2002 11:54
> To: Christian Grigis
> Cc: busybox
> Subject: Re: [BusyBox] Re: BusyBox insmod problem. Global variables
> badly initialized.
> 
> Hi Christian,
> 
> I think I encountered the same problem. Did you hear about a workaround ?
> 
> Matthias
> 
> Christian Grigis wrote:
> 
> > Hello,
> >
> > On Thu Mar 28 01:28:05 2002, <Frederic.Goddeeris at siemens.atea.be> wrote:
> >
> >>Hi,
> >>
> >>I have been struggling with global variables that are not always correctly
> >>initialized in kernel modules and have been posting reports to
> ppclinux-dev
> >>about this.
> >>
> >>Somebody reported that he had seen the same issue while somebody else
> >>reported he could not reproduce the problem. Today I discovered that when
> I
> >>use the original insmod instead of the insmod in Busybox the issue seems
> >>solved...
> >>
> >>This is the modules I used for testing:
> >>
> >>#include <linux/module.h>
> >>#include <linux/kernel.h>
> >>#include <linux/init.h>
> >>
> >>char MyMemSpace[2*0x100];
> >>char *MemPointers[2] = {&(MyMemSpace[0]), &(MyMemSpace[0x100])};
> >>
> >>typedef struct
> >>{
> >>      char *szName;
> >>      char *szName2;
> >>} MyStruct_t;
> >>
> >>MyStruct_t MyStruct[] = {{"A", "A2"}, {"B", "B2"}};
> >>
> >>int init_module(void)
> >>{
> >>      printk("TestDriver 3 Loaded\n");
> >>
> >>      printk("MyMemSpace: 0x%lx 0x%lx \n",  (long)&(MyMemSpace[0]),
> >>             (long)&(MyMemSpace[0x100]));
> >>      printk("MemPointers: 0x%lx 0x%lx \n", (long)(MemPointers[0]),
> >>             (long)(MemPointers[1]));
> >>
> >>      printk("First Char is MyStruct[0].szName %c\n",
> >>             MyStruct[0].szName[0]);
> >>
> >>
> >>      return -1;
> >>}
> >>
> >>void cleanup_module(void)
> >>{
> >>      return;
> >>}
> >>
> >>With insmod of busybox I get:
> >>      MyMemSpace: 0xc304a1ec 0xc304a2ec
> >>      MemPointers: 0xc304a1ec 0xc304a3ec
> >>      First Char is MyStruct[0].szName e
> >>
> >>With the regular insmod I get:
> >>      MyMemSpace: 0xc304226c 0xc304236c
> >>      MemPointers: 0xc304226c 0xc304236c
> >>      First Char is MyStruct[0].szName A
> >>
> >>I use HHL2.0 (2.4.2), gcc 2.95.3, Busybox 0.60.2
> >>
> >>Can somebody help me solving this issue?
> >>
> >>Thanks,
> >>Frederic
> >>
> >
> >
> > I have been having the exact same problem on a similar environment (HHL2.0
> PPC
> > w/kernel 2.4.2, gcc 2.95.3, latest CVS busybox), and also noticed that the
> > char pointers in a global struct were resolved correctly only with the
> > standard insmod from modutils, but not with BusyBox's insmod.
> >
> > Does anyone have more information about this? Is it a problem with
> BusyBox's
> > insmod or the kernel I am using?
> >
> > Thank you very much for any help.
> >
> > Regards,
> >
> > -Christian
> >
> >
> 
> --
> -------------------------------------------------------------------------
> 
>                              _/_/_/_/   Matthias Fuchs
>                             _/_/_/_/   Dipl.-Ing.
>                            _/_/_/_/   matthias.fuchs at esd-electronics.com
> 
>        _/_/_/   _/_/_/_/_/_/_/      esd electronic system design gmbh
>      _/   _/  _/             _/    Vahrenwalder Str. 207
>     _/   _/    _/_/_/   _/   _/   D-30165 Hannover
>     _/             _/  _/   _/   Phone: +49-511-37298-0
>      _/_/_/_/_/_/_/   _/_/_/    Fax:   +49-511-37298-68
> 
> -------------------------------------------------------------------------
> 
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://busybox.net/mailman/listinfo/busybox
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://busybox.net/mailman/listinfo/busybox
-------------- next part --------------
--- modutils-2.3.16/obj/obj_ppc.c	Wed Aug 23 02:23:26 2000
+++ modutils-2.4.16/obj/obj_ppc.c	Fri Mar  1 01:39:06 2002
@@ -20,8 +20,6 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-#ident "$Id: obj_ppc.c 1.4 Wed, 23 Aug 2000 10:23:26 +1000 kaos $"
-
 #include <stddef.h>
 #include <module.h>
 #include <obj.h>
@@ -180,8 +178,8 @@
   int i, offset;
   struct obj_section *sec, *syms, *strs;
   ElfW(Rela) *rel, *relend;
-  ElfW(Sym) *symtab, *extsym;
-  const char *strtab, *name;
+  ElfW(Sym) *symtab;
+  const char *strtab;
   struct ppc_symbol *intsym;
   struct ppc_plt_entry *pe;
 
@@ -203,12 +201,7 @@
 	{
 	  if (ELF32_R_TYPE(rel->r_info) != R_PPC_REL24)
 	    continue;
-	  extsym = &symtab[ELF32_R_SYM(rel->r_info)];
-	  if (extsym->st_name)
-	    name = strtab + extsym->st_name;
-	  else
-	    name = f->sections[extsym->st_shndx]->name;
-	  intsym = (struct ppc_symbol *) obj_find_symbol(f, name);
+	  obj_find_relsym(intsym, f, f, rel, symtab, strtab);
 
 	  for (pe = intsym->plt_entries; pe != NULL; pe = pe->next)
 	    if (pe->addend == rel->r_addend)
@@ -226,7 +219,7 @@
 	}
     }
 
-  pf->plt = obj_create_alloced_section(f, ".plt", 16, offset);
+  pf->plt = obj_create_alloced_section(f, ".plt", 16, offset, SHF_WRITE);
 
   return 1;
 }
@@ -249,7 +242,25 @@
 }
 
 int
-arch_archdata (struct obj_file *fin, struct obj_section *sec)
+arch_archdata (struct obj_file *f, struct obj_section *archdata_sec)
 {
+  struct archdata {
+    unsigned tgt_long __start___ftr_fixup;
+    unsigned tgt_long __stop___ftr_fixup;
+  } *ad;
+  struct obj_section *sec;
+
+  if (archdata_sec->contents)
+    free(archdata_sec->contents);
+  archdata_sec->header.sh_size = 0;
+  sec = obj_find_section(f, "__ftr_fixup");
+  if (sec) {
+    ad = (struct archdata *) (archdata_sec->contents) = xmalloc(sizeof(*ad));
+    memset(ad, 0, sizeof(*ad));
+    archdata_sec->header.sh_size = sizeof(*ad);
+    ad->__start___ftr_fixup = sec->header.sh_addr;
+    ad->__stop___ftr_fixup = sec->header.sh_addr + sec->header.sh_size;
+  }
+
   return 0;
 }


More information about the busybox mailing list