[lld-macho] Implement -hidden-l
Similarly to -load_hidden, this flag instructs the linker to not export symbols from the specified archive. While that flag takes a path, -hidden-l looks for the specified library name in the search path. The test changes are needed because -hidden-lfoo resolves to libfoo.a, not foo.a. Differential Revision: https://reviews.llvm.org/D130529
This commit is contained in:
parent
b9aedd94e6
commit
b2c53a9217
|
@ -407,10 +407,12 @@ static InputFile *addFile(StringRef path, LoadType loadType,
|
|||
}
|
||||
|
||||
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<StringRef> path = findLibrary(name)) {
|
||||
if (auto *dylibFile = dyn_cast_or_null<DylibFile>(
|
||||
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 @@ void macho::parseLCLinkerOption(InputFile *f, unsigned argc, StringRef data) {
|
|||
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 @@ static void createFiles(const InputArgList &args) {
|
|||
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:
|
||||
|
|
|
@ -244,6 +244,10 @@ def load_hidden : Separate<["-"], "load_hidden">,
|
|||
MetaVarName<"<path>">,
|
||||
HelpText<"Load all symbols from static library with hidden visibility">,
|
||||
Group<grp_libs>;
|
||||
def hidden_l : Joined<["-"], "hidden-l">,
|
||||
MetaVarName<"<name>">,
|
||||
HelpText<"Like -l<name>, but load all symbols with hidden visibility">,
|
||||
Group<grp_libs>;
|
||||
|
||||
def grp_content : OptionGroup<"content">, HelpText<"ADDITIONAL CONTENT">;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue