Index: lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp =================================================================== --- lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp +++ lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp @@ -60,7 +60,8 @@ } bool isTLVAccess(const Reference &ref) const override { - assert(ref.kindNamespace() == Reference::KindNamespace::mach_o); + if (ref.kindNamespace() != Reference::KindNamespace::mach_o) + return false; assert(ref.kindArch() == Reference::KindArch::x86_64); return ref.kindValue() == ripRel32Tlv; } Index: test/mach-o/tlv-refkind.yaml =================================================================== --- /dev/null +++ test/mach-o/tlv-refkind.yaml @@ -0,0 +1,56 @@ +# RUN: lld -flavor darwin -arch x86_64 %s %p/Inputs/libSystem.yaml \ +# RUN: -o %t +# RUN: llvm-nm -m -n %t | FileCheck %s +# +# +# Test that x86_64 checking for TLV on local symbols properly accounts for +# references not in the mach_o:: namespace. Specifically in this case, +# all::layout_after references. +# +--- !mach-o +arch: x86_64 +file-type: MH_OBJECT +flags: [ ] +compat-version: 0.0 +current-version: 0.0 +has-UUID: false +OS: unknown +sections: + - segment: __TEXT + section: __text + type: S_REGULAR + attributes: [ S_ATTR_PURE_INSTRUCTIONS, S_ATTR_SOME_INSTRUCTIONS ] + address: 0x0000000000000000 + content: [ 0xC3 ] + - segment: __DATA + section: __data + type: S_REGULAR + attributes: [ ] + address: 0x0000000000000001 + content: [ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 ] +local-symbols: + - name: l.blah + type: N_SECT + sect: 2 + value: 0x0000000000000001 + - name: l.blaz + type: N_SECT + sect: 2 + value: 0x0000000000000005 +global-symbols: + - name: _foo + type: N_SECT + scope: [ N_EXT ] + sect: 2 + value: 0x0000000000000001 + - name: _main + type: N_SECT + scope: [ N_EXT ] + sect: 1 + value: 0x0000000000000000 +page-size: 0x00000000 +... + + +# CHECK: (undefined) external dyld_stub_binder (from libSystem) +# CHECK-NEXT: external _main