diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-07-24 12:58:46 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-07-24 12:58:46 +0000 |
commit | 79a03b093048949d4fbe5d3d28b28076f4c45144 (patch) | |
tree | 6e41d3e9d37e64789c380a750683f48ff030f851 | |
parent | f0ed055da30188e8fcf78ebaf3c574bf83f7b183 (diff) | |
download | gcc-79a03b093048949d4fbe5d3d28b28076f4c45144.tar.gz |
2008-07-24 Basile Starynkevitch <basile@starynkevitch.net>
* gcc/basilys.h: added basilys_dlsym_all because ltdl.h has no RTLD_GLOBAL equivalent.
* gcc/basilys.c: (basilys_dlsym_all) new function.
(load_checked_dylib) fill the vector of dlhandle-s.
(basilys_dynobjstruct_fieldoffset_at, basilys_dynobjstruct_classlength_at) use basilys_dlsym_all.
* gcc/Makefile.in: added support for warm-*-d.so
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@138115 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog.melt | 9 | ||||
-rw-r--r-- | gcc/Makefile.in | 40 | ||||
-rw-r--r-- | gcc/basilys.c | 52 | ||||
-rw-r--r-- | gcc/basilys.h | 9 |
4 files changed, 75 insertions, 35 deletions
diff --git a/gcc/ChangeLog.melt b/gcc/ChangeLog.melt index 29cc04f8da5..455b7201c97 100644 --- a/gcc/ChangeLog.melt +++ b/gcc/ChangeLog.melt @@ -1,4 +1,13 @@ 2008-07-24 Basile Starynkevitch <basile@starynkevitch.net> + * basilys.h: added basilys_dlsym_all because ltdl.h has no RTLD_GLOBAL equivalent. + + * basilys.c: (basilys_dlsym_all) new function. + (load_checked_dylib) fill the vector of dlhandle-s. + (basilys_dynobjstruct_fieldoffset_at, basilys_dynobjstruct_classlength_at) use basilys_dlsym_all. + + * Makefile.in: added support for warm-*-d.so + +2008-07-24 Basile Starynkevitch <basile@starynkevitch.net> [adding dynamic fields offsets & class length] * basilys.c: (basilys_dynobjstruct_fieldoffset_at, diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 3bf217a7964..ed8b4175cfa 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -4780,6 +4780,8 @@ warm%.so: warm%.c built-melt-cc-script warm%-n.so : warm%.c built-melt-cc-script ./built-melt-cc-script -DMELTGCC_NOLINENUMBERING $< $@ +warm%-d.so : warm%.c built-melt-cc-script + ./built-melt-cc-script -d $< $@ warmelt-%-0.so: $(srcdir)/warmelt-%-0.c built-melt-cc-script ./built-melt-cc-script $< $@ @@ -4803,7 +4805,9 @@ WARMELT_BASELIST:=$(shell echo $(WARMELT_BASE)|sed 's: :,:g') WARMELT_BASE0= $(patsubst %, %-0, $(WARMELT_BASE)) WARMELT_BASE0C= $(patsubst %, %-0.c, $(WARMELT_BASE)) WARMELT_BASE0SO= $(patsubst %, %-0.so, $(WARMELT_BASE)) +WARMELT_BASE0DSO= $(patsubst %, %-0-d.so, $(WARMELT_BASE)) WARMELT_BASE0ROW:=$(shell echo $(WARMELT_BASE0)|sed 's/ /:/g') +WARMELT_BASE0DROW:=$(shell echo $(patsubst %, %-0-d, $(WARMELT_BASE))|sed 's/ /:/g') ## WARMELT_BASE1= $(patsubst %, %-1, $(WARMELT_BASE)) WARMELT_BASE1SO= $(patsubst %, %-1.so, $(WARMELT_BASE)) @@ -4829,7 +4833,7 @@ warmelt-%.so: warmelt-%.c built-melt-cc-script echo Melt building $@ from $< ./built-melt-cc-script $< $@ -warmelt0.modlis: $(WARMELT_BASE0SO) +warmelt0.modlis: $(WARMELT_BASE0DSO) date +"#$@ generated %c" > $@-tmp for f in $(WARMELT_BASE0); do echo $$f >> $@-tmp; done $(SHELL) $(srcdir)/../move-if-change $@-tmp $@ @@ -4846,24 +4850,24 @@ warmelt1.modlis: $(WARMELT_BASE1SO) ### warmelt*0.c files from SVN repository but warmelt-macro-1 is build ### using wamelt-first-1.so -warmelt-first-1.c: $(srcdir)/melt/warmelt-first.bysl warmelt0.modlis cc1$(exeext) $(WARMELT_BASE0SO) +warmelt-first-1.c: $(srcdir)/melt/warmelt-first.bysl warmelt0.modlis cc1$(exeext) $(WARMELT_BASE0DSO) -rm -f $@ @echo generating warmelt-first using $(WARMELT_BASE0) - @echo WARMELT_BASE0= $(WARMELT_BASE0) WARMELT_BASE0ROW= $(WARMELT_BASE0ROW) - $(MELTBASILYSCCINIT1) -fbasilys-init=$(WARMELT_BASE0ROW) \ + @echo WARMELT_BASE0= $(WARMELT_BASE0) WARMELT_BASE0ROW= $(WARMELT_BASE0DROW) + $(MELTBASILYSCCINIT1) -fbasilys-init=$(WARMELT_BASE0DROW) \ -fbasilys-arg=$< \ -fbasilys-secondarg=$@ ls -l $@ warmelt-macro-1.c: $(srcdir)/melt/warmelt-macro.bysl cc1$(exeext) \ warmelt-first-1.so \ - warmelt-macro-0.so \ - warmelt-normal-0.so \ - warmelt-genobj-0.so \ - warmelt-outobj-0.so + warmelt-macro-0-d.so \ + warmelt-normal-0-d.so \ + warmelt-genobj-0-d.so \ + warmelt-outobj-0-d.so -rm -f $@ $(MELTBASILYSCCFILE1) \ - -fbasilys-init=warmelt-first-1:warmelt-macro-0:warmelt-normal-0:warmelt-genobj-0:warmelt-outobj-0 \ + -fbasilys-init=warmelt-first-1:warmelt-macro-0-d:warmelt-normal-0-d:warmelt-genobj-0-d:warmelt-outobj-0-d \ -fbasilys-arg=$< \ -fbasilys-secondarg=$@ ls -l $@ @@ -4871,12 +4875,12 @@ warmelt-macro-1.c: $(srcdir)/melt/warmelt-macro.bysl cc1$(exeext) \ warmelt-normal-1.c: $(srcdir)/melt/warmelt-normal.bysl cc1$(exeext) \ warmelt-first-1.so \ warmelt-macro-1.so \ - warmelt-normal-0.so \ - warmelt-genobj-0.so \ - warmelt-outobj-0.so + warmelt-normal-0-d.so \ + warmelt-genobj-0-d.so \ + warmelt-outobj-0-d.so -rm -f $@ $(MELTBASILYSCCFILE1) \ - -fbasilys-init=warmelt-first-1:warmelt-macro-1:warmelt-normal-0:warmelt-genobj-0:warmelt-outobj-0 \ + -fbasilys-init=warmelt-first-1:warmelt-macro-1:warmelt-normal-0-d:warmelt-genobj-0-d:warmelt-outobj-0-d \ -fbasilys-arg=$< \ -fbasilys-secondarg=$@ ls -l $@ @@ -4885,11 +4889,11 @@ warmelt-genobj-1.c: $(srcdir)/melt/warmelt-genobj.bysl cc1$(exeext) \ warmelt-first-1.so \ warmelt-macro-1.so \ warmelt-normal-1.so \ - warmelt-genobj-0.so \ - warmelt-outobj-0.so + warmelt-genobj-0-d.so \ + warmelt-outobj-0-d.so -rm -f $@ $(MELTBASILYSCCFILE1) \ - -fbasilys-init=warmelt-first-1:warmelt-macro-1:warmelt-normal-1:warmelt-genobj-0:warmelt-outobj-0 \ + -fbasilys-init=warmelt-first-1:warmelt-macro-1:warmelt-normal-1:warmelt-genobj-0-d:warmelt-outobj-0-d \ -fbasilys-arg=$< \ -fbasilys-secondarg=$@ ls -l $@ @@ -4899,10 +4903,10 @@ warmelt-outobj-1.c: $(srcdir)/melt/warmelt-outobj.bysl cc1$(exeext) \ warmelt-macro-1.so \ warmelt-normal-1.so \ warmelt-genobj-1.so \ - warmelt-outobj-0.so + warmelt-outobj-0-d.so -rm -f $@ $(MELTBASILYSCCFILE1) \ - -fbasilys-init=warmelt-first-1:warmelt-macro-1:warmelt-normal-1:warmelt-genobj-1:warmelt-outobj-0 \ + -fbasilys-init=warmelt-first-1:warmelt-macro-1:warmelt-normal-1:warmelt-genobj-1:warmelt-outobj-0-d \ -fbasilys-arg=$< \ -fbasilys-secondarg=$@ ls -l $@ diff --git a/gcc/basilys.c b/gcc/basilys.c index 52598ed8a4f..6b2ca6ad9d4 100644 --- a/gcc/basilys.c +++ b/gcc/basilys.c @@ -1001,8 +1001,7 @@ forwarded_copy (basilys_ptr_t p) dst->entab = (struct entrybasicblocksbasilys_st *) ggc_alloc_cleared (siz * sizeof - (dst-> - entab + (dst->entab [0])); memcpy (dst->entab, src->entab, siz * sizeof (dst->entab[0])); } @@ -1453,15 +1452,15 @@ unsafe_index_mapobject (struct entryobjectsbasilys_st *tab, samehashcnt, (void *) attr, attr->obj_serial, (void *) curat, curat->obj_serial, curat->obj_hash, (void *) curat->obj_class, - basilys_string_str (curat-> - obj_class->obj_vartab[FNAMED_NAME])); + basilys_string_str (curat->obj_class-> + obj_vartab[FNAMED_NAME])); if (basilys_is_instance_of ((basilys_ptr_t) attr, (basilys_ptr_t) BASILYSGOB (CLASS_NAMED))) dbgprintf ("gotten attr named %s found attr named %s", basilys_string_str (attr->obj_vartab[FNAMED_NAME]), - basilys_string_str (curat->obj_vartab - [FNAMED_NAME])); + basilys_string_str (curat-> + obj_vartab[FNAMED_NAME])); basilys_dbgshortbacktrace ("gotten & found attr of same hash & class", 15); } @@ -1498,15 +1497,15 @@ unsafe_index_mapobject (struct entryobjectsbasilys_st *tab, samehashcnt, (void *) attr, attr->obj_serial, (void *) curat, curat->obj_serial, curat->obj_hash, (void *) curat->obj_class, - basilys_string_str (curat-> - obj_class->obj_vartab[FNAMED_NAME])); + basilys_string_str (curat->obj_class-> + obj_vartab[FNAMED_NAME])); if (basilys_is_instance_of ((basilys_ptr_t) attr, (basilys_ptr_t) BASILYSGOB (CLASS_NAMED))) dbgprintf ("gotten attr named %s found attr named %s", basilys_string_str (attr->obj_vartab[FNAMED_NAME]), - basilys_string_str (curat->obj_vartab - [FNAMED_NAME])); + basilys_string_str (curat-> + obj_vartab[FNAMED_NAME])); basilys_dbgshortbacktrace ("gotten & found attr of same hash & class", 15); } @@ -4434,12 +4433,21 @@ compile_to_dyl (const char *srcfile, const char *dlfile) } +/* we need a vector of dlhandle-s to scan every loaded dylib, because + libtool does not have the equivalent of RTLD_GLOBAL in dlopen */ +typedef struct lt_dlhandle_struct *lt_dlhandle; /* to keep gengtype happy, copied from ltdl.h */ + +DEF_VEC_P (lt_dlhandle); +DEF_VEC_ALLOC_P (lt_dlhandle, heap); + +static +VEC (lt_dlhandle, heap) * + modhdvec = 0; /* load a dynamic library using the filepath DYPATH; if MD5SRC is given, check that the basilys_md5 inside is indeed MD5SRC, otherwise return NULL */ -static lt_dlhandle -load_checked_dylib (const char *dypath, char *md5src) + static lt_dlhandle load_checked_dylib (const char *dypath, char *md5src) { lt_dlhandle dlh = NULL; char *dynmd5 = NULL; @@ -4474,6 +4482,7 @@ load_checked_dylib (const char *dypath, char *md5src) goto bad; } } + VEC_safe_push (lt_dlhandle, heap, modhdvec, dlh); debugeprintf ("load_checked_dylib dypath %s dynmd5 %s dyncomptimstamp %s", dypath, dynmd5, dyncomptimstamp); return dlh; @@ -4482,6 +4491,20 @@ bad: return NULL; } +void * +basilys_dlsym_all (const char *nam) +{ + int ix = 0; + lt_dlhandle h = 0; + for (ix = 0; VEC_iterate (lt_dlhandle, modhdvec, ix, h); ix++) + { + void *p = (void *) lt_dlsym (h, nam); + if (p) + return p; + }; + return (void *) lt_dlsym (proghandle, nam); +} + /* compile (as a dynamically loadable module) some (usually generated) C code (or a dynamically loaded stuff) and dynamically load it; the @@ -6167,6 +6190,7 @@ basilys_initialize (void) const char *randomseed = 0; if (inited) return; + modhdvec = VEC_alloc (lt_dlhandle, heap, 30); proghandle = lt_dlopen (NULL); if (!proghandle) fatal_error ("basilys failed to get whole program handle - %s", @@ -6247,7 +6271,7 @@ basilys_dynobjstruct_fieldoffset_at (const char *fldnam, const char *fil, char *nam = 0; void *ptr = 0; nam = concat ("fieldoff__", fldnam, NULL); - ptr = lt_dlsym (proghandle, nam); + ptr = basilys_dlsym_all (nam); if (!ptr) fatal_error ("basilys failed to find field offset %s - %s (%s:%d)", nam, lt_dlerror (), fil, lin); @@ -6263,7 +6287,7 @@ basilys_dynobjstruct_classlength_at (const char *clanam, const char *fil, char *nam = 0; void *ptr = 0; nam = concat ("classlen__", clanam, NULL); - ptr = lt_dlsym (proghandle, nam); + ptr = basilys_dlsym_all (nam); if (!ptr) fatal_error ("basilys failed to find class length %s - %s (%s:%d)", nam, lt_dlerror (), fil, lin); diff --git a/gcc/basilys.h b/gcc/basilys.h index e7ded8f7f06..7d61f89ad0d 100644 --- a/gcc/basilys.h +++ b/gcc/basilys.h @@ -1369,7 +1369,7 @@ basilys_dynobjstruct_getfield_object_at (basilys_ptr_t ob, unsigned off, const c (int**)0) static inline void -basilys_dynobjstruct_putfield_object_at(basilys_ptr_t ob, unsigned off, basilys_ptr_t val, const char*msg, const char*fil, int lin, int**poff) +basilys_dynobjstruct_putfield_object_at(basilys_ptr_t ob, unsigned off, basilys_ptr_t val, const char*fldnam, const char*fil, int lin, int**poff) { if (poff && !*poff) *poff = basilys_dynobjstruct_fieldoffset_at(fldnam, fil, lin); @@ -1381,9 +1381,9 @@ basilys_dynobjstruct_putfield_object_at(basilys_ptr_t ob, unsigned off, basilys_ pob->obj_vartab[off] = val; return; } - fatal_error("checked dynamic field put failed (bad offset %d/%d [%s:%d]) - %s", (int)off, (int)pob->obj_len, fil, lin, msg?msg:"..."); + fatal_error("checked dynamic field put failed (bad offset %d/%d [%s:%d]) - %s", (int)off, (int)pob->obj_len, fil, lin, fldnam?fldnam:"..."); } - fatal_error("checked dynamic field put failed (not object [%s:%d]) - %s", fil, lin, msg?msg:"..."); + fatal_error("checked dynamic field put failed (not object [%s:%d]) - %s", fil, lin, fldnam?fldnam:"..."); } #define basilys_putfield_object_at(Obj,Off,Val,Fldnam,Fil,Lin) do { \ @@ -1966,6 +1966,9 @@ void basilys_initialize (void); /* finalize all */ void basilys_finalize (void); +/* find a symbol in all the loaded modules */ +void* basilys_dlsym_all(const char*nam); + /* returns malloc-ed path inside a temporary directory, with a given basename */ char* basilys_tempdir_path(const char* basnam); |