diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -213,6 +213,15 @@ } } +static void addFileList(StringRef path) { + Optional buffer = readFile(path); + if (!buffer) + return; + MemoryBufferRef mbref = *buffer; + for (StringRef path : args::getLines(mbref)) + addFile(path); +} + static std::array archNames{"arm", "arm64", "i386", "x86_64", "ppc", "ppc64"}; static bool isArchString(StringRef s) { @@ -411,6 +420,9 @@ case OPT_INPUT: addFile(arg->getValue()); break; + case OPT_filelist: + addFileList(arg->getValue()); + break; case OPT_l: { StringRef name = arg->getValue(); if (Optional path = findLibrary(name)) { diff --git a/lld/test/MachO/filelist.s b/lld/test/MachO/filelist.s new file mode 100644 --- /dev/null +++ b/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 diff --git a/lld/test/MachO/invalid/no-filelist.s b/lld/test/MachO/invalid/no-filelist.s new file mode 100644 --- /dev/null +++ b/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