Index: lld/MachO/SyntheticSections.cpp =================================================================== --- lld/MachO/SyntheticSections.cpp +++ lld/MachO/SyntheticSections.cpp @@ -24,6 +24,7 @@ #include "llvm/Support/LEB128.h" #include "llvm/Support/Parallel.h" #include "llvm/Support/Path.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/Support/xxhash.h" #if defined(__APPLE__) @@ -1208,7 +1209,10 @@ } void SymtabSection::finalizeContents() { + SmallPtrSet seenSymbols; auto addSymbol = [&](std::vector &symbols, Symbol *sym) { + if (seenSymbols.insert(sym).second != true) + return; uint32_t strx = stringTableSection.addString(sym->getName()); symbols.push_back({sym, strx}); }; Index: lld/test/MachO/private-label-alias.s =================================================================== --- lld/test/MachO/private-label-alias.s +++ lld/test/MachO/private-label-alias.s @@ -26,9 +26,11 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weak-then-private.s -o %t/weak-then-private.o # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/private-then-weak.s -o %t/private-then-weak.o # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/no-dead-strip.s -o %t/no-dead-strip.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/all-local.s -o %t/all-local.o # RUN: %lld -dylib %t/weak-then-private.o %t/private-then-weak.o -o %t/test1 # RUN: %lld -dylib %t/private-then-weak.o %t/weak-then-private.o -o %t/test2 # RUN: %lld -dead_strip %t/no-dead-strip.o -o %t/no-dead-strip +# RUN: %lld -dylib %t/all-local.o -o %t/all-local # RUN: llvm-objdump --macho --syms --section="__DATA,__data" --weak-bind %t/test1 | FileCheck %s # RUN: llvm-objdump --macho --syms --section="__DATA,__data" --weak-bind %t/test2 | FileCheck %s @@ -59,6 +61,13 @@ # RUN: --check-prefix=NO-DEAD-STRIP # NO-DEAD-STRIP: __data 00000010 +## Ensure that a private alias to a local label doesn't write two identical +## entries to the symbol table. +# RUN: llvm-objdump --macho --syms %t/all-local | FileCheck %s --check-prefix=NO-DUPES +# NO-DUPES: SYMBOL TABLE: +# NO-DUPES-NEXT: 00000000000002c8 l F __TEXT,__text _label +# NO-DUPES-NEXT: 00000000000002d0 l F __TEXT,__text _ref + #--- weak-then-private.s .globl _weak .weak_definition _weak @@ -103,3 +112,15 @@ .quad 0x123 .subsections_via_symbols + +#--- all-local.s +.text + +l_ignored: +_label: + .quad 0x123 + +_ref: + .quad l_ignored + +.subsections_via_symbols