An egcs 1.1.2 patch for frame.h and crtstuff.c

Jeffrey A Law
Sun Feb 28 18:15:00 GMT 1999

  In message < >you write:
  > Thu Feb 25 11:25:13 1999  H.J. Lu  (
  > 	* frame.h (TARGET_ATTRIBUTE_WEAK): New. Use __attribute__ only
  > 	if SUPPORTS_WEAK is not zero and IN_CRTSTUFF is defined.
  > 	(__register_frame_info): Append TARGET_ATTRIBUTE_WEAK.
  > 	(__deregister_frame_info): Likewise.
  > 	* crtstuff.c (IN_CRTSTUFF): Defined before #include "frame.h".
  > 	(__do_global_dtors_aux): Check if __deregister_frame_info is
  > 	zero before calling it.
  > 	(__do_global_dtors): Likewise.
  > 	(frame_dummy): Check if __register_frame_info is zero before
  > 	calling it.
  > 	(__frame_dummy): Likewise.
Thanks.  I was actually ready to install this into the release branch --
then I changed my mind.

The IN_CRTSTUFF approach seems like a reasonable way to conditionalize the
definition of TARGET_ATTRIBUTE_WEAK.  But when I started thinking about how
this code would work in the mainline tree, specifically to replace the
pragma uses in the thread files and maybe one day other things, it occurred to
me that it will not scale well.

The core and fundamental problem is the declaration in a common header file
is used to provide information for both uses and definitions of the the

Normally that is a good thing; however in the case of weak it is a major

The other approach would be to have a second function declaration in the
file where we actually want the weak references.  This is similar to how
your original patch with #pragma weak worked, except that we have duplicated
function declarations.

Normally I think such duplication is bad (maintenance issues), but then it
occurred to me that the functions we're most interested in making weak
references are functions we're exporting out of libgcc.  And given the
realities surrounding shared libraries, the interface of such functions needs
to be unchanging.

So while the second declaration isn't pretty, it really doesn't add any
maintenance burden since the interface of the functions in question is

So, for weak references, I think the way to go is to have a second
declaration of the weak function in the file where it is used.

For a weak definition we can put the weak attribute on the definition of
the function.

If we want both definitions and references to be weak, we put the attribute
on the declaration in the shared header file.

The net result for the release branch is the changes are isolated in
crtstuff.c, though I did add some comments in frame.h.

For the mainline tree, we'll put the TARGET_ATTRIBUTE_WEAK definition in
gansidecl.h, then use it in crtstuff and other locations as needed.

I'll take care of both trees shortly.


ps.  Another possibility would be to have a weak attribute that applies to
definitions, another that applies to references and a third that applies to
both.  I didn't implement this, though it might be the best solution long

pps. To verify that it actually works:

objdump --syms crtbegin.o
[ ... ]
00000000  w      *UND*  00000000 __deregister_frame_info
00000000  w      *UND*  00000000 __register_frame_info

objdump --syms frame.o
[ ... ]
00000a08 g     F .text  00000049 __register_frame_info
00000b04 g     F .text  00000057 __deregister_frame_info

More information about the Gcc-patches mailing list