This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC compile models -- theory of operation?
"Jonathan S. Shapiro" <shap@eros-os.com> writes:
> On Fri, 2007-08-03 at 11:06 -0400, Daniel Jacobowitz wrote:
> > crtbeginT.o is used for -static; crtbegin.o is used without -static.
> > I don't recall why they have to be different.
>
> So far as we can tell from looking at the linux versions, the only
> difference is that crtbeginT is calling
>
> register_frame_info_bases
> deregister_frame_info_bases
>
> I suspect that these are related to the exception frame walker, because
> if --static (therefore crtbeginT) is provided then --eh-frame-header is
> not applied by default. That is: I suspect that --static does not
> support exception frame walking. This smells like a Linux legacy issue
> that may not apply to us. Can anybody confirm or correct that guess?
If you pass --eh-frame-header to the linker, it will create a
PT_GNU_EH_FRAME segment in the output file. The code in
gcc/unwind-dw2-fde-glibc.c will locate that segment by using
dl_iterate_phdr. dl_iterate_phdr is provided by glibc. At one time
it only worked for dynamically linked binaries, but I believe that it
currently also works for statically linked binaries. So I believe
that in principle it would now be possible to use --eh-frame-header
and unwind-dw2-fde-glibc.c with statically linked binaries. But I
haven't actually tried.
In order for you to use --eh-frame-header, your libc will need to
provide dl_iterate_phdr. The advantage of this approach is that it
does not require registering the exceptions at program start time,
thus saving a bit of startup time. Also, if everything works
correctly, the linker will create a sorted list of FDEs, which will
permit faster lookup of the required stack unwinding information when
an exception occurs.
If you don't have dl_iterate_phdr, then you will need to call
register_frame_info_bases at startup time. And you won't want to use
--eh-frame-header.
All of this is completely ELF specific, by the way.
Ian