Skip to content

Commit fa825fc

Browse files
author
git apple-llvm automerger
committed
Merge commit '1f470a3ad031' from apple/main into swift/next
2 parents 30c49b0 + 1f470a3 commit fa825fc

File tree

6 files changed

+36
-32
lines changed

6 files changed

+36
-32
lines changed

lld/MachO/Driver.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,7 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive) {
274274
if (config->allLoad || forceLoadArchive) {
275275
if (Optional<MemoryBufferRef> buffer = readFile(path)) {
276276
for (const ArchiveMember &member : getArchiveMembers(*buffer)) {
277-
inputFiles.push_back(
278-
make<ObjFile>(member.mbref, member.modTime, path));
277+
inputFiles.insert(make<ObjFile>(member.mbref, member.modTime, path));
279278
printArchiveMemberLoad(
280279
(forceLoadArchive ? "-force_load" : "-all_load"),
281280
inputFiles.back());
@@ -293,7 +292,7 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive) {
293292
if (Optional<MemoryBufferRef> buffer = readFile(path)) {
294293
for (const ArchiveMember &member : getArchiveMembers(*buffer)) {
295294
if (hasObjCSection(member.mbref)) {
296-
inputFiles.push_back(
295+
inputFiles.insert(
297296
make<ObjFile>(member.mbref, member.modTime, path));
298297
printArchiveMemberLoad("-ObjC", inputFiles.back());
299298
}
@@ -325,7 +324,7 @@ static InputFile *addFile(StringRef path, bool forceLoadArchive) {
325324
// print the .a name here.
326325
if (config->printEachFile && magic != file_magic::archive)
327326
lld::outs() << toString(newFile) << '\n';
328-
inputFiles.push_back(newFile);
327+
inputFiles.insert(newFile);
329328
}
330329
return newFile;
331330
}
@@ -521,7 +520,7 @@ static void compileBitcodeFiles() {
521520
lto->add(*bitcodeFile);
522521

523522
for (ObjFile *file : lto->compile())
524-
inputFiles.push_back(file);
523+
inputFiles.insert(file);
525524
}
526525

527526
// Replaces common symbols with defined symbols residing in __common sections.
@@ -873,7 +872,7 @@ bool macho::link(llvm::ArrayRef<const char *> argsArr, bool canExitEarly,
873872
StringRef fileName = arg->getValue(2);
874873
Optional<MemoryBufferRef> buffer = readFile(fileName);
875874
if (buffer)
876-
inputFiles.push_back(make<OpaqueFile>(*buffer, segName, sectName));
875+
inputFiles.insert(make<OpaqueFile>(*buffer, segName, sectName));
877876
}
878877

879878
// Initialize InputSections.

lld/MachO/DriverUtils.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "lld/Common/Memory.h"
1616
#include "lld/Common/Reproduce.h"
1717
#include "llvm/ADT/CachedHashString.h"
18-
#include "llvm/ADT/DenseSet.h"
18+
#include "llvm/ADT/DenseMap.h"
1919
#include "llvm/Option/Arg.h"
2020
#include "llvm/Option/ArgList.h"
2121
#include "llvm/Option/Option.h"
@@ -168,33 +168,32 @@ Optional<std::string> macho::resolveDylibPath(StringRef path) {
168168
return {};
169169
}
170170

171-
static Optional<DylibFile *> makeDylibFromTapi(MemoryBufferRef mbref,
172-
DylibFile *umbrella) {
173-
Expected<std::unique_ptr<InterfaceFile>> result = TextAPIReader::get(mbref);
174-
if (!result) {
175-
error("could not load TAPI file at " + mbref.getBufferIdentifier() + ": " +
176-
toString(result.takeError()));
177-
return {};
178-
}
179-
return make<DylibFile>(**result, umbrella);
180-
}
181-
182-
static DenseSet<CachedHashStringRef> loadedDylibs;
171+
// It's not uncommon to have multiple attempts to load a single dylib,
172+
// especially if it's a commonly re-exported core library.
173+
static DenseMap<CachedHashStringRef, DylibFile *> loadedDylibs;
183174

184175
Optional<DylibFile *> macho::loadDylib(MemoryBufferRef mbref,
185176
DylibFile *umbrella) {
186177
StringRef path = mbref.getBufferIdentifier();
187-
if (loadedDylibs.contains(CachedHashStringRef(path)))
188-
return {};
189-
loadedDylibs.insert(CachedHashStringRef(path));
178+
DylibFile *&file = loadedDylibs[CachedHashStringRef(path)];
179+
if (file)
180+
return file;
190181

191182
file_magic magic = identify_magic(mbref.getBuffer());
192-
if (magic == file_magic::tapi_file)
193-
return makeDylibFromTapi(mbref, umbrella);
194-
195-
assert(magic == file_magic::macho_dynamically_linked_shared_lib ||
196-
magic == file_magic::macho_dynamically_linked_shared_lib_stub);
197-
return make<DylibFile>(mbref, umbrella);
183+
if (magic == file_magic::tapi_file) {
184+
Expected<std::unique_ptr<InterfaceFile>> result = TextAPIReader::get(mbref);
185+
if (!result) {
186+
error("could not load TAPI file at " + mbref.getBufferIdentifier() +
187+
": " + toString(result.takeError()));
188+
return {};
189+
}
190+
file = make<DylibFile>(**result, umbrella);
191+
} else {
192+
assert(magic == file_magic::macho_dynamically_linked_shared_lib ||
193+
magic == file_magic::macho_dynamically_linked_shared_lib_stub);
194+
file = make<DylibFile>(mbref, umbrella);
195+
}
196+
return file;
198197
}
199198

200199
uint32_t macho::getModTime(StringRef path) {

lld/MachO/InputFiles.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ std::string lld::toString(const InputFile *f) {
8585
.str();
8686
}
8787

88-
std::vector<InputFile *> macho::inputFiles;
88+
SetVector<InputFile *> macho::inputFiles;
8989
std::unique_ptr<TarWriter> macho::tar;
9090
int InputFile::idCount = 0;
9191

@@ -516,7 +516,7 @@ static bool isImplicitlyLinked(StringRef path) {
516516
void loadReexport(StringRef path, DylibFile *umbrella) {
517517
Optional<DylibFile *> reexport = loadReexportHelper(path, umbrella);
518518
if (reexport && isImplicitlyLinked(path))
519-
inputFiles.push_back(*reexport);
519+
inputFiles.insert(*reexport);
520520
}
521521

522522
DylibFile::DylibFile(MemoryBufferRef mb, DylibFile *umbrella)
@@ -670,7 +670,7 @@ void ArchiveFile::fetch(const object::Archive::Symbol &sym) {
670670
" has unhandled file type");
671671
return;
672672
}
673-
inputFiles.push_back(file);
673+
inputFiles.insert(file);
674674

675675
// ld64 doesn't demangle sym here even with -demangle. Match that, so
676676
// intentionally no call to toMachOString() here.

lld/MachO/InputFiles.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "lld/Common/LLVM.h"
1515
#include "lld/Common/Memory.h"
1616
#include "llvm/ADT/DenseSet.h"
17+
#include "llvm/ADT/SetVector.h"
1718
#include "llvm/BinaryFormat/MachO.h"
1819
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
1920
#include "llvm/Object/Archive.h"
@@ -158,7 +159,7 @@ class BitcodeFile : public InputFile {
158159
std::unique_ptr<llvm::lto::InputFile> obj;
159160
};
160161

161-
extern std::vector<InputFile *> inputFiles;
162+
extern llvm::SetVector<InputFile *> inputFiles;
162163

163164
llvm::Optional<MemoryBufferRef> readFile(StringRef path);
164165

lld/test/MachO/invalid/duplicate-symbol.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
33
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t-dup.o
44
# RUN: not %lld -o /dev/null %t-dup.o %t.o 2>&1 | FileCheck %s
5+
# RUN: not %lld -o /dev/null %t.o %t.o 2>&1 | FileCheck %s
56

67
# CHECK: error: duplicate symbol: _main
78

lld/test/MachO/weak-import.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
# RUN: %lld -weak-lSystem %t/test.o -weak_framework CoreFoundation -weak_library %t/libfoo.dylib -o %t/test
88
# RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s -DDIR=%t
9+
# RUN: %lld -weak-lSystem %t/test.o \
10+
# RUN: -framework CoreFoundation -weak_framework CoreFoundation -framework CoreFoundation \
11+
# RUN: %t/libfoo.dylib -weak_library %t/libfoo.dylib %t/libfoo.dylib -o %t/test
12+
# RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s -DDIR=%t
913

1014
# CHECK: cmd LC_LOAD_WEAK_DYLIB
1115
# CHECK-NEXT: cmdsize

0 commit comments

Comments
 (0)