diff options
author | Jez Ng <jezng@fb.com> | 2020-12-01 14:45:10 -0800 |
---|---|---|
committer | Jez Ng <jezng@fb.com> | 2020-12-01 15:05:20 -0800 |
commit | d0c4be42e35d8cff069f91a45b76ea24187c233d (patch) | |
tree | 27bb7a10b5043637ab4e5dc7b5bd611653594976 | |
parent | [lld-macho] Emit local symbols in symtab; record metadata in LC_DYSYMTAB (diff) | |
download | llvm-project-d0c4be42e35d8cff069f91a45b76ea24187c233d.tar.gz llvm-project-d0c4be42e35d8cff069f91a45b76ea24187c233d.tar.bz2 llvm-project-d0c4be42e35d8cff069f91a45b76ea24187c233d.zip |
[lld-macho] Emit empty string as first entry of string table
ld64 emits string tables which start with a space and a zero byte. We
match its behavior here since some tools depend on it.
Similar rationale as {D89561}.
Reviewed By: #lld-macho, smeenai
Differential Revision: https://reviews.llvm.org/D89639
-rw-r--r-- | lld/MachO/SyntheticSections.h | 9 | ||||
-rw-r--r-- | lld/test/MachO/symtab.s | 21 |
2 files changed, 17 insertions, 13 deletions
diff --git a/lld/MachO/SyntheticSections.h b/lld/MachO/SyntheticSections.h index e52bc480e9aa..56f4bf66ce23 100644 --- a/lld/MachO/SyntheticSections.h +++ b/lld/MachO/SyntheticSections.h @@ -398,11 +398,10 @@ public: void writeTo(uint8_t *buf) const override; private: - // An n_strx value of 0 always indicates the empty string, so we must locate - // our non-empty string values at positive offsets in the string table. - // Therefore we insert a dummy value at position zero. - std::vector<StringRef> strings{"\0"}; - size_t size = 1; + // ld64 emits string tables which start with a space and a zero byte. We + // match its behavior here since some tools depend on it. + std::vector<StringRef> strings{" "}; + size_t size = 2; }; struct SymtabEntry { diff --git a/lld/test/MachO/symtab.s b/lld/test/MachO/symtab.s index 22dc80ad62f3..a4dce665acb4 100644 --- a/lld/test/MachO/symtab.s +++ b/lld/test/MachO/symtab.s @@ -4,11 +4,11 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o # RUN: %lld -dylib %t/libfoo.o -o %t/libfoo.dylib # RUN: %lld -lSystem %t/test.o %t/libfoo.dylib -o %t/test -# RUN: llvm-readobj --syms --macho-dysymtab %t/test | FileCheck %s +# RUN: llvm-readobj --syms --macho-dysymtab %t/test | FileCheck %s # CHECK: Symbols [ # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: _local (1) +# CHECK-NEXT: Name: _local (2) # CHECK-NEXT: Type: Section (0xE) # CHECK-NEXT: Section: __data (0x4) # CHECK-NEXT: RefType: UndefinedNonLazy (0x0) @@ -17,7 +17,7 @@ # CHECK-NEXT: Value: 0x1{{[0-9a-f]*}} # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: _main (8) +# CHECK-NEXT: Name: _main (9) # CHECK-NEXT: Extern # CHECK-NEXT: Type: Section (0xE) # CHECK-NEXT: Section: __text (0x1) @@ -27,7 +27,7 @@ # CHECK-NEXT: Value: 0x1{{[0-9a-f]*}} # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: _external (54) +# CHECK-NEXT: Name: _external (55) # CHECK-NEXT: Extern # CHECK-NEXT: Type: Section (0xE) # CHECK-NEXT: Section: __data (0x4) @@ -37,7 +37,7 @@ # CHECK-NEXT: Value: 0x1{{[0-9a-f]*}} # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: _external_weak (64) +# CHECK-NEXT: Name: _external_weak (65) # CHECK-NEXT: Extern # CHECK-NEXT: Type: Section (0xE) # CHECK-NEXT: Section: __text (0x1) @@ -48,7 +48,7 @@ # CHECK-NEXT: Value: 0x1{{[0-9a-f]*}} # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: __dyld_private (102) +# CHECK-NEXT: Name: __dyld_private (103) # CHECK-NEXT: Extern # CHECK-NEXT: Type: Section (0xE) # CHECK-NEXT: Section: __data (0x4) @@ -58,7 +58,7 @@ # CHECK-NEXT: Value: 0x1{{[0-9a-f]*}} # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: dyld_stub_binder (14) +# CHECK-NEXT: Name: dyld_stub_binder (15) # CHECK-NEXT: Type: Undef (0x0) # CHECK-NEXT: Section: (0x0) # CHECK-NEXT: RefType: UndefinedNonLazy (0x0) @@ -67,7 +67,7 @@ # CHECK-NEXT: Value: 0x0 # CHECK-NEXT: } # CHECK-NEXT: Symbol { -# CHECK-NEXT: Name: _dynamic (79) +# CHECK-NEXT: Name: _dynamic (80) # CHECK-NEXT: Type: Undef (0x0) # CHECK-NEXT: Section: (0x0) # CHECK-NEXT: RefType: UndefinedNonLazy (0x0) @@ -84,6 +84,11 @@ # CHECK-NEXT: iundefsym: 5 # CHECK-NEXT: nundefsym: 2 +## Verify that the first entry in the StringTable is a space. +# RUN: obj2yaml %t/test | FileCheck %s --check-prefix=YAML +# YAML: StringTable: +# YAML-NEXT: ' ' + #--- libfoo.s .globl _dynamic _dynamic: |