Skip to content

Commit d09f3d7

Browse files
committed
Address Comments #1 & fix test for Windows
1 parent dc3fbc0 commit d09f3d7

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

lld/MachO/SyntheticSections.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ void StubHelperSection::writeTo(uint8_t *buf) const {
791791

792792
void StubHelperSection::setUp() {
793793
Symbol *binder = symtab->addUndefined("dyld_stub_binder", /*file=*/nullptr,
794-
/*isWeakRef=*/false);
794+
/*isWeakRef=*/false);
795795
if (auto *undefined = dyn_cast<Undefined>(binder))
796796
treatUndefinedSymbol(*undefined,
797797
"lazy binding (normally in libSystem.dylib)");
@@ -1182,7 +1182,7 @@ void SymtabSection::emitObjectFileStab(ObjFile *file) {
11821182
StabsEntry stab(N_OSO);
11831183
stab.sect = target->cpuSubtype;
11841184
SmallString<261> path(!file->archiveName.empty() ? file->archiveName
1185-
: file->getName());
1185+
: file->getName());
11861186
std::error_code ec = sys::fs::make_absolute(path);
11871187
if (ec)
11881188
fatal("failed to get absolute path for " + path);
@@ -1540,24 +1540,17 @@ StringTableSection::StringTableSection()
15401540
: LinkEditSection(segment_names::linkEdit, section_names::stringTable) {}
15411541

15421542
uint32_t StringTableSection::addString(StringRef str) {
1543-
// If deduplication is disabled, just add the string
1544-
if (!config->deduplicateSymbolStrings) {
1545-
uint32_t strx = size;
1546-
strings.push_back(str);
1547-
size += str.size() + 1; // +1 for null terminator
1548-
return strx;
1549-
}
1550-
1551-
// Deduplicate strings
1552-
llvm::CachedHashStringRef hashedStr(str);
1553-
auto it = stringMap.find(hashedStr);
1554-
if (it != stringMap.end())
1555-
return it->second;
1556-
15571543
uint32_t strx = size;
1558-
stringMap[hashedStr] = strx;
1544+
if (config->deduplicateSymbolStrings) {
1545+
// Deduplicate strings
1546+
llvm::CachedHashStringRef hashedStr(str);
1547+
auto [it, inserted] = stringMap.try_emplace(hashedStr, strx);
1548+
if (!inserted)
1549+
return it->second;
1550+
}
1551+
15591552
strings.push_back(str);
1560-
size += str.size() + 1;
1553+
size += str.size() + 1; // +1 for null terminator
15611554
return strx;
15621555
}
15631556

lld/test/MachO/cfstring-dedup.s

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010
# Check that string deduplication for symbol names is working
1111
# RUN: %lld -dylib -framework CoreFoundation %t/foo1.o %t/foo2.o -o %t/foo_no_dedup -no-deduplicate-symbol-strings
12-
# RUN: count1=$((`llvm-strings %t/foo | grep _named_cfstring | wc -l`))
13-
# RUN: test $count1 -eq 1
14-
# RUN: count2=$((`llvm-strings %t/foo_no_dedup | grep _named_cfstring | wc -l`))
15-
# RUN: test $count2 -eq 2
12+
# RUN: llvm-strings %t/foo | FileCheck %s --check-prefix=CHECK-DEDUP
13+
# RUN: llvm-strings %t/foo_no_dedup | FileCheck %s --check-prefix=CHECK-NO-DEDUP
14+
# CHECK-DEDUP: _named_cfstring
15+
# CHECK-DEDUP-NOT: _named_cfstring
16+
# CHECK-NO-DEDUP: _named_cfstring
17+
# CHECK-NO-DEDUP: _named_cfstring
18+
# CHECK-NO-DEDUP-NOT: _named_cfstring
1619

1720

1821
# CHECK: (__TEXT,__text) section

0 commit comments

Comments
 (0)