From 17271ece0da69c4dde0bbab60883b7fdd05be131 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 19 Jun 2021 09:54:11 -0400 Subject: [PATCH] [lld/mac] Give __DATA,__thread_ptrs type S_THREAD_LOCAL_VARIABLE_POINTERS ...instead of S_NON_LAZY_SYMBOL_POINTERS. This matches ld64. Part of PR50769. While here, also remove an old TODO that was done in D87178. Differential Revision: https://reviews.llvm.org/D104594 --- lld/MachO/SyntheticSections.cpp | 12 +++++++++++- lld/MachO/SyntheticSections.h | 11 ++--------- lld/test/MachO/tlv-dylib.s | 20 ++++++++++++++++++++ lld/test/MachO/tlv.s | 4 ++-- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index fec4300..a5d21dc 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -218,7 +218,6 @@ NonLazyPointerSectionBase::NonLazyPointerSectionBase(const char *segname, const char *name) : SyntheticSection(segname, name) { align = target->wordSize; - flags = S_NON_LAZY_SYMBOL_POINTERS; } void macho::addNonLazyBindingEntries(const Symbol *sym, @@ -254,6 +253,17 @@ void NonLazyPointerSectionBase::writeTo(uint8_t *buf) const { write64le(&buf[i * target->wordSize], defined->getVA()); } +GotSection::GotSection() + : NonLazyPointerSectionBase(segment_names::dataConst, section_names::got) { + flags = S_NON_LAZY_SYMBOL_POINTERS; +} + +TlvPointerSection::TlvPointerSection() + : NonLazyPointerSectionBase(segment_names::data, + section_names::threadPtrs) { + flags = S_THREAD_LOCAL_VARIABLE_POINTERS; +} + BindingSection::BindingSection() : LinkEditSection(segment_names::linkEdit, section_names::binding) {} diff --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h index 3614177..3b26058 100644 --- a/lld/MachO/SyntheticSections.h +++ b/lld/MachO/SyntheticSections.h @@ -136,19 +136,12 @@ private: class GotSection final : public NonLazyPointerSectionBase { public: - GotSection() - : NonLazyPointerSectionBase(segment_names::dataConst, - section_names::got) { - // TODO: section_64::reserved1 should be an index into the indirect symbol - // table, which we do not currently emit - } + GotSection(); }; class TlvPointerSection final : public NonLazyPointerSectionBase { public: - TlvPointerSection() - : NonLazyPointerSectionBase(segment_names::data, - section_names::threadPtrs) {} + TlvPointerSection(); }; struct Location { diff --git a/lld/test/MachO/tlv-dylib.s b/lld/test/MachO/tlv-dylib.s index bb40475..d02f787 100644 --- a/lld/test/MachO/tlv-dylib.s +++ b/lld/test/MachO/tlv-dylib.s @@ -26,6 +26,26 @@ # CHECK-DAG: __DATA __thread_ptrs 0x{{0*}}[[#%x, BAR]] pointer 0 libtlv _bar # CHECK-DAG: __DATA_CONST __got 0x{{0*}}[[#%x, BAZ]] pointer 0 libtlv _baz +# RUN: llvm-otool -lv %t/test | FileCheck --check-prefix=FLAGS %s +# FLAGS: sectname __got +# FLAGS-NEXT: segname __DATA_CONST +# FLAGS-NEXT: addr +# FLAGS-NEXT: size 0x0000000000000008 +# FLAGS-NEXT: offset +# FLAGS-NEXT: align 2^3 (8) +# FLAGS-NEXT: reloff 0 +# FLAGS-NEXT: nreloc 0 +# FLAGS-NEXT: type S_NON_LAZY_SYMBOL_POINTERS +# FLAGS: sectname __thread_ptrs +# FLAGS-NEXT: segname __DATA +# FLAGS-NEXT: addr +# FLAGS-NEXT: size 0x0000000000000010 +# FLAGS-NEXT: offset +# FLAGS-NEXT: align 2^3 (8) +# FLAGS-NEXT: reloff 0 +# FLAGS-NEXT: nreloc 0 +# FLAGS-NEXT: type S_THREAD_LOCAL_VARIABLE_POINTERS + #--- libtlv.s .section __DATA,__thread_vars,thread_local_variables .globl _foo, _bar, _baz diff --git a/lld/test/MachO/tlv.s b/lld/test/MachO/tlv.s index 6263e37..a7e032b 100644 --- a/lld/test/MachO/tlv.s +++ b/lld/test/MachO/tlv.s @@ -4,13 +4,13 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/tbss.s -o %t/tbss.o # RUN: %lld -lSystem -no_pie -o %t/regular %t/regular.o -# RUN: llvm-readobj --file-headers %t/regular | FileCheck %s --check-prefix=HEADER +# RUN: llvm-otool -hv %t/regular | FileCheck %s --check-prefix=HEADER # RUN: llvm-objdump -d --bind --rebase %t/regular | FileCheck %s --check-prefixes=REG,LINKEDIT # RUN: llvm-objdump --macho --section=__DATA,__thread_vars %t/regular | \ # RUN: FileCheck %s --check-prefix=REG-TLVP # RUN: %lld -lSystem -pie %t/regular.o -o %t/regular-pie -# RUN: llvm-readobj --file-headers %t/regular-pie | FileCheck %s --check-prefix=HEADER +# RUN: llvm-otool -hv %t/regular-pie | FileCheck %s --check-prefix=HEADER # RUN: llvm-objdump -d --bind --rebase %t/regular-pie | FileCheck %s --check-prefixes=REG,LINKEDIT # RUN: llvm-objdump --macho --section=__DATA,__thread_vars %t/regular-pie | \ # RUN: FileCheck %s --check-prefix=REG-TLVP -- 2.7.4