public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103275] New: don't generate kmov with IE model relocations
@ 2021-11-16 13:55 jason at zx2c4 dot com
  2021-11-16 14:02 ` [Bug target/103275] " pinskia at gcc dot gnu.org
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: jason at zx2c4 dot com @ 2021-11-16 13:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103275
           Summary: don't generate kmov with IE model relocations
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jason at zx2c4 dot com
  Target Milestone: ---

This is a spin-off from https://sourceware.org/bugzilla/show_bug.cgi?id=28595

1.c:
extern __thread int mytls __attribute__((tls_model ("initial-exec")));

__attribute__((noipa)) void
foo (void)
{
  asm ("");
}

int
main ()
{
  foo ();
#ifdef KMOVD
  asm volatile ("kmovd mytls@gotntpoff(%%ebx), %%k0" : : : "k0");
#else
  volatile int a = mytls;
#endif
  return 0;
}
2.c:
__thread int mytls __attribute__((tls_model ("initial-exec")));
$ gcc -O2 -m32 -fPIC /tmp/1.c /tmp/2.c -o /tmp/1 -UKMOVD -mavx512f
$ gcc -O2 -m32 -fPIC /tmp/1.c /tmp/2.c -o /tmp/1 -DKMOVD -mavx512f
/usr/bin/ld: /tmp/ccQrvWxU.o: TLS transition from R_386_TLS_GOTIE to
R_386_TLS_LE_32 against `mytls' at 0x1c in section `.text.startup' failed
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

That results from the type check returning false here:

    case R_386_TLS_GOTIE:
    case R_386_TLS_IE_32:
      /* Check transition from {IE_32,GOTIE} access model:
                subl foo@{tpoff,gontoff}(%reg1), %reg2
                movl foo@{tpoff,gontoff}(%reg1), %reg2
                addl foo@{tpoff,gontoff}(%reg1), %reg2
       */

      if (offset < 2 || (offset + 4) > sec->size)
        return false;

      val = bfd_get_8 (abfd, contents + offset - 1);
      if ((val & 0xc0) != 0x80 || (val & 7) == 4)
        return false;

      type = bfd_get_8 (abfd, contents + offset - 2);
      return type == 0x8b || type == 0x2b || type == 0x03;


In the ensuing discussion, Florian thought that GAS shouldn't even be
assembling it, because that's not a valid relocation type. As a consequence,
GCC shouldn't be emitting it either, which it is in the context of glibc.
Quoting Jakub:


> https://akkadia.org/drepper/tls.pdf
> I don't remember anymore whether it is ok if some of the TLS
> relocations appear also in instructions not exactly mentioned
> in the above mentioned pdf and if instead of giving the linker
> errors like the above the linker should just not optimize a
> particular TLS model, i.e. still use IE model here when it
> can't optimize it into LE model (then it would be a linker bug),
> or whether the compiler needs to ensure that those @gotntpoff
> etc. appear solely in the instructions mentioned in the pdf
> (here in movl).  In that case it would be a gcc bug, e.g. for
> the @gotntpoff MEMs it would need to disallow them by default
> and only accept them as a special case in a simple *movsi_internal.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-01-19 16:15 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16 13:55 [Bug c/103275] New: don't generate kmov with IE model relocations jason at zx2c4 dot com
2021-11-16 14:02 ` [Bug target/103275] " pinskia at gcc dot gnu.org
2021-11-16 14:18 ` jason at zx2c4 dot com
2021-11-16 14:26 ` jason at zx2c4 dot com
2021-11-16 14:35 ` [Bug target/103275] [11 Regression] " jakub at gcc dot gnu.org
2021-11-16 14:51 ` pinskia at gcc dot gnu.org
2021-11-16 15:00 ` [Bug target/103275] [11/12 " rguenth at gcc dot gnu.org
2021-11-16 23:40 ` jason at zx2c4 dot com
2021-11-17  2:48 ` crazylht at gmail dot com
2021-11-17  3:09 ` hjl.tools at gmail dot com
2021-11-17  7:04 ` jakub at gcc dot gnu.org
2021-11-17 13:16 ` crazylht at gmail dot com
2021-11-17 13:19 ` hjl.tools at gmail dot com
2021-11-17 14:02 ` jason at zx2c4 dot com
2021-11-17 14:17 ` jakub at gcc dot gnu.org
2021-11-18  5:48 ` crazylht at gmail dot com
2021-11-22  3:36 ` cvs-commit at gcc dot gnu.org
2021-11-22  3:37 ` cvs-commit at gcc dot gnu.org
2021-11-22  3:39 ` crazylht at gmail dot com
2022-01-19 16:15 ` jakub at gcc dot gnu.org

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).