<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - MIPS: Thread local variable not flagged as thread local in object file"
   href="https://bugs.llvm.org/show_bug.cgi?id=35140">35140</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>MIPS: Thread local variable not flagged as thread local in object file
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: MIPS
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>alex@crichton.co
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We've been getting weird linkage errors in rust-lang/rust [1] which I believe
we've minimized to this IR:



@foo = external hidden thread_local global i32

define i32 @bar() {
  %a = load i32, i32* @foo
  ret i32 %a
}



I don't personally know a lot about MIPS unfortunately, but I think this may
show the problem:


$ llc foo.ll -filetype=obj -o foo.o -mtriple=mipsel-unknown-linux-gnu
-relocation-model=pic
$ readelf -Ws foo.o

Symbol table '.symtab' contains 7 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS foo.ll
     2: 00000000     0 SECTION LOCAL  DEFAULT    2
     3: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __tls_get_addr
     4: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND _gp_disp
     5: 00000000    56 FUNC    GLOBAL DEFAULT    2 bar
     6: 00000000     0 NOTYPE  GLOBAL HIDDEN   UND foo



Note that the import of `foo` under "Type" says "NOTYPE", whereas normally TLS
variables have "TLS" mentioned there. Also note that if `hidden` is removed
from the IR or the `-relocation-model=pic` argument is dropped then the "Type"
listed is indeed "TLS". 

Is this perhaps expected behavior and I'm barking up the wrong tree? I tried
compiling the equivalent C code with gcc to see what it output:


$ cat foo.c
extern __thread int foo __attribute__((visibility("hidden")));

int bar() {
        return foo;
}
$ mipsel-linux-gnu-gcc foo.c -c && mipsel-linux-gnu-readelf -Ws foo.o

Symbol table '.symtab' contains 14 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 FILE    LOCAL  DEFAULT  ABS foo.c
     2: 00000000     0 SECTION LOCAL  DEFAULT    1
     3: 00000000     0 SECTION LOCAL  DEFAULT    3
     4: 00000000     0 SECTION LOCAL  DEFAULT    4
     5: 00000000     0 SECTION LOCAL  DEFAULT    9
     6: 00000000     0 SECTION LOCAL  DEFAULT    5
     7: 00000000     0 SECTION LOCAL  DEFAULT    6
     8: 00000000     0 SECTION LOCAL  DEFAULT    7
     9: 00000000     0 SECTION LOCAL  DEFAULT   10
    10: 00000000     0 SECTION LOCAL  DEFAULT   11
    11: 00000000    60 FUNC    GLOBAL DEFAULT    1 bar
    12: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __gnu_local_gp
    13: 00000000     0 TLS     GLOBAL HIDDEN   UND foo


Note that the reference to `foo` is flagged as TLS and HIDDEN, so that's what
caused me to think that this may be an accidental bug in LLVM's codegen
perhaps?


[1]: <a href="https://travis-ci.org/rust-lang/rust/jobs/293501043">https://travis-ci.org/rust-lang/rust/jobs/293501043</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>