This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Set DF_STATIC_TLS flag for x86_64 target.
AbandonedPublic

Authored by grimar on May 10 2017, 8:05 AM.

Details

Summary

DF_STATIC_TLS
If set in a shared object or executable, this flag instructs the dynamic linker to reject attempts to load this file dynamically. It indicates that the shared object or executable contains code using a static thread-local storage scheme. Implementations need not support any form of thread-local storage.

The is same as D32354, but for x86_64 target.

Diff Detail

Event Timeline

grimar created this revision.May 10 2017, 8:05 AM
ruiu edited edge metadata.May 10 2017, 10:40 AM

Can you verify that you actually cannot dlopen() an .so file if the file has the DF_STATIC_TLS flag? I want to make sure that glibc actually uses the flag.

joerg added a subscriber: joerg.May 10 2017, 1:26 PM

It's actually more a diagnostic hint. Due to things like Nvidia's binary-only libGL, this is actually supported by most TLS implementations as long as no initializers are needed.

In D33041#751238, @ruiu wrote:

Can you verify that you actually cannot dlopen() an .so file if the file has the DF_STATIC_TLS flag? I want to make sure that glibc actually uses the flag.

Flag does not seem to have effect for me on Ubuntu 16.04.1 LTS.

Used code:

#include <iostream>
#include <dlfcn.h>

int main() {
    std::cout << "Opening test_flag.so...\n";
    void* handle = dlopen("./test_flag.so", RTLD_NOW);
    if (!handle) {
      std::cout << "Cannot open library: " << dlerror() << std::endl;
      return 0;
   }

  std::cout << "OK" << std::endl;
  dlclose(handle);
  return 0;
}

umb@umb-virtual-machine:~/tests/311$ g++ test.cpp -o temp -ldl
umb@umb-virtual-machine:~/tests/311$ ./temp
Opening test_flag.so...
OK
umb@umb-virtual-machine:~/tests/311$ readelf --dynamic test_flag.so

Dynamic section at offset 0x228 contains 10 entries:
  Tag        Type                         Name/Value
 0x0000000000000004 (HASH)               0x120
 0x0000000000000005 (STRTAB)             0x1e0
 0x0000000000000006 (SYMTAB)             0x150
 0x000000000000000a (STRSZ)              29 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000007 (RELA)               0x200
 0x0000000000000008 (RELASZ)             24 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000000000001e (FLAGS)              STATIC_TLS
 0x0000000000000000 (NULL)               0x0
grimar abandoned this revision.May 12 2017, 12:33 AM

Abandoning since we decided to remove support of STATIC_TLS flag.

emaste added a subscriber: emaste.Feb 3 2019, 2:16 PM

FreeBSD patch adding initial exec TLS mode for dynamically loaded shared objects: https://reviews.freebsd.org/D19072. Can we revisit this lld patch?

FreeBSD patch adding initial exec TLS mode for dynamically loaded shared objects: https://reviews.freebsd.org/D19072. Can we revisit this lld patch?

I'll take a look tomorrow. Seems FreeBSD is going to use it for both x86_64 and i386 targets for start? That means we also might want to revisit D32354.
It was reverted.

FTR and to answer the comment from freebsd.org page above, which was
"They did not stated why DF_STATIC_TLS was considered as 'not needed'.":

Rafael's answer in the mail list that time was:

I just cloned musl and DF_STATIC_TLS is not used anywhere.

glibc used to use it, but doesn't since 2002
(2430d57a13f4f10312e13c58962cd9104e6428fd).

It is also not used by the freebsd one.

emaste added a comment.Feb 4 2019, 9:07 AM

FreeBSD patch adding initial exec TLS mode for dynamically loaded shared objects: https://reviews.freebsd.org/D19072. Can we revisit this lld patch?

I'll take a look tomorrow.

Great, thank you.

Seems FreeBSD is going to use it for both x86_64 and i386 targets for start? That means we also might want to revisit D32354.
It was reverted.

Yes, we were still shipping GNU ld.bfd 2.17.50 as /usr/bin/ld on i386 until just recently because of trouble in the ports tree (although the kernel and base system userland has been linked with lld for quite some time).

Now that lld is fully enabled on amd64, i386, arm64 and armv7 we'll start making use of these features across platforms, i386 included.

FTR and to answer the comment from freebsd.org page above, which was
"They did not stated why DF_STATIC_TLS was considered as 'not needed'.":

Rafael's answer in the mail list that time was:

I just cloned musl and DF_STATIC_TLS is not used anywhere.

glibc used to use it, but doesn't since 2002
(2430d57a13f4f10312e13c58962cd9104e6428fd).

It is also not used by the freebsd one.

Thank you for the archaeology; looking into what we'll do in FreeBSD.

grimar added a comment.Feb 6 2019, 7:35 AM

Updated version is D57821.