3.0.1 PATCH: Support #pragma weak on Tru64 UNIX
Rainer Orth
ro@TechFak.Uni-Bielefeld.DE
Tue Jul 17 13:30:00 GMT 2001
The patch below implements support for weak symbols and #pragma weak on
Tru64 UNIX. I had this lying in my tree for 1.5 years, but triggered by
the corresponding IRIX 5/6 patch, I've cleaned it up and retested.
Two changes may need an explanation:
* When I initially defined ASM_WEAKEN_LABEL and friends on Tru64 UNIX, the
resulting object files didn't have weak definitions ;-( It turned out
that the info is carried in a special field (coff_uint weakext:1) in EXTR
(the external symbol record defined in <sym.h>), and mips-tfile lost that
information by only copying selected fields from the input object to the
output file. The patch below fixes this, copying the whole EXTR and so
avoids this (and possibly other) lossage.
* I've added code to target-supports.exp (check_weak_alias) to handle
alpha*-*-osf* targets, since that function used to require binutils
objdump to determine the file format and decide if that supports weak
symbols. On many commercial platforms, users won't have binutils
installed and those testcases won't be run. I think it's best to
hardcode this information where this is easily possible (as is already
done for all MIPS targets), so I've started with Tru64 UNIX. It's
probably desirable to continue this for more platforms?
Bootstrapped on alpha-dec-osf4.0f and alpha-dec-osf5.1 with the following
testsuite changes:
* 4.0f and 5.1:
-FAIL: 21_strings/capacity.cc (test for excess errors)
-FAIL: 22_locale/numpunct.cc (test for excess errors)
-FAIL: 26_numerics/complex_inserters_extractors.cc (test for excess errors)
* 5.1 only:
+FAIL: 26_numerics/complex_inserters_extractors.cc execution test
Assertion failed: flteq(z.imag(), y), file /vol/gnu/src/gcc/gcc-3.0/libstdc++-v3/testsuite/26_numerics/complex_inserters_extractors.cc, line 48
failed to link before, so still better
* 4.0f and 5.1:
+FAIL: g++.dg/special/conpr-3.C (test for excess errors)
+FAIL: g++.dg/special/conpr-3.C (test for excess errors)
/usr/bin/ld:
conpr-3b.o: foo_t::foo_t(): weak symbol multiply defined
/usr/bin/ld:
conpr-3b.o: _ZN5foo_tC1Ev: weak symbol multiply defined
linker warning only, executable still built, but aborts (before the
patch, the test compiled, but aborted, so no regression here)
-FAIL: g++.other/mangle3.C (test for excess errors)
+FAIL: g++.pt/instantiate5.C (test for excess errors)
/usr/bin/ld:
/tmp/ccVPJkq7.o: bar() : weak symbol multiply defined
/tmp/ccVPJkq7.o: void foo<void>(): weak symbol multiply defined
/usr/bin/ld:
/tmp/ccVPJkq7.o: _Z3barv: weak symbol multiply defined
/tmp/ccVPJkq7.o: _Z3fooIvEvv: weak symbol multiply defined
but runs ok, so it may be necessary to ignore this linker message in the
DejaGnu framework?
+XPASS: g++.pt/static3.C (test for excess errors)
+XPASS: g++.pt/static3.C Execution test
+XPASS: g++.pt/static6.C (test for excess errors)
were marked XFAIL alpha*-dec-osf*, the patch below removes this, so they
PASS now.
Ok for branch and mainline?
Rainer
-----------------------------------------------------------------------------
Rainer Orth, Faculty of Technology, Bielefeld University
Email: ro@TechFak.Uni-Bielefeld.DE
Mon Jul 16 19:57:19 2001 Rainer Orth <ro@TechFak.Uni-Bielefeld.DE>
* config/alpha/osf.h (ASM_OUTPUT_WEAK_ALIAS, ASM_WEAKEN_LABEL,
HANDLE_SYSV_PRAGMA): Define.
* mips-tfile.c (add_ext_symbol): Pass complete symbol ptr, inline
previous args.
(copy_object): Caller changed.
testsuite:
* g++.old-deja/g++.pt/static3.C: Removed alpha*-*-osf* XFAIL.
g++.old-deja/g++.pt/static6.C: Likewise.
* lib/target-supports.exp (check_weak_available): alpha*-*-osf*
supports weak symbols.
===================================================================
RCS file: gcc/config/alpha/RCS/osf.h,v
retrieving revision 1.1
diff -up -r1.1 gcc/config/alpha/osf.h
--- gcc/config/alpha/osf.h 2001/06/11 16:15:19 1.1
+++ gcc/config/alpha/osf.h 2001/06/11 14:15:19
@@ -183,3 +183,26 @@ __enable_execute_stack (addr) \
(TARGET_GAS \
? (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4) \
: DW_EH_PE_aligned)
+
+/* This is how we tell the assembler that a symbol is weak. */
+
+#define ASM_OUTPUT_WEAK_ALIAS(FILE, NAME, VALUE) \
+ do \
+ { \
+ ASM_GLOBALIZE_LABEL (FILE, NAME); \
+ fputs ("\t.weakext\t", FILE); \
+ assemble_name (FILE, NAME); \
+ if (VALUE) \
+ { \
+ fputc (' ', FILE); \
+ assemble_name (FILE, VALUE); \
+ } \
+ fputc ('\n', FILE); \
+ } \
+ while (0)
+
+#define ASM_WEAKEN_LABEL(FILE, NAME) ASM_OUTPUT_WEAK_ALIAS(FILE, NAME, 0)
+
+/* Handle #pragma weak and #pragma pack. */
+#undef HANDLE_SYSV_PRAGMA
+#define HANDLE_SYSV_PRAGMA 1
===================================================================
RCS file: gcc/RCS/mips-tfile.c,v
retrieving revision 1.1
diff -up -r1.1 gcc/mips-tfile.c
--- gcc/mips-tfile.c 2001/06/13 18:04:12 1.1
+++ gcc/mips-tfile.c 2001/06/13 16:04:12
@@ -1637,12 +1637,7 @@ STATIC symint_t add_local_symbol
symint_t,
symint_t));
-STATIC symint_t add_ext_symbol __proto((const char *,
- const char *,
- st_t,
- sc_t,
- long,
- symint_t,
+STATIC symint_t add_ext_symbol __proto((EXTR *,
int));
STATIC symint_t add_aux_sym_symint
@@ -2063,23 +2058,24 @@ add_local_symbol (str_start, str_end_p1,
/* Add an external symbol. */
STATIC symint_t
-add_ext_symbol (str_start, str_end_p1, type, storage, value, indx, ifd)
- const char *str_start; /* first byte in string */
- const char *str_end_p1; /* first byte after string */
- st_t type; /* symbol type */
- sc_t storage; /* storage class */
- long value; /* value of symbol */
- symint_t indx; /* index to local/aux. syms */
+add_ext_symbol (esym, ifd)
+ EXTR *esym; /* symbol pointer */
int ifd; /* file index */
{
+ const char *str_start; /* first byte in string */
+ const char *str_end_p1; /* first byte after string */
register EXTR *psym;
register varray_t *vp = &ext_symbols;
shash_t *hash_ptr = (shash_t *) 0;
+ str_start = ORIG_ESTRS (esym->asym.iss);
+ str_end_p1 = str_start + strlen(str_start);
+
if (debug > 1)
{
- const char *sc_str = sc_to_string (storage);
- const char *st_str = st_to_string (type);
+ long value = esym->asym.value;
+ const char *sc_str = sc_to_string (esym->asym.sc);
+ const char *st_str = st_to_string (esym->asym.st);
fprintf (stderr,
"\tesym\tv= %10ld, ifd= %2d, sc= %-12s",
@@ -2097,11 +2093,9 @@ add_ext_symbol (str_start, str_end_p1, t
psym = &vp->last->datum->esym[ vp->objects_last_page++ ];
+ *psym = *esym;
psym->ifd = ifd;
- psym->asym.value = value;
- psym->asym.st = (unsigned) type;
- psym->asym.sc = (unsigned) storage;
- psym->asym.index = indx;
+ psym->asym.index = indexNil;
psym->asym.iss = (str_start == (const char *) 0)
? 0
: add_string (&ext_strings,
@@ -4648,17 +4642,10 @@ copy_object __proto((void))
for (es = 0; es < orig_sym_hdr.iextMax; es++)
{
register EXTR *eptr = orig_ext_syms + es;
- register char *ename = ORIG_ESTRS (eptr->asym.iss);
register unsigned ifd = eptr->ifd;
- (void) add_ext_symbol (ename,
- ename + strlen (ename),
- (st_t) eptr->asym.st,
- (sc_t) eptr->asym.sc,
- eptr->asym.value,
- (symint_t) indexNil,
- ((long) ifd < orig_sym_hdr.ifdMax
- ? remap_file_number[ifd] : (int) ifd));
+ (void) add_ext_symbol (eptr, ((long) ifd < orig_sym_hdr.ifdMax)
+ ? remap_file_number[ ifd ] : ifd );
}
===================================================================
RCS file: gcc/testsuite/g++.old-deja/g++.pt/RCS/static3.C,v
retrieving revision 1.1
diff -up -r1.1 gcc/testsuite/g++.old-deja/g++.pt/static3.C
--- gcc/testsuite/g++.old-deja/g++.pt/static3.C 2000/06/12 23:48:12 1.1
+++ gcc/testsuite/g++.old-deja/g++.pt/static3.C 2000/06/12 21:48:12
@@ -1,6 +1,6 @@
// On targets that don't support weak symbols, we require an explicit
// instantiation of arr.
-// excess errors test - XFAIL *-*-aout *-*-coff *-*-hpux* alpha*-dec-osf* *-*-hms
+// excess errors test - XFAIL *-*-aout *-*-coff *-*-hpux* *-*-hms
template<class T>
struct A {
===================================================================
RCS file: gcc/testsuite/g++.old-deja/g++.pt/RCS/static6.C,v
retrieving revision 1.1
diff -up -r1.1 gcc/testsuite/g++.old-deja/g++.pt/static6.C
--- gcc/testsuite/g++.old-deja/g++.pt/static6.C 2000/06/15 00:14:08 1.1
+++ gcc/testsuite/g++.old-deja/g++.pt/static6.C 2000/06/14 22:14:08
@@ -1,5 +1,5 @@
// Build don't run:
-// excess errors test - XFAIL *-*-aout *-*-coff *-*-hpux* alpha*-dec-osf* *-*-hms
+// excess errors test - XFAIL *-*-aout *-*-coff *-*-hpux* *-*-hms
// Simplified from testcase by Erez Louidor Lior <s3824888@techst02.technion.ac.il>
===================================================================
RCS file: gcc/testsuite/lib/RCS/target-supports.exp,v
retrieving revision 1.1
diff -up -r1.1 gcc/testsuite/lib/target-supports.exp
--- gcc/testsuite/lib/target-supports.exp 2001/01/03 18:22:23 1.1
+++ gcc/testsuite/lib/target-supports.exp 2001/01/03 17:22:23
@@ -27,6 +27,7 @@
# this proc returns 1 if they're supported, 0 if they're not, or -1 if unsure
proc check_weak_available { } {
+ global target_triplet
global target_cpu
# All mips targets should support it
@@ -35,6 +36,12 @@ proc check_weak_available { } {
return 1
}
+ # DEC OSF/1/Digital UNIX/Tru64 UNIX supports it
+
+ if { [regexp "alpha.*osf.*" $target_triplet] } {
+ return 1
+ }
+
# ELF and ECOFF support it. a.out does with gas/gld but may also with
# other linkers, so we should try it
More information about the Gcc-patches
mailing list