[PATCH] D86777: [PowerPC] Fix missing TLS symbol type.

Stefan Pintilie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 1 12:18:45 PDT 2020


stefanp added a comment.

In D86777#2244533 <https://reviews.llvm.org/D86777#2244533>, @MaskRay wrote:

> I'll not say this is a bug. For an undefined symbol, `STT_TLS` is not strictly required. For a definition, `STT_TLS` is indeed better.

MaskRay,
Thank you for looking at this patch.

Sorry it took me a couple of days to reply to this. I wanted to clarify in my head what was going on.
The reason I added this patch was because I ran into this following setup:

  clang -O3 -mcpu=pwr10 -fPIC -c PCRelTLS.c

The source file `PCRelTLS.c` has some examples of General Dynamic and has two TLS variables defined as:

  extern __thread unsigned int x;
  extern __thread unsigned int y;

Now, if I look at the symbol table I end up with:

  7: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND x
  8: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND y

However, when I link this object:

  ld.lld --shared PCRelTLS.o -o PCRelTLS.so

It looks like LLD will enter the function

  template <class ELFT>
  static unsigned
  handleTlsRelocation(RelType type, Symbol &sym, InputSectionBase &c,
                      typename ELFT::uint offset, int64_t addend, RelExpr expr) {
    if (!sym.isTls())
      return 0;

and then exit immediately and the relocations related to `x` and `y` won't be handled correctly.
So, I did what you see in this patch: I made sure that all of the symbols like `x` and `y` had the type `STT_TLS`.

Of course, there could be something I've missed in my logic.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86777/new/

https://reviews.llvm.org/D86777



More information about the llvm-commits mailing list