<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - need arm llvm -fpie to work without __aeabi_read_tp"
   href="https://llvm.org/bugs/show_bug.cgi?id=23566">23566</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>need arm llvm -fpie to work without __aeabi_read_tp
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>chh@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Current clang generates references to __aeabi_read_tp
for arm target under -fpie.
It generates references to __tls_get_addr under -fPIC,
and no special library reference under -fpie for x86 target.

The reference to __aeabi_read_tp caused link time error
because Android run-time library does not have this function yet.

Gcc for arm target generates references to __emutls_get_address under -fpie or
-fPIC.

Is there any clang arm target configuration flag to generate
for -fpie references to __tls_get_addr or __emutls_get_address,
or no external reference at all?
This will allow existing AOSP upstream projects to continue using -fpie,
instead of -fPIC or waiting for an upgrade of AOSP library.


The folloing is a test case reduced from Android Open Source
external/fio/gettime.c
It shows that reference to __aeabi_read_tp is used only for arm -fpie,
not for -fPIC or x86.

$ cat g.i.c
struct mytimeval {
  int tv_sec;
  int tv_usec;
};
struct tv_valid {
 struct mytimeval last_tv;
 int last_tv_valid;
};
extern __thread struct tv_valid static_tv_valid;
void fio_gettime(struct mytimeval *tp)
{
 struct tv_valid *tv = &static_tv_valid;
 if (tv) {
  if (tv->last_tv_valid)
    tp->tv_sec = tv->last_tv.tv_sec;
  tv->last_tv_valid = 1;
 }
}

$ clang -fpie g.i.c -c -o /tmp/c.x86.pie.o
$ clang -fPIC g.i.c -c -o /tmp/c.x86.PIC.o
$ clang -target arm-linux-androideabi -fpie g.i.c -c -o /tmp/c.pie.o
$ clang -target arm-linux-androideabi -fPIC g.i.c -c -o /tmp/c.PIC.o

$ nm /tmp/c.x86.pie.o | grep -E 'aeabi_read|tls_'
$ nm /tmp/c.x86.PIC.o | grep -E 'aeabi_read|tls_'
        U __tls_get_addr
$ nm /tmp/c.pie.o | grep -E 'aeabi_read|tls_'
        U __aeabi_read_tp
$ nm /tmp/c.PIC.o | grep -E 'aeabi_read|tls_'
        U __tls_get_addr</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>