public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dje at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/94177] New: TLS global-dynamic model clobbers function parameter on AIX
Date: Sat, 14 Mar 2020 22:59:47 +0000	[thread overview]
Message-ID: <bug-94177-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94177

            Bug ID: 94177
           Summary: TLS global-dynamic model clobbers function parameter
                    on AIX
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dje at gcc dot gnu.org
  Target Milestone: ---
            Target: powerpc-ibm-aix*

In global-dynamic model, if a TLS variable first is referenced in the argument
list to a function call, GCC can load the parameters to the call before
invoking the function to legitimize the TLS variable, and the legitimize
function clobbers some of the same function argument registers.

extern int foo (char *, int *, int);

int main()
{
   static __thread int result;

   foo ("%p %u\n", &result, 169);
   return 0;
}

$ gcc -fPIC -S bug_tls.c
        li 5,169
        lwz 10,LCM..1(2)
        lwz 9,LC..1(2)
        mr 3,10
        mr 4,9
        bla __tls_get_addr <*** clobbers r4, r5 already loaded with arguments
to foo
        mr 9,3
        mr 4,9
        lwz 3,LC..2(2)
        bl .foo


The pattern that generates __tls_get_addr shows that it clobbers r4 and r5

(define_insn "tls_get_addr_internal<mode>"
  [(set (reg:P 3)
        (unspec:P [(reg:P 3) (reg:P 4)] UNSPEC_TLSTLS))
   (clobber (reg:P 0))
   (clobber (reg:P 4))
   (clobber (reg:P 5))
   (clobber (reg:P 11))
   (clobber (reg:CC CR0_REGNO))
   (clobber (reg:P LR_REGNO))]
  "TARGET_XCOFF && HAVE_AS_TLS"
  "bla __tls_get_addr")

but GCC overwrites the parameters in calls.c during initial RTL generation.

             reply	other threads:[~2020-03-14 22:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-14 22:59 dje at gcc dot gnu.org [this message]
2021-03-09 18:11 ` [Bug target/94177] " dje at gcc dot gnu.org
2021-04-27 16:32 ` cvs-commit at gcc dot gnu.org
2021-04-27 19:01 ` dje at gcc dot gnu.org
2021-05-28 20:49 ` cvs-commit at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-94177-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).