This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, committed] Fix TLS and -fstack-protector on sparc64
> TLS details in .debug_info (sparc_output_dwarf_dtprel) and
> tgd_add in tg_call's delay slot, that's it AFAIK.
> The latter is that Sun as/ld requires AFAIK only
> R_SPARC_TLS_GD_HI22
> R_SPARC_TLS_GD_LO10
> R_SPARC_TLS_GD_ADD
> R_SPARC_TLS_GD_CALL
> sequence (in that order), while gas handles also
> R_SPARC_TLS_GD_HI22
> R_SPARC_TLS_GD_LO10
> R_SPARC_TLS_GD_CALL
> R_SPARC_TLS_GD_ADD ! in call's delay slot
OK, thanks. Indeed the page I linked to has a note explicitly forbidding to
put the 'add' in the delay slot of the 'call'; the problem is that the reorg
pass nonetheless does so :-( I've applied the first patch to every branch.
And I've narrowed down the libgomp problem to these lines in configure.tgt:
# Optimize TLS usage by avoiding the overhead of dynamic allocation.
# This does require that the library be present during process
# startup, so mark the library as not to be dlopened.
if test $have_tls = yes && test "$with_gnu_ld" = "yes"; then
XCFLAGS="${XCFLAGS} -ftls-model=initial-exec"
XLDFLAGS="${XLDFLAGS} -Wl,-z,nodlopen"
fi
A bit too Linux-centric I'm afraid. :-) I'm proposing the second patch.
2006-02-09 Eric Botcazou <ebotcazou@libertysurf.fr>
gcc/
* config/sparc/sparc.c (tls_call_delay): Fix oversight.
libgomp/
* configure.tgt: Force initial-exec TLS model on Linux only.
--
Eric Botcazou
Index: configure.tgt
===================================================================
--- configure.tgt (revision 110691)
+++ configure.tgt (working copy)
@@ -13,9 +13,14 @@
# Optimize TLS usage by avoiding the overhead of dynamic allocation.
# This does require that the library be present during process
# startup, so mark the library as not to be dlopened.
-if test $have_tls = yes && test "$with_gnu_ld" = "yes"; then
+if test $have_tls = yes ; then
+ case "${target}" in
+
+ *-*-linux*)
XCFLAGS="${XCFLAGS} -ftls-model=initial-exec"
XLDFLAGS="${XLDFLAGS} -Wl,-z,nodlopen"
+ ;;
+ esac
fi
# Since we require POSIX threads, assume a POSIX system by default.
Index: config/sparc/sparc.c
===================================================================
--- config/sparc/sparc.c (revision 110691)
+++ config/sparc/sparc.c (working copy)
@@ -2415,26 +2415,34 @@ empty_delay_slot (rtx insn)
int
tls_call_delay (rtx trial)
{
- rtx pat, unspec;
+ rtx pat;
/* Binutils allows
- call __tls_get_addr, %tgd_call (foo)
- add %l7, %o0, %o0, %tgd_add (foo)
+ call __tls_get_addr, %tgd_call (foo)
+ add %l7, %o0, %o0, %tgd_add (foo)
while Sun as/ld does not. */
if (TARGET_GNU_TLS || !TARGET_TLS)
return 1;
pat = PATTERN (trial);
- if (GET_CODE (pat) != SET || GET_CODE (SET_DEST (pat)) != PLUS)
- return 1;
- unspec = XEXP (SET_DEST (pat), 1);
- if (GET_CODE (unspec) != UNSPEC
- || (XINT (unspec, 1) != UNSPEC_TLSGD
- && XINT (unspec, 1) != UNSPEC_TLSLDM))
- return 1;
+ /* We must reject tgd_add{32|64}, i.e.
+ (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSGD)))
+ and tldm_add{32|64}, i.e.
+ (set (reg) (plus (reg) (unspec [(reg) (symbol_ref)] UNSPEC_TLSLDM)))
+ for Sun as/ld. */
+ if (GET_CODE (pat) == SET
+ && GET_CODE (SET_SRC (pat)) == PLUS)
+ {
+ rtx unspec = XEXP (SET_SRC (pat), 1);
+
+ if (GET_CODE (unspec) == UNSPEC
+ && (XINT (unspec, 1) == UNSPEC_TLSGD
+ || XINT (unspec, 1) == UNSPEC_TLSLDM))
+ return 0;
+ }
- return 0;
+ return 1;
}
/* Return nonzero if TRIAL, an insn, can be combined with a 'restore'