[PATCH] D84486: [lld-macho] Support -filelist
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 23 21:21:30 PDT 2020
int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
XCode passes files in using this flag
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84486
Files:
lld/MachO/Driver.cpp
lld/test/MachO/filelist.s
lld/test/MachO/invalid/no-filelist.s
Index: lld/test/MachO/invalid/no-filelist.s
===================================================================
--- /dev/null
+++ lld/test/MachO/invalid/no-filelist.s
@@ -0,0 +1,9 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
+# RUN: not lld -flavor darwinnew -Z -filelist nonexistent %t.o -o %t 2>&1 | FileCheck %s
+# CHECK: cannot open nonexistent: No such file or directory
+
+.globl _main
+
+_main:
+ ret
Index: lld/test/MachO/filelist.s
===================================================================
--- /dev/null
+++ lld/test/MachO/filelist.s
@@ -0,0 +1,40 @@
+# REQUIRES: x86
+
+## This test verifies that the paths in -filelist get processed in command-line
+## order.
+
+# RUN: mkdir -p %t
+# RUN: echo ".globl _foo; .weak_definition _foo; .section __TEXT,first; _foo:" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/first.o
+# RUN: echo ".globl _foo; .weak_definition _foo; .section __TEXT,second; _foo:" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/second.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
+
+# FIRST: __TEXT,first _foo
+# SECOND: __TEXT,second _foo
+
+# RUN: echo "%t/first.o" > filelist
+# RUN: echo "%t/second.o" >> filelist
+# RUN: lld -flavor darwinnew -Z -filelist filelist %t/test.o -o %t/test
+# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=FIRST
+
+# RUN: echo "%t/second.o" > filelist
+# RUN: echo "%t/first.o" >> filelist
+# RUN: lld -flavor darwinnew -Z -filelist filelist %t/test.o -o %t/test
+# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=SECOND
+
+# RUN: echo "%t/first.o" > filelist
+# RUN: lld -flavor darwinnew -Z -filelist filelist %t/second.o %t/test.o -o %t/test
+# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=FIRST
+# RUN: lld -flavor darwinnew -Z %t/second.o -filelist filelist %t/test.o -o %t/test
+# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=SECOND
+
+# RUN: echo "%t/first.o" > filelist-1
+# RUN: echo "%t/second.o" > filelist-2
+# RUN: lld -flavor darwinnew -Z -filelist filelist-1 -filelist filelist-2 %t/test.o -o %t/test
+# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=FIRST
+# RUN: lld -flavor darwinnew -Z -filelist filelist-2 -filelist filelist-1 %t/test.o -o %t/test
+# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=SECOND
+
+.globl _main
+
+_main:
+ ret
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -214,6 +214,15 @@
}
}
+static void addFileList(StringRef path) {
+ Optional<MemoryBufferRef> buffer = readFile(path);
+ if (!buffer)
+ return;
+ MemoryBufferRef mbref = *buffer;
+ for (StringRef path : args::getLines(mbref))
+ addFile(path);
+}
+
static std::array<StringRef, 6> archNames{"arm", "arm64", "i386",
"x86_64", "ppc", "ppc64"};
static bool isArchString(StringRef s) {
@@ -412,6 +421,9 @@
case OPT_INPUT:
addFile(arg->getValue());
break;
+ case OPT_filelist:
+ addFileList(arg->getValue());
+ break;
case OPT_l: {
StringRef name = arg->getValue();
if (Optional<std::string> path = findLibrary(name)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84486.280323.patch
Type: text/x-patch
Size: 3307 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200724/a121cdbe/attachment.bin>
More information about the llvm-commits
mailing list