This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[committed] Revamp handling of initialization functions on hppa64-hpux
- From: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 9 Apr 2006 14:54:39 -0400 (EDT)
- Subject: [committed] Revamp handling of initialization functions on hppa64-hpux
The enclosed patch changes the technique for handling initialization
functions such as __register_frame_info on hppa*64*-*-hpux*. The
problem is that in HP land undefined weak symbols have to be defined
or else the dynamic loader refuses to run an application. A secondary
problem is that a strong definition does not replace a previous weak
definition. The HP linker will resolve a weak symbol using both
archive and shared libraries, while the GNU linker only resolves
weak symbols from shared libraries.
So, I've decided to remove '__attribute__ ((weak))' from
TARGET_ATTRIBUTE_WEAK and add an archive library of stub functions
that is linked in last after libgcc. I've also removed the stub
definitions for __cxa_finalize and _Jv_RegisterClasses from the
crtbegin*.o objects as they couldn't be overloaded.
The patch also fixes a typo in LIB_SPEC (PR target/27034).
Tested on hppa64-hp-hpux11.11 with both GNU ld and HP ld.
Committed to trunk and 4.1.
Dave
--
J. David Anglin dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada (613) 990-0752 (FAX: 952-6602)
2006-04-09 John David Anglin <dave.anglin@nrc-cnrc.gc.ca>
PR target/27034
PR target/26508
* config.gcc (hppa*64*-*-hpux11*): Add 'libgcc_stub.a' to extra_parts.
* pa64-hpux.h (LIB_SPEC): Correct typo. Don't append milli.a.
(LINK_GCC_C_SEQUENCE_SPEC): Define. Append milli.a here.
(PA_CXA_FINALIZE_STUB, PA_JV_REGISTERCLASSES_STUB): Delete defines.
(PA_INIT_FINI_HACK): Rename to PA_CRTBEGIN_HACK.
(PA_CRTBEGIN_HACK): Ensure __do_global_ctors_aux is placed in text
section. Delete PA_CXA_FINALIZE_STUB and PA_JV_REGISTERCLASSES_STUB
stubs. Add ".align 8" directives before all ".dword" directives.
(GTHREAD_USE_WEAK): Revise comment.
(TARGET_ATTRIBUTE_WEAK): Define.
* pa/t-pa64 (LIBGCCSTUB_OBJS): Add new rules for stublib.c, rfi-stub.o,
dfi-stub.o, cxaf-stub.o and jvrc-stub.o.
* stublib.c: New file.
Index: config.gcc
===================================================================
--- config.gcc (revision 112778)
+++ config.gcc (working copy)
@@ -967,7 +967,8 @@
else
tmake_file="$tmake_file pa/t-slibgcc-dwarf-ver"
fi
- extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o crtbeginT.o"
+ extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o crtbeginT.o \
+ libgcc_stub.a"
case x${enable_threads} in
xyes | xposix )
thread_file=posix
Index: config/pa/pa64-hpux.h
===================================================================
--- config/pa/pa64-hpux.h (revision 112778)
+++ config/pa/pa64-hpux.h (working copy)
@@ -63,22 +63,26 @@
%{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
%{pg:%{static:%{!mhp-ld:-a shared}%{mhp-ld:-a archive_shared}}\
-lgprof %{static:-a archive} %{static|mt|pthread:-lpthread} -lc\
- %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
- /usr/lib/pa20_64/milli.a"
+ %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}"
#else
#define LIB_SPEC \
"%{!shared:\
%{!p:%{!pg: %{static|mt|pthread:-lpthread} -lc\
%{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
%{p:%{!pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
- -lprof %{static:-a archive} %{shatic|mt|pthread:-lpthread} -lc\
+ -lprof %{static:-a archive} %{static|mt|pthread:-lpthread} -lc\
%{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
%{pg:%{static:%{mgnu-ld:-a shared}%{!mgnu-ld:-a archive_shared}}\
-lgprof %{static:-a archive} %{static|mt|pthread:-lpthread} -lc\
- %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}\
- /usr/lib/pa20_64/milli.a"
+ %{static:%{!nolibdld:-a shared -ldld -a archive -lc}}}}"
#endif
+/* The libgcc_stub.a and milli.a libraries need to come last. */
+#undef LINK_GCC_C_SEQUENCE_SPEC
+#define LINK_GCC_C_SEQUENCE_SPEC "\
+ %G %L %G %{!nostdlib:%{!nodefaultlibs:%{!shared:-lgcc_stub}\
+ /usr/lib/pa20_64/milli.a}}"
+
/* Under hpux11, the normal location of the `ld' and `as' programs is the
/usr/ccs/bin directory. */
@@ -326,16 +330,7 @@
the array. DT_FINI_ARRAY is supposed to be executed in the opposite
order.
- The second hack is stubs for __cxa_finalize and _Jv_RegisterClasses.
- The HP implementation of undefined weak symbols is broken. The linker
- and dynamic loader both search for undefined weak symbols contrary the
- generic System V ABI. An undefined weak symbol should resolve to a
- value of 0 rather than causing an error. The prototypes for
- __cxa_finalize and _Jv_RegisterClasses in crtstuff.c are weak when
- weak is supported (GNU as), so in theory a strong define should override
- the stub functions provided here.
-
- The final hack is a set of plabels to implement the effect of
+ The second hack is a set of plabels to implement the effect of
CRT_CALL_STATIC_FUNCTION. HP-UX 11 only supports DI_INIT_ARRAY and
DT_FINI_ARRAY and they put the arrays in .init and .fini, rather than
in .init_array and .fini_array. The standard defines for .init and
@@ -351,25 +346,6 @@
either using the linker +init command or a plabel, run before the
initializers specified here. */
-/* We need a __cxa_finalize stub if CRTSTUFFS_O is defined. */
-#ifdef CRTSTUFFS_O
-#define PA_CXA_FINALIZE_STUB \
-extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK; \
-void \
-__cxa_finalize (void *p __attribute__((unused))) {}
-#else
-#define PA_CXA_FINALIZE_STUB
-#endif
-
-/* We need a _Jv_RegisterClasses stub if JCR_SECTION_NAME is defined. */
-#ifdef JCR_SECTION_NAME
-#define PA_JV_REGISTERCLASSES_STUB \
-void \
-_Jv_RegisterClasses (void *p __attribute__((unused))) {}
-#else
-#define PA_JV_REGISTERCLASSES_STUB
-#endif
-
/* We need to add frame_dummy to the initializer list if EH_FRAME_SECTION_NAME
or JCR_SECTION_NAME is defined. */
#if defined(EH_FRAME_SECTION_NAME) || defined(JCR_SECTION_NAME)
@@ -378,7 +354,10 @@
#define PA_INIT_FRAME_DUMMY_ASM_OP ""
#endif
-#define PA_INIT_FINI_HACK \
+/* The following hack sets up the .init, .init_array, .fini and
+ .fini_array sections. */
+#define PA_CRTBEGIN_HACK \
+asm (TEXT_SECTION_ASM_OP); \
static void __attribute__((used)) \
__do_global_ctors_aux (void) \
{ \
@@ -389,35 +368,36 @@
(*p) (); \
} \
\
-PA_CXA_FINALIZE_STUB \
-PA_JV_REGISTERCLASSES_STUB \
- \
asm (HP_INIT_ARRAY_SECTION_ASM_OP); \
+asm (".align 8"); \
asm (".dword P%__do_global_ctors_aux"); \
asm (PA_INIT_FRAME_DUMMY_ASM_OP); \
asm (GNU_INIT_ARRAY_SECTION_ASM_OP); \
+asm (".align 8"); \
asm (".dword P%__do_global_ctors_aux"); \
asm (PA_INIT_FRAME_DUMMY_ASM_OP); \
asm (HP_FINI_ARRAY_SECTION_ASM_OP); \
+asm (".align 8"); \
asm (".dword P%__do_global_dtors_aux"); \
asm (GNU_FINI_ARRAY_SECTION_ASM_OP); \
+asm (".align 8"); \
asm (".dword P%__do_global_dtors_aux")
/* The following two variants of DTOR_LIST_BEGIN are identical to those
- in crtstuff.c except for the addition of the above init-fini hack. */
+ in crtstuff.c except for the addition of the above crtbegin hack. */
#ifdef DTORS_SECTION_ASM_OP
#define DTOR_LIST_BEGIN \
asm (DTORS_SECTION_ASM_OP); \
STATIC func_ptr __DTOR_LIST__[1] \
__attribute__ ((aligned(sizeof(func_ptr)))) \
= { (func_ptr) (-1) }; \
-PA_INIT_FINI_HACK
+PA_CRTBEGIN_HACK
#else
#define DTOR_LIST_BEGIN \
STATIC func_ptr __DTOR_LIST__[1] \
__attribute__ ((section(".dtors"), aligned(sizeof(func_ptr)))) \
= { (func_ptr) (-1) }; \
-PA_INIT_FINI_HACK
+PA_CRTBEGIN_HACK
#endif
/* If using HP ld do not call pxdb. Use size as a program that does nothing
@@ -425,6 +405,15 @@
an interpreter. */
#define INIT_ENVIRONMENT "LD_PXDB=/usr/ccs/bin/size"
-/* The HPUX dynamic linker objects to weak symbols with no
- definitions, so do not use them in gthr-posix.h. */
+/* The HPUX dynamic linker objects to undefined weak symbols, so do
+ not use them in gthr-posix.h. */
#define GTHREAD_USE_WEAK 0
+
+/* We don't want undefined weak references to __register_frame_info,
+ __deregister_frame_info, _Jv_RegisterClasses and __cxa_finalize
+ introduced by crtbegin.o. The GNU linker only resolves weak
+ references if they appear in a shared library. Thus, it would be
+ impossible to create a static executable if the symbols were weak.
+ So, the best solution seems to be to make the symbols strong and
+ provide an archive library of empty stub functions. */
+#define TARGET_ATTRIBUTE_WEAK
Index: config/pa/t-pa64
===================================================================
--- config/pa/t-pa64 (revision 112778)
+++ config/pa/t-pa64 (working copy)
@@ -1,2 +1,28 @@
-TARGET_LIBGCC2_CFLAGS = -fPIC -Dpa64=1 -DELF=1 -mlong-calls
-LIB2FUNCS_EXTRA=quadlib.c
+TARGET_LIBGCC2_CFLAGS = -fPIC -Dpa64=1 -DELF=1 -mlong-calls
+LIB2FUNCS_EXTRA = quadlib.c
+LIBGCCSTUB_OBJS = rfi-stub.o dfi-stub.o jvrc-stub.o cxaf-stub.o
+
+stublib.c: $(srcdir)/config/pa/stublib.c
+ rm -f stublib.c
+ cp $(srcdir)/config/pa/stublib.c .
+
+rfi-stub.o: stublib.c
+ $(GCC_FOR_TARGET) -c -O2 -DL_register_frame_info stublib.c \
+ -o rfi-stub.o
+
+dfi-stub.o: stublib.c
+ $(GCC_FOR_TARGET) -c -O2 -DL_deregister_frame_info stublib.c \
+ -o dfi-stub.o
+
+cxaf-stub.o: stublib.c
+ $(GCC_FOR_TARGET) -c -O2 -DL_cxa_finalize stublib.c \
+ -o cxaf-stub.o
+
+jvrc-stub.o: stublib.c
+ $(GCC_FOR_TARGET) -c -O2 -DL_Jv_RegisterClasses stublib.c \
+ -o jvrc-stub.o
+
+libgcc_stub.a: $(LIBGCCSTUB_OBJS)
+ -rm -rf libgcc_stub.a
+ $(AR) rc libgcc_stub.a $(LIBGCCSTUB_OBJS)
+ $(RANLIB) libgcc_stub.a
--- /dev/null Sun Apr 2 16:48:13 2006
+++ config/pa/stublib.c Sun Apr 2 15:56:37 2006
@@ -0,0 +1,63 @@
+/* Stub functions.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING. If not, write to
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+#ifdef L_register_frame_info
+struct object;
+void __register_frame_info (const void * __attribute__((unused)),
+ struct object * __attribute__((unused)));
+void
+__register_frame_info (const void *p, struct object *ob)
+{
+}
+#endif
+
+#ifdef L_deregister_frame_info
+void *__deregister_frame_info (const void * __attribute__((unused)));
+void *
+__deregister_frame_info (const void *p)
+{
+ return (void *)0;
+}
+#endif
+
+#ifdef L_cxa_finalize
+void __cxa_finalize (void * __attribute__((unused)));
+void
+__cxa_finalize (void *p)
+{
+}
+#endif
+
+#ifdef L_Jv_RegisterClasses
+void _Jv_RegisterClasses (void * __attribute__((unused)));
+void
+_Jv_RegisterClasses (void *p)
+{
+}
+#endif