diff --git a/include/swift/Driver/ToolChain.h b/include/swift/Driver/ToolChain.h index 783b812e4d4b6..c5cede418d0eb 100644 --- a/include/swift/Driver/ToolChain.h +++ b/include/swift/Driver/ToolChain.h @@ -195,6 +195,9 @@ class ToolChain { /// relative to the compiler. void getRuntimeLibraryPath(SmallVectorImpl &runtimeLibPath, const llvm::opt::ArgList &args, bool shared) const; + void getRuntimeLibraryPathWithArch(SmallVectorImpl &runtimeLibPath, + const llvm::opt::ArgList &args, + bool shared) const; void addPathEnvironmentVariableIfNeeded(Job::EnvironmentVector &env, const char *name, diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index a3f391cae12a1..9b2766a66ccbd 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -1038,6 +1038,14 @@ void ToolChain::getRuntimeLibraryPath(SmallVectorImpl &runtimeLibPath, getPlatformNameForTriple(getTriple())); } +void ToolChain::getRuntimeLibraryPathWithArch( + SmallVectorImpl &runtimeLibPath, const llvm::opt::ArgList &args, + bool shared) const { + getRuntimeLibraryPath(runtimeLibPath, args, shared); + llvm::sys::path::append(runtimeLibPath, + swift::getMajorArchitectureName(getTriple())); +} + bool ToolChain::sanitizerRuntimeLibExists(const ArgList &args, StringRef sanitizerName, bool shared) const { diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp index 4c48ae20c6b12..16f05357ce78a 100644 --- a/lib/Driver/UnixToolChains.cpp +++ b/lib/Driver/UnixToolChains.cpp @@ -73,8 +73,8 @@ toolchains::GenericUnix::constructInvocation(const InterpretJobAction &job, InvocationInfo II = ToolChain::constructInvocation(job, context); SmallString<128> runtimeLibraryPath; - getRuntimeLibraryPath(runtimeLibraryPath, context.Args, - /*Shared=*/true); + getRuntimeLibraryPathWithArch(runtimeLibraryPath, context.Args, + /*Shared=*/true); addPathEnvironmentVariableIfNeeded(II.ExtraEnvironment, "LD_LIBRARY_PATH", ":", options::OPT_L, context.Args, @@ -205,10 +205,12 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, } SmallString<128> SharedRuntimeLibPath; - getRuntimeLibraryPath(SharedRuntimeLibPath, context.Args, /*Shared=*/true); + getRuntimeLibraryPathWithArch(SharedRuntimeLibPath, context.Args, + /*Shared=*/true); SmallString<128> StaticRuntimeLibPath; - getRuntimeLibraryPath(StaticRuntimeLibPath, context.Args, /*Shared=*/false); + getRuntimeLibraryPathWithArch(StaticRuntimeLibPath, context.Args, + /*Shared=*/false); // Add the runtime library link path, which is platform-specific and found // relative to the compiler. @@ -222,8 +224,6 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, } SmallString<128> swiftrtPath = SharedRuntimeLibPath; - llvm::sys::path::append(swiftrtPath, - swift::getMajorArchitectureName(getTriple())); llvm::sys::path::append(swiftrtPath, "swiftrt.o"); Arguments.push_back(context.Args.MakeArgString(swiftrtPath)); @@ -260,6 +260,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, Arguments.push_back(context.Args.MakeArgString(StaticRuntimeLibPath)); SmallString<128> linkFilePath = StaticRuntimeLibPath; + llvm::sys::path::remove_filename(linkFilePath); // remove arch name llvm::sys::path::append(linkFilePath, "static-executable-args.lnk"); auto linkFile = linkFilePath.str(); @@ -273,6 +274,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, Arguments.push_back(context.Args.MakeArgString(StaticRuntimeLibPath)); SmallString<128> linkFilePath = StaticRuntimeLibPath; + llvm::sys::path::remove_filename(linkFilePath); // remove arch name llvm::sys::path::append(linkFilePath, "static-stdlib-args.lnk"); auto linkFile = linkFilePath.str(); if (llvm::sys::fs::is_regular_file(linkFile)) { @@ -306,6 +308,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job, if (context.Args.hasArg(options::OPT_profile_generate)) { SmallString<128> LibProfile(SharedRuntimeLibPath); + llvm::sys::path::remove_filename(LibProfile); // remove arch name llvm::sys::path::remove_filename(LibProfile); // remove platform name llvm::sys::path::append(LibProfile, "clang", "lib"); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index c0c47fc0a8f65..02e7e5ff77750 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -47,10 +47,15 @@ static void updateRuntimeLibraryPath(SearchPathOptions &SearchPathOpts, llvm::SmallString<128> LibPath(SearchPathOpts.RuntimeResourcePath); llvm::sys::path::append(LibPath, getPlatformNameForTriple(Triple)); - SearchPathOpts.RuntimeLibraryPath = LibPath.str(); + if (Triple.isOSDarwin()) { + SearchPathOpts.RuntimeLibraryPath = LibPath.str(); + } llvm::sys::path::append(LibPath, swift::getMajorArchitectureName(Triple)); SearchPathOpts.RuntimeLibraryImportPath = LibPath.str(); + if (!Triple.isOSDarwin()) { + SearchPathOpts.RuntimeLibraryPath = LibPath.str(); + } } void CompilerInvocation::setRuntimeResourcePath(StringRef Path) { diff --git a/stdlib/public/runtime/CMakeLists.txt b/stdlib/public/runtime/CMakeLists.txt index d53c72531c790..7b38136d7a6cf 100644 --- a/stdlib/public/runtime/CMakeLists.txt +++ b/stdlib/public/runtime/CMakeLists.txt @@ -157,7 +157,6 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX") foreach(arch IN LISTS SWIFT_SDK_LINUX_ARCHITECTURES) add_dependencies(static_binary_magic ${swift_image_inspection_${arch}_static}) endforeach() - add_dependencies(static_binary_magic ${swift_image_inspection_static_primary_arch}) add_swift_library(swiftImageInspectionSharedObject OBJECT_LIBRARY TARGET_LIBRARY ImageInspectionELF.cpp diff --git a/test/Driver/environment.swift b/test/Driver/environment.swift index 90a6cbde4899f..26c3313b45ad3 100644 --- a/test/Driver/environment.swift +++ b/test/Driver/environment.swift @@ -3,5 +3,5 @@ // RUN: %swift_driver -target x86_64-unknown-gnu-linux -L/foo/ -driver-use-frontend-path %S/Inputs/print-var.sh %s LD_LIBRARY_PATH | %FileCheck -check-prefix=CHECK${LD_LIBRARY_PATH+_LAX} %s -// CHECK: {{^/foo/:[^:]+/lib/swift/linux$}} -// CHECK_LAX: {{^/foo/:[^:]+/lib/swift/linux}} +// CHECK: {{^/foo/:[^:]+/lib/swift/linux/x86_64$}} +// CHECK_LAX: {{^/foo/:[^:]+/lib/swift/linux/x86_64}} diff --git a/test/Driver/options-interpreter.swift b/test/Driver/options-interpreter.swift index 3a7bd0e94eb3b..baf98e7b3854f 100644 --- a/test/Driver/options-interpreter.swift +++ b/test/Driver/options-interpreter.swift @@ -18,8 +18,8 @@ // CHECK-RESOURCE-DIR-ONLY: # DYLD_LIBRARY_PATH=/RSRC/macosx{{$}} // RUN: %swift_driver -### -target x86_64-unknown-linux-gnu -resource-dir /RSRC/ %s | %FileCheck -check-prefix=CHECK-RESOURCE-DIR-ONLY-LINUX${LD_LIBRARY_PATH+_LAX} %s -// CHECK-RESOURCE-DIR-ONLY-LINUX: # LD_LIBRARY_PATH=/RSRC/linux{{$}} -// CHECK-RESOURCE-DIR-ONLY-LINUX_LAX: # LD_LIBRARY_PATH=/RSRC/linux{{$|:}} +// CHECK-RESOURCE-DIR-ONLY-LINUX: # LD_LIBRARY_PATH=/RSRC/linux/x86_64{{$}} +// CHECK-RESOURCE-DIR-ONLY-LINUX_LAX: # LD_LIBRARY_PATH=/RSRC/linux/x86_64{{$|:}} // RUN: %swift_driver -### -target x86_64-apple-macosx10.9 -L/foo/ %s | %FileCheck -check-prefix=CHECK-L %s // CHECK-L: # DYLD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/macosx$}} @@ -59,9 +59,9 @@ // CHECK-COMPLEX-DAG: DYLD_LIBRARY_PATH={{/foo2/:/bar2/:[^:]+/lib/swift/macosx($| )}} // RUN: %swift_driver -### -target x86_64-unknown-linux-gnu -L/foo/ %s | %FileCheck -check-prefix=CHECK-L-LINUX${LD_LIBRARY_PATH+_LAX} %s -// CHECK-L-LINUX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux$}} -// CHECK-L-LINUX_LAX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux($|:)}} +// CHECK-L-LINUX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux/x86_64$}} +// CHECK-L-LINUX_LAX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux/x86_64($|:)}} // RUN: env LD_LIBRARY_PATH=/abc/ %swift_driver_plain -### -target x86_64-unknown-linux-gnu -L/foo/ -L/bar/ %s | %FileCheck -check-prefix=CHECK-LINUX-COMPLEX${LD_LIBRARY_PATH+_LAX} %s -// CHECK-LINUX-COMPLEX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux:/abc/$}} -// CHECK-LINUX-COMPLEX_LAX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux:/abc/($|:)}} +// CHECK-LINUX-COMPLEX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux/x86_64:/abc/$}} +// CHECK-LINUX-COMPLEX_LAX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux/x86_64:/abc/($|:)}} diff --git a/validation-test/execution/interpret-with-dependencies-linux.swift b/validation-test/execution/interpret-with-dependencies-linux.swift index 809d9b154b124..9025cee545f30 100644 --- a/validation-test/execution/interpret-with-dependencies-linux.swift +++ b/validation-test/execution/interpret-with-dependencies-linux.swift @@ -8,9 +8,9 @@ // CHECK: {{okay}} // Now test a dependency on a library in the compiler's resource directory. -// RUN: %empty-directory(%t/rsrc/%target-sdk-name) -// RUN: ln -s %t/libabc.so %t/rsrc/%target-sdk-name/ -// RUN: ln -s %platform-module-dir/../* %t/rsrc/%target-sdk-name/ +// RUN: %empty-directory(%t/rsrc/%target-sdk-name/%target-cpu) +// RUN: ln -s %t/libabc.so %t/rsrc/%target-sdk-name/%target-cpu/ +// RUN: ln -s %platform-module-dir/../%target-cpu/* %t/rsrc/%target-sdk-name/%target-cpu // RUN: ln -s %platform-module-dir/../../shims %t/rsrc/ // RUN: %empty-directory(%t/other) // RUN: ln -s %t/libfoo.so %t/other