Index: lld/MachO/Driver.cpp =================================================================== --- lld/MachO/Driver.cpp +++ lld/MachO/Driver.cpp @@ -324,24 +324,34 @@ return newFile; } -static void addLibrary(StringRef name, bool isWeak, bool isExplicit = true) { +static void addLibrary(StringRef name, bool isWeak, bool isReexport, + bool isExplicit) { if (Optional path = findLibrary(name)) { if (auto *dylibFile = dyn_cast_or_null(addFile(*path, false))) { dylibFile->explicitlyLinked = isExplicit; if (isWeak) dylibFile->forceWeakImport = true; + if (isReexport) { + config->hasReexports = true; + dylibFile->reexport = true; + } } return; } error("library not found for -l" + name); } -static void addFramework(StringRef name, bool isWeak, bool isExplicit = true) { +static void addFramework(StringRef name, bool isWeak, bool isReexport, + bool isExplicit) { if (Optional path = findFramework(name)) { if (auto *dylibFile = dyn_cast_or_null(addFile(*path, false))) { dylibFile->explicitlyLinked = isExplicit; if (isWeak) dylibFile->forceWeakImport = true; + if (isReexport) { + config->hasReexports = true; + dylibFile->reexport = true; + } } return; } @@ -371,10 +381,12 @@ for (const Arg *arg : args) { switch (arg->getOption().getID()) { case OPT_l: - addLibrary(arg->getValue(), /*isWeak=*/false, /*isExplicit=*/false); + addLibrary(arg->getValue(), /*isWeak=*/false, /*isReexport=*/false, + /*isExplicit=*/false); break; case OPT_framework: - addFramework(arg->getValue(), /*isWeak=*/false, /*isExplicit=*/false); + addFramework(arg->getValue(), /*isWeak=*/false, /*isReexport=*/false, + /*isExplicit=*/false); break; default: error(arg->getSpelling() + " is not allowed in LC_LINKER_OPTION"); @@ -866,6 +878,13 @@ case OPT_INPUT: addFile(rerootPath(arg->getValue()), false); break; + case OPT_reexport_library: + if (auto *dylibFile = dyn_cast_or_null( + addFile(rerootPath(arg->getValue()), false))) { + config->hasReexports = true; + dylibFile->reexport = true; + } + break; case OPT_weak_library: if (auto *dylibFile = dyn_cast_or_null( addFile(rerootPath(arg->getValue()), false))) @@ -878,12 +897,16 @@ addFile(rerootPath(arg->getValue()), true); break; case OPT_l: + case OPT_reexport_l: case OPT_weak_l: - addLibrary(arg->getValue(), opt.getID() == OPT_weak_l); + addLibrary(arg->getValue(), opt.getID() == OPT_weak_l, + opt.getID() == OPT_reexport_l, /*isExplicit=*/true); break; case OPT_framework: + case OPT_reexport_framework: case OPT_weak_framework: - addFramework(arg->getValue(), opt.getID() == OPT_weak_framework); + addFramework(arg->getValue(), opt.getID() == OPT_weak_framework, + opt.getID() == OPT_reexport_framework, /*isExplicit=*/true); break; default: break; Index: lld/MachO/Options.td =================================================================== --- lld/MachO/Options.td +++ lld/MachO/Options.td @@ -117,12 +117,10 @@ def reexport_l : Joined<["-"], "reexport-l">, MetaVarName<"">, HelpText<"Like -l, but export all symbols of from newly created library">, - Flags<[HelpHidden]>, Group; def reexport_library : Separate<["-"], "reexport_library">, MetaVarName<"">, HelpText<"Like bare , but export all symbols of from newly created library">, - Flags<[HelpHidden]>, Group; def upward_l : Joined<["-"], "upward-l">, MetaVarName<"">, @@ -162,7 +160,6 @@ def reexport_framework : Separate<["-"], "reexport_framework">, MetaVarName<"">, HelpText<"Like -framework , but export all symbols of from the newly created library">, - Flags<[HelpHidden]>, Group; def upward_framework : Separate<["-"], "upward_framework">, MetaVarName<"">, Index: lld/test/MachO/sub-library.s =================================================================== --- lld/test/MachO/sub-library.s +++ lld/test/MachO/sub-library.s @@ -18,14 +18,23 @@ ## Check that they have the appropriate LC_REEXPORT_DYLIB commands, and that ## NO_REEXPORTED_DYLIBS is (un)set as appropriate. -# RUN: llvm-objdump --macho --all-headers %t/libhello.dylib | FileCheck %s \ -# RUN: --check-prefix=HELLO-HEADERS +# RUN: llvm-otool -hv %t/libhello.dylib | \ +# RUN: FileCheck --check-prefix=HELLO-HEADERS %s # HELLO-HEADERS: NO_REEXPORTED_DYLIBS -# RUN: llvm-objdump --macho --all-headers %t/libgoodbye.dylib | FileCheck %s \ +# RUN: llvm-otool -l %t/libgoodbye.dylib | FileCheck %s \ # RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libhello.dylib -# RUN: llvm-objdump --macho --all-headers %t/libsuper.dylib | FileCheck %s \ +# RUN: llvm-otool -l %t/libsuper.dylib | FileCheck %s \ +# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libgoodbye.dylib + +# RUN: %lld -dylib -L%t -reexport-lgoodbye -install_name \ +# RUN: @executable_path/libsuper.dylib %t/libsuper.o -o %t/libsuper.dylib +# RUN: llvm-otool -l %t/libsuper.dylib | FileCheck %s \ +# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libgoodbye.dylib +# RUN: %lld -dylib -reexport_library %t/libgoodbye.dylib -install_name \ +# RUN: @executable_path/libsuper.dylib %t/libsuper.o -o %t/libsuper.dylib +# RUN: llvm-otool -l %t/libsuper.dylib | FileCheck %s \ # RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/libgoodbye.dylib # REEXPORT-HEADERS-NOT: NO_REEXPORTED_DYLIBS @@ -53,16 +62,24 @@ ## We can match dylibs without extensions too. -# RUN: mkdir -p %t/Hello.framework/Versions -# RUN: %lld -dylib %t/libhello.o -o %t/Hello.framework/Versions/Hello -# RUN: %lld -dylib -o %t/libgoodbye2.dylib -sub_library Hello %t/Hello.framework/Versions/Hello %t/libgoodbye.o -# RUN: llvm-objdump --macho --all-headers %t/libgoodbye2.dylib | FileCheck %s \ -# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Versions/Hello +# RUN: mkdir -p %t/Hello.framework +# RUN: %lld -dylib %t/libhello.o -o %t/Hello.framework/Hello +# RUN: %lld -dylib -o %t/libgoodbye2.dylib -sub_library Hello %t/Hello.framework/Hello %t/libgoodbye.o +# RUN: llvm-otool -l %t/libgoodbye2.dylib | FileCheck %s \ +# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello ## -sub_umbrella works almost identically... -# RUN: %lld -dylib -o %t/libgoodbye3.dylib -sub_umbrella Hello %t/Hello.framework/Versions/Hello %t/libgoodbye.o -# RUN: llvm-objdump --macho --all-headers %t/libgoodbye3.dylib | FileCheck %s \ -# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Versions/Hello +# RUN: %lld -dylib -o %t/libgoodbye3.dylib -sub_umbrella Hello %t/Hello.framework/Hello %t/libgoodbye.o +# RUN: llvm-otool -l %t/libgoodbye3.dylib | FileCheck %s \ +# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello + +# RUN: %lld -dylib -o %t/libgoodbye3.dylib -F %t -framework Hello -sub_umbrella Hello %t/libgoodbye.o +# RUN: llvm-otool -l %t/libgoodbye3.dylib | FileCheck %s \ +# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello + +# RUN: %lld -dylib -o %t/libgoodbye3.dylib -F %t -reexport_framework Hello %t/libgoodbye.o +# RUN: llvm-otool -l %t/libgoodbye3.dylib | FileCheck %s \ +# RUN: --check-prefix=REEXPORT-HEADERS -DPATH=%t/Hello.framework/Hello ## But it doesn't match .dylib extensions: # RUN: not %lld -dylib -L%t -sub_umbrella libhello -lhello %t/libgoodbye.o \