Skip to content

Change a few functions related to runtime library paths to use the correct architecture specific paths #15560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ class ToolChain {
/// relative to the compiler.
void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
const llvm::opt::ArgList &args, bool shared) const;
void getRuntimeLibraryPathWithArch(SmallVectorImpl<char> &runtimeLibPath,
const llvm::opt::ArgList &args,
bool shared) const;

void addPathEnvironmentVariableIfNeeded(Job::EnvironmentVector &env,
const char *name,
Expand Down
8 changes: 8 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,14 @@ void ToolChain::getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
getPlatformNameForTriple(getTriple()));
}

void ToolChain::getRuntimeLibraryPathWithArch(
SmallVectorImpl<char> &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 {
Expand Down
15 changes: 9 additions & 6 deletions lib/Driver/UnixToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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));

Expand Down Expand Up @@ -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();

Expand All @@ -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)) {
Expand Down Expand Up @@ -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");

Expand Down
7 changes: 6 additions & 1 deletion lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion stdlib/public/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/Driver/environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
12 changes: 6 additions & 6 deletions test/Driver/options-interpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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$}}
Expand Down Expand Up @@ -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/($|:)}}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down