This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: ld-auto-import memory bug fixing


>
>
> > I know that gcc has support of basic block profiling. Could this
> used in anyway
> > to automated print out functions name on calling the relating functions ?
>
> With newer gcc's, you want:
>
>   -finstrument-functions  Instrument function entry/exit with profiling calls
>
> Older gcc's should have -pg (call graph counting).
>
> Either one should tell you which functions get called by which
> functions and how many times for each combination.
>
> You'll have to look the options up to see how to use them and which
> extra programs to run (gprof, gcov, etc) to get reports.
>
It seems to be to much overhead for this,because I need this in relating of used
memory,
so I'm trying to check manual which functions are involved.

... much debugging...

I have found that the currently mostly problem seems to be
pe_walk_relocs_of_symbol() like mentioned below.
To find this I have added some printfs before and
after any called function in ldemul.c and later in some subroutines.

pe_walk_relocs_of_symbol() seems to need about 4 MB for any auto imported
symbol,
so if there are 30 vars to import it needs 120 MB. :-(((

This depends on the number of used libs and there are many libs in the test case
( 
look at the link line below) 

BTW: Can anyone tell me, what pe_find_data_imports () and pe_walk_relocs_of_symbol() really do ? 

What I have seen, is that pe_walk_relocs_of_symbol() goes through every input bfd, 
that means through all loaded libs and object files and read the relating symbol table 
and relocation data and make something with it. The relocation data are freed, 
but the symbol table not. That is the problem. 

Perhaps it is possible to load the symbols table only if not already done and cache the pointer as 
read every loop again. (1) 

A note says 
	  /* Warning: the allocated symbols are remembered in BFD and reused
	     later, so don't free them! */
This makes me some headache, because I don't know where to look and if (1) is really a possible solution. 
Additional if the symbols are rembered in BFD, why should they allocated every time again ???

Any suggestions welcome. 

void
pe_walk_relocs_of_symbol (info, name, cb)
     struct bfd_link_info *info;
     CONST char *name;
     int (*cb) (arelent *);
{
  bfd *b;
  struct sec *s;
	
  for (b = info->input_bfds; b; b = b->link_next)
    {
      arelent **relocs;
      int relsize, nrelocs, i;

      for (s = b->sections; s; s = s->next)
	{
	  asymbol **symbols;
	  int nsyms, symsize;
	  int flags = bfd_get_section_flags (b, s);

	  /* Skip discarded linkonce sections */
	  if (flags & SEC_LINK_ONCE
	      && s->output_section == bfd_abs_section_ptr)
	    continue;

	  current_sec=s;

	  symsize = bfd_get_symtab_upper_bound (b);
	  symbols = (asymbol **) xmalloc (symsize);
	  nsyms = bfd_canonicalize_symtab (b, symbols);

	  relsize = bfd_get_reloc_upper_bound (b, s);
	  relocs = (arelent **) xmalloc ((size_t) relsize);
	  nrelocs = bfd_canonicalize_reloc (b, s, relocs, symbols);

	  for (i = 0; i < nrelocs; i++)
	    {
	      struct symbol_cache_entry *sym = *relocs[i]->sym_ptr_ptr;
	      if (!strcmp(name,sym->name)) cb(relocs[i]);
	    }
	  free (relocs);
	  /* Warning: the allocated symbols are remembered in BFD and reused
	     later, so don't free them! */
	  /* free (symbols); */
	}
    }
}

<snip>
ld logging 
stage: ldemul_open_dynamic_archive - END
stage: ldemul_open_dynamic_archive - START
stage: ldemul_open_dynamic_archive - END
stage: ldemul_open_dynamic_archive - START
stage: ldemul_open_dynamic_archive - END
stage: ldemul_open_dynamic_archive - START
        gld_i386pe_open_dynamic_archive: archive name=/usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5/libgcc.a
stage: ldemul_open_dynamic_archive - END
stage: ldemul_recognized_file - START
stage: ldemul_recognized_file - END
stage: ldemul_after_open - START
Warning: resolving _qt_x_time by linking to __imp__qt_x_time (auto-import)
stage: pe_walk_relocs_of_symbol - START
      
  pe_walk_relocs_of_symbol: malloc = 4090408
stage: pe_walk_relocs_of_symbol - END
Warning: resolving __12QApplication$focus_widget by linking to
__imp___12QApplication$focus_widget (auto-import)
stage: pe_walk_relocs_of_symbol - START
        pe_walk_relocs_of_symbol: malloc = 4090604
stage: pe_walk_relocs_of_symbol - END
Warning: resolving _qApp by linking to __imp__qApp (auto-import)
stage: pe_walk_relocs_of_symbol - START
        pe_walk_relocs_of_symbol: malloc = 4090920
stage: pe_walk_relocs_of_symbol - END
Warning: resolving _qt_wm_protocols by linking to __imp__qt_wm_protocols
(auto-import)
stage: pe_walk_relocs_of_symbol - START
        pe_walk_relocs_of_symbol: malloc = 4090996
stage: pe_walk_relocs_of_symbol - END
Warning: resolving _qt_wm_take_focus by linking to __imp__qt_wm_take_focus
(auto-import)
stage: pe_walk_relocs_of_symbol - START
        pe_walk_relocs_of_symbol: malloc = 4091032
stage: pe_walk_relocs_of_symbol - END
Warning: resolving _qt_wm_delete_window by linking to __imp__qt_wm_delete_window
(auto-import)
stage: pe_walk_relocs_of_symbol - START
        pe_walk_relocs_of_symbol: malloc = 4091068
stage: pe_walk_relocs_of_symbol - END



$ /bin/ld --shared -Bdynamic -e __cygwin_dll_entry@12 --dll-search-prefix=cyg -o
.libs/cygkdeui-3.dll -L/home/habacker/
tmp/kde/anoncvs.kde.org/kdelibs/dcop/KDE-ICE/.libs -L/opt/kde2/lib -L/home/habac
ker/tmp/kde/anoncvs.kde.org/kdelibs/dco
p/.libs -L/usr/X11R6/lib -L/usr/lib/qt2/lib -L/usr/local/lib -L/usr/lib -L/usr/l
ib/w32api -L/usr/lib/gcc-lib/i686-pc-cy
gwin/2.95.3-5 -L/usr/lib/gcc-lib/i686-pc-cygwin/2.95.3-5/../../../../i686-pc-cyg
win/lib --enable-auto-import --export-a
ll-symbols --whole-archive .libs/qxembed.o .libs/ksharedpixmap.o
.libs/kthemestyle.o .libs/kurllabel.o .libs/knuminput.
o .libs/ktoolbar.o .libs/klineedit.o .libs/klistview.o .libs/kprogress.o
.libs/kimageeffect.o .libs/kcolordlg.o .libs/k
select.o .libs/kdatepik.o .libs/kdatetbl.o .libs/kfontdialog.o
.libs/kpopupmenu.o .libs/ktabctl.o .libs/kstatusbar.o .l
ibs/kmainwindow.o .libs/ktmainwindow.o .libs/kmenubar.o .libs/kpixmapio.o
.libs/keditlistbox.o .libs/kseparator.o .libs
/krestrictedline.o .libs/kcolorbtn.o .libs/ksystemtray.o .libs/kbuttonbox.o
.libs/keditcl1.o .libs/keditcl2.o .libs/kle
d.o .libs/kdbtn.o .libs/kwizard.o .libs/kcontainer.o .libs/kkeydialog.o
.libs/kruler.o .libs/kcursor.o .libs/kaccelmenu
.o .libs/klineeditdlg.o .libs/kthemebase.o .libs/kcharselect.o
.libs/kcolordrag.o .libs/knumvalidator.o .libs/kdialog.o
 .libs/kdialogbase.o .libs/kjanuswidget.o .libs/kaboutdialog.o
.libs/kpixmapeffect.o .libs/kauthicon.o .libs/kmessagebo
x.o .libs/kdualcolorbtn.o .libs/ktoolbarradiogroup.o .libs/ktoolbarbutton.o
.libs/ktextbrowser.o .libs/kaction.o .libs/
khelpmenu.o .libs/kcmenumngr.o .libs/kpanelmenu.o .libs/kstdaction.o
.libs/kdrawutil.o .libs/kiconview.o .libs/klistbox
.o .libs/kbugreport.o .libs/kcombobox.o .libs/kpassdlg.o .libs/kxmlguiclient.o
.libs/kxmlgui.o .libs/kxmlguibuilder.o .
libs/kedittoolbar.o .libs/kdocktabctl.o .libs/kdockwidget.o
.libs/kdockwidget_private.o .libs/kanimwidget.o .libs/kroot
pixmap.o .libs/kaboutkde.o .libs/kaboutapplication.o .libs/kpanelapplet.o
.libs/kdcopactionproxy.o .libs/kcolorcombo.o
.libs/kpushbutton.o .libs/kpanelextension.o .libs/kcompletionbox.o
.libs/kalphapainter.o .libs/ksqueezedtextlabel.o .li
bs/kcommand.o .libs/kwindowlistmenu.o .libs/kfontcombo.o .libs/ktip.o
.libs/kdatewidget.o .libs/karrowbutton.o .libs/li
bkdeui_la_meta_unload.o --no-whole-archive -lcygwin
../kdecore/.libs/libkdecore.dll.a /home/habacker/tmp/kde/anoncvs.kd
e.org/kdelibs/dcop/.libs/libDCOP.dll.a
/home/habacker/tmp/kde/anoncvs.kde.org/kdelibs/dcop/KDE-ICE/.libs/libkICE.dll.a
-lqt -lpng -lz -ljpeg -lXext -lX11 -lipc -lSM -lICE --out-implib
.libs/libkdeui.dll.a -lstdc++ -lgcc -lcygwin -luser32
-lkernel32 -ladvapi32 -lshell32 -lgcc --enable-extra-pe-debug --enable-extra-pe-
debug


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]