How to list all symbolic names for references to global varibables and functions with objdump (for MIPS arch)?
Nick Clifton
nickc@redhat.com
Thu Dec 4 11:19:00 GMT 2008
Hi Pan,
> Support for .init sections means the kernel allocates pages from the
> init sections when the programs are loaded and being initialized. And
> after initialization is finished, the kernel reclaims the pages for
> init sections. This can reduce memory requirements significantly for
> an embedded system.
Ah - OK - I understand now. It sounds like what you really want to do
is to hook into the linker's section-garbage-collection mechanism. This
currently allows the linker to find functions which are never used and
throw them away, (providing that the program has been compiled with
gcc's -ffunction-section command line option).
What you want to do is to augment the current code so that any function
which is used by which is not referenced via the program's entry
point(*) is placed into a special segment which the loader knows it can
discard after the initialization routines have been run.
Cheers
Nick
(*) Actually you will also have to consider termination routines as well
(C++ deconstructors, .fini sections etc). These may also invoke
functions in the program which are not referenced via the entry point,
but which need to be present when the program exits. Possibly your
kernel will have to reload the segment containing the init routines.
Although if the program is exiting because it has run out of memory this
might prove difficult to implement...
You know it might be a whole lot easier to abandon trying to make this
an automatic mechanism and instead require that the program's creator
annotate any only-used-during-init functions via some kind of attribute.
Eg if you specified that any such function had to be given a section
name attribute of .init.text say, then you could arrange for your linker
script to keep all code in this section separate from the normal .text
section and then your kernel could know to discard this section once it
is ready to invoke the program's entry point.
More information about the Binutils
mailing list