diff options
| -rw-r--r-- | lld/ELF/OutputSections.h | 2 | ||||
| -rw-r--r-- | lld/ELF/Target.cpp | 2 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 5 | ||||
| -rw-r--r-- | lld/test/elf2/tls.s | 8 | 
4 files changed, 11 insertions, 6 deletions
diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index 51c0fb0a688..8468da5b69f 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -372,6 +372,7 @@ template <class ELFT> struct Out {    static SymbolTableSection<ELFT> *DynSymTab;    static SymbolTableSection<ELFT> *SymTab;    static uintX_t TlsInitImageVA; +  static size_t TlsInitImageAlignedSize;  };  template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic; @@ -392,6 +393,7 @@ template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab;  template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab;  template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab;  template <class ELFT> typename Out<ELFT>::uintX_t Out<ELFT>::TlsInitImageVA; +template <class ELFT> size_t Out<ELFT>::TlsInitImageAlignedSize;  } // namespace elf2  } // namespace lld diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 7adc5c6de43..137dae39b3e 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -340,7 +340,7 @@ void X86_64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,      write32le(Loc, SA);      break;    case R_X86_64_TPOFF32: -    write32le(Loc, SA); +    write32le(Loc, SA - Out<llvm::object::ELF64LE>::TlsInitImageAlignedSize);      break;    default:      error("unrecognized reloc " + Twine(Type)); diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index d923712e59e..00dc4733d66 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -740,8 +740,11 @@ template <class ELFT> void Writer<ELFT>::assignAddresses() {      }    } -  if (TlsPhdr.p_vaddr) +  if (TlsPhdr.p_vaddr) {      Phdrs[++PhdrIdx] = TlsPhdr; +    Out<ELFT>::TlsInitImageAlignedSize = +        RoundUpToAlignment(TlsPhdr.p_memsz, TlsPhdr.p_align); +  }    // Add an entry for .dynamic.    if (isOutputDynamic()) { diff --git a/lld/test/elf2/tls.s b/lld/test/elf2/tls.s index 6b3cad13885..f947839628c 100644 --- a/lld/test/elf2/tls.s +++ b/lld/test/elf2/tls.s @@ -164,7 +164,7 @@ d:  // DIS:      Disassembly of section .text:  // DIS-NEXT: _start: -// DIS-NEXT:    11000: {{.+}} movl    %fs:8, %eax -// DIS-NEXT:    11008: {{.+}} movl    %fs:0, %eax -// DIS-NEXT:    11010: {{.+}} movl    %fs:12, %eax -// DIS-NEXT:    11018: {{.+}} movl    %fs:4, %eax +// DIS-NEXT:    11000: {{.+}} movl    %fs:-8, %eax +// DIS-NEXT:    11008: {{.+}} movl    %fs:-16, %eax +// DIS-NEXT:    11010: {{.+}} movl    %fs:-4, %eax +// DIS-NEXT:    11018: {{.+}} movl    %fs:-12, %eax  | 

