https://llvm.org/bugs/show_bug.cgi?id=29068

            Bug ID: 29068
           Summary: Static TLS for i386: addend ignored
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: other
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: ELF
          Assignee: unassignedb...@nondot.org
          Reporter: e...@80386.nl
                CC: llvm-bugs@lists.llvm.org
    Classification: Unclassified

Consider the following piece of code:

#include <stdio.h>

_Thread_local struct {
  int x, y, z;
} var = { .x = 12, .y = 34, .z = 56 };

void print(int);

int main() {
  print(var.y);
}

Compiling it for i686 will yield the following main() function (abbreviated):

main:
        movl    %gs:0, %eax
        pushl   var@NTPOFF+4(%eax)
        calll   print
        addl    $4, %esp
        xorl    %eax, %eax
        retl

Now, changing the call to print() to var.z, we get:

main:
        movl    %gs:0, %eax
        pushl   var@NTPOFF+8(%eax)
        calll   print
        addl    $4, %esp
        xorl    %eax, %eax
        retl

This is all good. Now this is where the interesting part starts. If we link it
into a simple executable, we always generate the following code (as in, it
doesn't matter if var.y or var.z is used):

00014750 <main>:
   14750:       65 a1 00 00 00 00       mov    %gs:0x0,%eax
   14756:       ff b0 dc ff ff ff       pushl  -0x24(%eax)
   1475c:       e8 0f 00 00 00          call   14770 <print>
   14761:       83 c4 04                add    $0x4,%esp
   14764:       31 c0                   xor    %eax,%eax
   14766:       c3                      ret

The value that is passed to print() is equal to twelve. In other words, the
linker completely ignores the addend of the relocation, always making it use
the first element in the structure.

I'll debug this issue in more detail. Marking this as a blocker for LLVM 3.9,
as it makes PIE effectively broken when used in non-PIE code on i386. The issue
is both present in trunk and 3.9rc1.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to