Index: lld/MachO/Driver.cpp =================================================================== --- lld/MachO/Driver.cpp +++ lld/MachO/Driver.cpp @@ -407,10 +407,12 @@ } static void addLibrary(StringRef name, bool isNeeded, bool isWeak, - bool isReexport, bool isExplicit, LoadType loadType) { + bool isReexport, bool isHidden, bool isExplicit, + LoadType loadType) { if (Optional path = findLibrary(name)) { if (auto *dylibFile = dyn_cast_or_null( - addFile(*path, loadType, /*isLazy=*/false, isExplicit))) { + addFile(*path, loadType, /*isLazy=*/false, isExplicit, + /*isBundleLoader=*/false, isHidden))) { if (isNeeded) dylibFile->forceNeeded = true; if (isWeak) @@ -474,7 +476,7 @@ StringRef arg = argv[i]; if (arg.consume_front("-l")) { addLibrary(arg, /*isNeeded=*/false, /*isWeak=*/false, - /*isReexport=*/false, /*isExplicit=*/false, + /*isReexport=*/false, /*isHidden=*/false, /*isExplicit=*/false, LoadType::LCLinkerOption); } else if (arg == "-framework") { StringRef name = argv[++i]; @@ -1045,8 +1047,10 @@ case OPT_needed_l: case OPT_reexport_l: case OPT_weak_l: + case OPT_hidden_l: addLibrary(arg->getValue(), opt.getID() == OPT_needed_l, opt.getID() == OPT_weak_l, opt.getID() == OPT_reexport_l, + opt.getID() == OPT_hidden_l, /*isExplicit=*/true, LoadType::CommandLine); break; case OPT_framework: Index: lld/MachO/Options.td =================================================================== --- lld/MachO/Options.td +++ lld/MachO/Options.td @@ -244,6 +244,10 @@ MetaVarName<"">, HelpText<"Load all symbols from static library with hidden visibility">, Group; +def hidden_l : Joined<["-"], "hidden-l">, + MetaVarName<"">, + HelpText<"Like -l, but load all symbols with hidden visibility">, + Group; def grp_content : OptionGroup<"content">, HelpText<"ADDITIONAL CONTENT">; Index: lld/test/MachO/load-hidden.s =================================================================== --- lld/test/MachO/load-hidden.s +++ lld/test/MachO/load-hidden.s @@ -2,51 +2,53 @@ # RUN: rm -rf %t; split-file %s %t # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/archive-foo.s -o %t/archive-foo.o # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/archive-baz.s -o %t/archive-baz.o -# RUN: llvm-ar rcs %t/foo.a %t/archive-foo.o -# RUN: llvm-ar rcs %t/baz.a %t/archive-baz.o +# RUN: llvm-ar rcs %t/libfoo.a %t/archive-foo.o +# RUN: llvm-ar rcs %t/libbaz.a %t/archive-baz.o # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/obj.s -o %t/obj.o # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/obj-bar.s -o %t/obj-bar.o -# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/foo.a -o %t/test.dylib +# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/libfoo.a -o %t/test.dylib # RUN: llvm-nm %t/test.dylib | FileCheck %s +# RUN: %lld -dylib -lSystem -L%t %t/obj.o -hidden-lfoo -o %t/test2.dylib +# RUN: llvm-nm %t/test2.dylib | FileCheck %s # CHECK-DAG: t _foo # CHECK-DAG: d _bar ## If an archive has already been loaded without -load_hidden earlier in the command line, ## -load_hidden does not have an effect. -# RUN: %lld -dylib -lSystem %t/obj.o %t/foo.a -load_hidden %t/foo.a -o %t/test-regular-then-hidden.dylib +# RUN: %lld -dylib -lSystem %t/obj.o %t/libfoo.a -load_hidden %t/libfoo.a -o %t/test-regular-then-hidden.dylib # RUN: llvm-nm %t/test-regular-then-hidden.dylib | FileCheck %s --check-prefix=REGULAR-THEN-HIDDEN # REGULAR-THEN-HIDDEN-DAG: T _foo # REGULAR-THEN-HIDDEN-DAG: D _bar ## If -load_hidden comes first, the symbols will have hidden visibility. -# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/foo.a %t/foo.a -o %t/test-hidden-then-regular.dylib +# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/libfoo.a %t/libfoo.a -o %t/test-hidden-then-regular.dylib # RUN: llvm-nm %t/test-hidden-then-regular.dylib | FileCheck %s --check-prefix=HIDDEN-THEN-REGULAR # HIDDEN-THEN-REGULAR-DAG: t _foo # HIDDEN-THEN-REGULAR-DAG: d _bar ## If both -load_hidden and -force_load are specified, the earlier one will have an effect. -# RUN: %lld -dylib -lSystem %t/obj.o %t/foo.a -force_load %t/baz.a -load_hidden %t/baz.a -o %t/test-force-then-hidden.dylib +# RUN: %lld -dylib -lSystem %t/obj.o %t/libfoo.a -force_load %t/libbaz.a -load_hidden %t/libbaz.a -o %t/test-force-then-hidden.dylib # RUN: llvm-nm %t/test-force-then-hidden.dylib | FileCheck %s --check-prefix=FORCE-THEN-HIDDEN # FORCE-THEN-HIDDEN: T _baz -# RUN: %lld -dylib -lSystem %t/obj.o %t/foo.a -load_hidden %t/baz.a -force_load %t/baz.a -o %t/test-hidden-then-force.dylib +# RUN: %lld -dylib -lSystem %t/obj.o %t/libfoo.a -load_hidden %t/libbaz.a -force_load %t/libbaz.a -o %t/test-hidden-then-force.dylib # RUN: llvm-nm %t/test-hidden-then-force.dylib | FileCheck %s --check-prefix=HIDDEN-THEN-FORCE # HIDDEN-THEN-FORCE-NOT: _baz ## -load_hidden does not cause the library to be loaded eagerly. -# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/foo.a -load_hidden %t/baz.a -o %t/test-lazy.dylib +# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/libfoo.a -load_hidden %t/libbaz.a -o %t/test-lazy.dylib # RUN: llvm-nm %t/test-lazy.dylib | FileCheck %s --check-prefix=LAZY # LAZY-NOT: _baz ## Specifying the same library twice is fine. -# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/foo.a -load_hidden %t/foo.a -o %t/test-twice.dylib +# RUN: %lld -dylib -lSystem %t/obj.o -load_hidden %t/libfoo.a -load_hidden %t/libfoo.a -o %t/test-twice.dylib # RUN: llvm-nm %t/test-twice.dylib | FileCheck %s --check-prefix=TWICE # TWICE-DAG: t _foo # TWICE-DAG: d _bar ## -load_hidden causes the symbols to have "private external" visibility, so duplicate definitions ## are not allowed. -# RUN: not %lld -dylib -lSystem %t/obj.o %t/obj-bar.o -load_hidden %t/foo.a 2>&1 | FileCheck %s --check-prefix=DUP +# RUN: not %lld -dylib -lSystem %t/obj.o %t/obj-bar.o -load_hidden %t/libfoo.a 2>&1 | FileCheck %s --check-prefix=DUP # DUP: error: duplicate symbol: _bar #--- archive-foo.s