Subject: loadelf_32.c: code review request: was=>Re: ia64 unwind section: Loader implementation
To: Allen Briggs <briggs@netbsd.org>
From: Cherry G. Mathew <cherry@sdf.lonestar.org>
List: tech-kern
Date: 04/02/2006 00:43:39
On 12/31/05, Cherry George Mathew <cherry@sdf.lonestar.org> wrote:
> On Fri, 2005-12-30 at 09:38 -0500, Allen Briggs wrote:
>
> > Aside from that, this seems like the best option to me, but can it
> > be abstracted a little bit into an md callback?  Either to allow
> > machine-specific selection of extra sections to load (I think this
> > is my preference without digging into the code) or to just call a
> > machine-specific routine to load what it needs?
> >
>
> On IA64, I found it best to implement it via a simple macro which
> returns boolean about whether the
> segment needs to be loaded. The macro would be passed the whole Phdr
> structure which would enable
> the md hook to do post processing ( reloc type thingies ? ) if
> required.
>
> For IA64 unwind sections, a simple one liner did the trick:
>
> #define MD_LOADSEG(phdr) (phdr.p_type =3D=3D PT_IA_64_UNWIND ? TRUE : FAL=
SE)
>
> I've filed a PR: kern/32423
> http://netbsd.org/cgi-bin/query-pr-single.pl?number=3D32423
>
> Thanks,
>
> Cherry
>
>

Hi,

Would this affect other ports ?

Thanks,

Cherry


cvs diff -uN loadfile_elf32.c
Index: loadfile_elf32.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/sys/lib/libsa/loadfile_elf32.c,v
retrieving revision 1.13
diff -u -r1.13 loadfile_elf32.c
--- loadfile_elf32.c=0925 Jan 2006 18:27:23 -0000=091.13
+++ loadfile_elf32.c=091 Apr 2006 19:02:52 -0000
@@ -296,6 +296,13 @@

 =09for (first =3D 1, i =3D 0; i < elf->e_phnum; i++) {
 =09=09internalize_phdr(elf->e_ident[EI_DATA], &phdr[i]);
+
+#ifdef MD_LOADSEG /* Allow processor ABI specific segment loads */
+=09=09if ( (phdr[i].p_type & PT_LOPROC) &&
+=09=09     MD_LOADSEG(phdr[i]))
+=09=09=09goto loadseg;
+#endif /*MD_LOADSEG*/
+
 =09=09if (phdr[i].p_type !=3D PT_LOAD ||
 =09=09    (phdr[i].p_flags & (PF_W|PF_X)) =3D=3D 0)
 =09=09=09continue;
@@ -309,6 +316,7 @@
 =09=09if ((IS_TEXT(phdr[i]) && (flags & LOAD_TEXT)) ||
 =09=09    (IS_DATA(phdr[i]) && (flags & LOAD_DATA))) {

+=09=09loadseg:
 =09=09=09/* Read in segment. */
 =09=09=09PROGRESS(("%s%lu", first ? "" : "+",
 =09=09=09    (u_long)phdr[i].p_filesz));


--
~Cherry