[lld] r252131 - [elf2] Fix R_X86_64_TPOFF32 handling.

Michael Spencer via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 5 12:08:59 PST 2015


On Thu, Nov 5, 2015 at 11:25 AM, Rui Ueyama <ruiu at google.com> wrote:
> Took a quick look at gold and found this piece of code.
>
> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gold/x86_64.cc;h=3651d398ff673ab0d56ed8a0211482ccf132ead7;hb=HEAD#l3942
>
> This doesn't seems to include the padding.

gold adds the padding to the end of the PT_TLS by aligning p_memsz to p_align.

- Michael Spencer

>
> On Thu, Nov 5, 2015 at 11:20 AM, Michael Spencer <bigcheesegs at gmail.com>
> wrote:
>>
>> On Thu, Nov 5, 2015 at 11:19 AM, Rui Ueyama <ruiu at google.com> wrote:
>> > Does this test cover that?
>>
>> No, I'll add that.
>>
>> - Michael Spencer
>>
>> >
>> > On Thu, Nov 5, 2015 at 11:16 AM, Michael Spencer <bigcheesegs at gmail.com>
>> > wrote:
>> >>
>> >> On Thu, Nov 5, 2015 at 10:13 AM, Rui Ueyama <ruiu at google.com> wrote:
>> >> > On Wed, Nov 4, 2015 at 6:00 PM, Michael J. Spencer via llvm-commits
>> >> > <llvm-commits at lists.llvm.org> wrote:
>> >> >>
>> >> >> Author: mspencer
>> >> >> Date: Wed Nov  4 20:00:35 2015
>> >> >> New Revision: 252131
>> >> >>
>> >> >> URL: http://llvm.org/viewvc/llvm-project?rev=252131&view=rev
>> >> >> Log:
>> >> >> [elf2] Fix R_X86_64_TPOFF32 handling.
>> >> >>
>> >> >> For x86-64 the initial executable TLS block is placed directly
>> >> >> before
>> >> >> the
>> >> >> thread specific data register so compilers can directly access it
>> >> >> via
>> >> >> R_X86_64_TPOFF32. Generate the correct (negative) offset for this
>> >> >> case.
>> >> >>
>> >> >> Modified:
>> >> >>     lld/trunk/ELF/OutputSections.h
>> >> >>     lld/trunk/ELF/Target.cpp
>> >> >>     lld/trunk/ELF/Writer.cpp
>> >> >>     lld/trunk/test/elf2/tls.s
>> >> >>
>> >> >> Modified: lld/trunk/ELF/OutputSections.h
>> >> >> URL:
>> >> >>
>> >> >>
>> >> >> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=252131&r1=252130&r2=252131&view=diff
>> >> >>
>> >> >>
>> >> >>
>> >> >> ==============================================================================
>> >> >> --- lld/trunk/ELF/OutputSections.h (original)
>> >> >> +++ lld/trunk/ELF/OutputSections.h Wed Nov  4 20:00:35 2015
>> >> >> @@ -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
>> >> >>  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
>> >> >>
>> >> >> Modified: lld/trunk/ELF/Target.cpp
>> >> >> URL:
>> >> >>
>> >> >>
>> >> >> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=252131&r1=252130&r2=252131&view=diff
>> >> >>
>> >> >>
>> >> >>
>> >> >> ==============================================================================
>> >> >> --- lld/trunk/ELF/Target.cpp (original)
>> >> >> +++ lld/trunk/ELF/Target.cpp Wed Nov  4 20:00:35 2015
>> >> >> @@ -340,7 +340,7 @@ void X86_64TargetInfo::relocateOne(uint8
>> >> >>      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));
>> >> >>
>> >> >> Modified: lld/trunk/ELF/Writer.cpp
>> >> >> URL:
>> >> >>
>> >> >>
>> >> >> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=252131&r1=252130&r2=252131&view=diff
>> >> >>
>> >> >>
>> >> >>
>> >> >> ==============================================================================
>> >> >> --- lld/trunk/ELF/Writer.cpp (original)
>> >> >> +++ lld/trunk/ELF/Writer.cpp Wed Nov  4 20:00:35 2015
>> >> >> @@ -740,8 +740,11 @@ template <class ELFT> void Writer<ELFT>:
>> >> >>      }
>> >> >>    }
>> >> >>
>> >> >> -  if (TlsPhdr.p_vaddr)
>> >> >> +  if (TlsPhdr.p_vaddr) {
>> >> >>      Phdrs[++PhdrIdx] = TlsPhdr;
>> >> >> +    Out<ELFT>::TlsInitImageAlignedSize =
>> >> >> +        RoundUpToAlignment(TlsPhdr.p_memsz, TlsPhdr.p_align);
>> >> >> +  }
>> >> >
>> >> >
>> >> > Can you give me the pointer to the spec that says "TLS block end" is
>> >> > an
>> >> > aligned value this way?
>> >>
>> >> Spec seems vague about it, but it's what glibc does.
>> >>
>> >> - Michael Spencer
>> >>
>> >> >
>> >> >>
>> >> >>
>> >> >>    // Add an entry for .dynamic.
>> >> >>    if (isOutputDynamic()) {
>> >> >>
>> >> >> Modified: lld/trunk/test/elf2/tls.s
>> >> >> URL:
>> >> >>
>> >> >>
>> >> >> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/tls.s?rev=252131&r1=252130&r2=252131&view=diff
>> >> >>
>> >> >>
>> >> >>
>> >> >> ==============================================================================
>> >> >> --- lld/trunk/test/elf2/tls.s (original)
>> >> >> +++ lld/trunk/test/elf2/tls.s Wed Nov  4 20:00:35 2015
>> >> >> @@ -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
>> >> >>
>> >> >>
>> >> >> _______________________________________________
>> >> >> llvm-commits mailing list
>> >> >> llvm-commits at lists.llvm.org
>> >> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>> >> >
>> >> >
>> >
>> >
>
>


More information about the llvm-commits mailing list