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

--- Comment #10 from H.J. Lu <hjl.tools at gmail dot com> ---
Another testcase:

[hjl@gnu-tools-1 pr58066]$ cat x.i
struct in_addr
  {
    int s_addr;
  };

typedef long unsigned int size_t;
extern void __snprintf (char *__restrict __s, size_t __maxlen,
         const char *__restrict __format, ...)
     __attribute__ ((__format__ (__printf__, 3, 4)));

static __thread char buffer[18];

char *
inet_ntoa (struct in_addr in)
{
  unsigned char *bytes = (unsigned char *) &in;
  __snprintf (buffer, sizeof (buffer), "%d.%d.%d.%d",
       bytes[0], bytes[1], bytes[2], bytes[3]);

  return buffer;
}
[hjl@gnu-tools-1 pr58066]$ gcc -S -fPIC -O2 x.i
[hjl@gnu-tools-1 pr58066]$ cat x.s
        .file   "x.i"
        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "%d.%d.%d.%d"
        .section        .text.unlikely,"ax",@progbits
.LCOLDB1:
        .text
.LHOTB1:
        .p2align 4,,15
        .globl  inet_ntoa
        .type   inet_ntoa, @function
inet_ntoa:
.LFB0:
        .cfi_startproc
        pushq   %r14
        .cfi_def_cfa_offset 16
        .cfi_offset 14, -16
        pushq   %r13
        .cfi_def_cfa_offset 24
        .cfi_offset 13, -24
        movzbl  %dil, %r13d
        pushq   %r12
        .cfi_def_cfa_offset 32
        .cfi_offset 12, -32
        pushq   %rbp
        .cfi_def_cfa_offset 40
        .cfi_offset 6, -40
        movl    %edi, %r12d
        pushq   %rbx
        .cfi_def_cfa_offset 48
        .cfi_offset 3, -48
        movl    %edi, %ebx
        shrl    $16, %r12d
        movzbl  %bh, %eax
        shrl    $24, %ebx
        movzbl  %r12b, %r12d
        subq    $8, %rsp
        .cfi_def_cfa_offset 56
        movl    %eax, %r14d
        leaq    buffer@tlsld(%rip), %rdi
        call    __tls_get_addr@PLT
        pushq   %rbx
        .cfi_def_cfa_offset 64
        leaq    .LC0(%rip), %rdx
        movl    %r12d, %r9d
        leaq    buffer@dtpoff(%rax), %rbp
        movl    %r14d, %r8d
        movl    %r13d, %ecx
        xorl    %eax, %eax
        movl    $18, %esi
        movq    %rbp, %rdi
        call    __snprintf@PLT
        popq    %rax
        .cfi_def_cfa_offset 56
        movq    %rbp, %rax
        popq    %rdx
        .cfi_def_cfa_offset 48
        popq    %rbx
        .cfi_def_cfa_offset 40
        popq    %rbp
        .cfi_def_cfa_offset 32
        popq    %r12
        .cfi_def_cfa_offset 24
        popq    %r13
        .cfi_def_cfa_offset 16
        popq    %r14
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE0:
        .size   inet_ntoa, .-inet_ntoa
        .section        .text.unlikely
.LCOLDE1:
        .text
.LHOTE1:
        .section        .tbss,"awT",@nobits
        .type   buffer, @object
        .size   buffer, 18
buffer:
        .zero   18
        .ident  "GCC: (GNU) 5.1.1 20150707 (Red Hat 5.1.1-5)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-tools-1 pr58066]$ 

__tls_get_addr is called with misaligned stack.

Reply via email to