[lld] 62b39b3 - [lld-macho] Implement -all_load
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 26 19:27:04 PDT 2020
Author: Jez Ng
Date: 2020-08-26T19:21:17-07:00
New Revision: 62b39b3a0cb287809d208fb4959526d37d4ded02
URL: https://github.com/llvm/llvm-project/commit/62b39b3a0cb287809d208fb4959526d37d4ded02
DIFF: https://github.com/llvm/llvm-project/commit/62b39b3a0cb287809d208fb4959526d37d4ded02.diff
LOG: [lld-macho] Implement -all_load
Differential Revision: https://reviews.llvm.org/D86640
Added:
Modified:
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/test/MachO/archive.s
Removed:
################################################################################
diff --git a/lld/MachO/Config.h b/lld/MachO/Config.h
index c126dbebe76d..5fbb477c1993 100644
--- a/lld/MachO/Config.h
+++ b/lld/MachO/Config.h
@@ -33,6 +33,7 @@ struct PlatformInfo {
struct Configuration {
Symbol *entry;
bool hasReexports = false;
+ bool allLoad = false;
bool forceLoadObjC = false;
uint32_t headerPad;
llvm::StringRef installName;
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 90aaa219c409..cda82ecd5630 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -248,7 +248,11 @@ static void addFile(StringRef path) {
if (!file->isEmpty() && !file->hasSymbolTable())
error(path + ": archive has no index; run ranlib to add one");
- if (config->forceLoadObjC) {
+ if (config->allLoad) {
+ if (Optional<MemoryBufferRef> buffer = readFile(path))
+ for (MemoryBufferRef member : getArchiveMembers(*buffer))
+ inputFiles.push_back(make<ObjFile>(member));
+ } else if (config->forceLoadObjC) {
for (const object::Archive::Symbol &sym : file->symbols())
if (sym.getName().startswith(objc::klass))
symtab->addUndefined(sym.getName());
@@ -519,6 +523,7 @@ bool macho::link(llvm::ArrayRef<const char *> argsArr, bool canExitEarly,
config->headerPad = args::getHex(args, OPT_headerpad, /*Default=*/32);
config->outputType = args.hasArg(OPT_dylib) ? MH_DYLIB : MH_EXECUTE;
config->runtimePaths = args::getStrings(args, OPT_rpath);
+ config->allLoad = args.hasArg(OPT_all_load);
std::vector<StringRef> &roots = config->systemLibraryRoots;
for (const Arg *arg : args.filtered(OPT_syslibroot))
@@ -583,6 +588,7 @@ bool macho::link(llvm::ArrayRef<const char *> argsArr, bool canExitEarly,
case OPT_platform_version:
handlePlatformVersion(arg);
break;
+ case OPT_all_load:
case OPT_o:
case OPT_dylib:
case OPT_e:
diff --git a/lld/test/MachO/archive.s b/lld/test/MachO/archive.s
index 370980768faa..cb81fb0de47f 100644
--- a/lld/test/MachO/archive.s
+++ b/lld/test/MachO/archive.s
@@ -22,11 +22,17 @@
# ARCHIVE-FIRST: T _boo
# ARCHIVE-FIRST: T _main
-
# RUN: llvm-nm %t/test.out | FileCheck %s --check-prefix VISIBLE
# VISIBLE-NOT: T _undefined
# VISIBLE-NOT: T _unused
+# RUN: lld -flavor darwinnew %t/test.a %t/main.o -o %t/all-load -all_load
+# RUN: llvm-nm %t/all-load | FileCheck %s --check-prefix ALL-LOAD
+# ALL-LOAD: T _bar
+# ALL-LOAD: T _boo
+# ALL-LOAD: T _main
+# ALL-LOAD: T _unused
+
.global _main
_main:
callq _boo
More information about the llvm-commits
mailing list