Skip to content

Commit c572dfe

Browse files
committed
Change a few functions related to runtime library paths to use the correct architecture specific path
Adjust the runtimeLibPath for the GenerixUnix toolchain to use the architecture specific path. Modify the `runtimeLibraryPath` in CompilerInvocation.cpp to use the architecture specific version for non-Darwin platforms. Modify a few tests to agree with these changes.
1 parent 520c645 commit c572dfe

File tree

8 files changed

+37
-19
lines changed

8 files changed

+37
-19
lines changed

include/swift/Driver/ToolChain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ class ToolChain {
195195
/// relative to the compiler.
196196
void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
197197
const llvm::opt::ArgList &args, bool shared) const;
198+
void getRuntimeLibraryPathWithArch(SmallVectorImpl<char> &runtimeLibPath,
199+
const llvm::opt::ArgList &args,
200+
bool shared) const;
198201

199202
void addPathEnvironmentVariableIfNeeded(Job::EnvironmentVector &env,
200203
const char *name,

lib/Driver/ToolChains.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,14 @@ void ToolChain::getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
10381038
getPlatformNameForTriple(getTriple()));
10391039
}
10401040

1041+
void ToolChain::getRuntimeLibraryPathWithArch(
1042+
SmallVectorImpl<char> &runtimeLibPath, const llvm::opt::ArgList &args,
1043+
bool shared) const {
1044+
getRuntimeLibraryPath(runtimeLibPath, args, shared);
1045+
llvm::sys::path::append(runtimeLibPath,
1046+
swift::getMajorArchitectureName(getTriple()));
1047+
}
1048+
10411049
bool ToolChain::sanitizerRuntimeLibExists(const ArgList &args,
10421050
StringRef sanitizerName,
10431051
bool shared) const {

lib/Driver/UnixToolChains.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ toolchains::GenericUnix::constructInvocation(const InterpretJobAction &job,
7373
InvocationInfo II = ToolChain::constructInvocation(job, context);
7474

7575
SmallString<128> runtimeLibraryPath;
76-
getRuntimeLibraryPath(runtimeLibraryPath, context.Args,
77-
/*Shared=*/true);
76+
getRuntimeLibraryPathWithArch(runtimeLibraryPath, context.Args,
77+
/*Shared=*/true);
7878

7979
addPathEnvironmentVariableIfNeeded(II.ExtraEnvironment, "LD_LIBRARY_PATH",
8080
":", options::OPT_L, context.Args,
@@ -205,10 +205,12 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
205205
}
206206

207207
SmallString<128> SharedRuntimeLibPath;
208-
getRuntimeLibraryPath(SharedRuntimeLibPath, context.Args, /*Shared=*/true);
208+
getRuntimeLibraryPathWithArch(SharedRuntimeLibPath, context.Args,
209+
/*Shared=*/true);
209210

210211
SmallString<128> StaticRuntimeLibPath;
211-
getRuntimeLibraryPath(StaticRuntimeLibPath, context.Args, /*Shared=*/false);
212+
getRuntimeLibraryPathWithArch(StaticRuntimeLibPath, context.Args,
213+
/*Shared=*/false);
212214

213215
// Add the runtime library link path, which is platform-specific and found
214216
// relative to the compiler.
@@ -222,8 +224,6 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
222224
}
223225

224226
SmallString<128> swiftrtPath = SharedRuntimeLibPath;
225-
llvm::sys::path::append(swiftrtPath,
226-
swift::getMajorArchitectureName(getTriple()));
227227
llvm::sys::path::append(swiftrtPath, "swiftrt.o");
228228
Arguments.push_back(context.Args.MakeArgString(swiftrtPath));
229229

@@ -260,6 +260,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
260260
Arguments.push_back(context.Args.MakeArgString(StaticRuntimeLibPath));
261261

262262
SmallString<128> linkFilePath = StaticRuntimeLibPath;
263+
llvm::sys::path::remove_filename(linkFilePath); // remove arch name
263264
llvm::sys::path::append(linkFilePath, "static-executable-args.lnk");
264265
auto linkFile = linkFilePath.str();
265266

@@ -273,6 +274,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
273274
Arguments.push_back(context.Args.MakeArgString(StaticRuntimeLibPath));
274275

275276
SmallString<128> linkFilePath = StaticRuntimeLibPath;
277+
llvm::sys::path::remove_filename(linkFilePath); // remove arch name
276278
llvm::sys::path::append(linkFilePath, "static-stdlib-args.lnk");
277279
auto linkFile = linkFilePath.str();
278280
if (llvm::sys::fs::is_regular_file(linkFile)) {
@@ -306,6 +308,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
306308

307309
if (context.Args.hasArg(options::OPT_profile_generate)) {
308310
SmallString<128> LibProfile(SharedRuntimeLibPath);
311+
llvm::sys::path::remove_filename(LibProfile); // remove arch name
309312
llvm::sys::path::remove_filename(LibProfile); // remove platform name
310313
llvm::sys::path::append(LibProfile, "clang", "lib");
311314

lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@ static void updateRuntimeLibraryPath(SearchPathOptions &SearchPathOpts,
4747
llvm::SmallString<128> LibPath(SearchPathOpts.RuntimeResourcePath);
4848

4949
llvm::sys::path::append(LibPath, getPlatformNameForTriple(Triple));
50-
SearchPathOpts.RuntimeLibraryPath = LibPath.str();
50+
if (Triple.isOSDarwin()) {
51+
SearchPathOpts.RuntimeLibraryPath = LibPath.str();
52+
}
5153

5254
llvm::sys::path::append(LibPath, swift::getMajorArchitectureName(Triple));
5355
SearchPathOpts.RuntimeLibraryImportPath = LibPath.str();
56+
if (!Triple.isOSDarwin()) {
57+
SearchPathOpts.RuntimeLibraryPath = LibPath.str();
58+
}
5459
}
5560

5661
void CompilerInvocation::setRuntimeResourcePath(StringRef Path) {

stdlib/public/runtime/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ if(SWIFT_BUILD_STATIC_STDLIB AND "${sdk}" STREQUAL "LINUX")
157157
foreach(arch IN LISTS SWIFT_SDK_LINUX_ARCHITECTURES)
158158
add_dependencies(static_binary_magic ${swift_image_inspection_${arch}_static})
159159
endforeach()
160-
add_dependencies(static_binary_magic ${swift_image_inspection_static_primary_arch})
161160

162161
add_swift_library(swiftImageInspectionSharedObject OBJECT_LIBRARY TARGET_LIBRARY
163162
ImageInspectionELF.cpp

test/Driver/environment.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
// 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
55

6-
// CHECK: {{^/foo/:[^:]+/lib/swift/linux$}}
7-
// CHECK_LAX: {{^/foo/:[^:]+/lib/swift/linux}}
6+
// CHECK: {{^/foo/:[^:]+/lib/swift/linux/x86_64$}}
7+
// CHECK_LAX: {{^/foo/:[^:]+/lib/swift/linux/x86_64}}

test/Driver/options-interpreter.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
// CHECK-RESOURCE-DIR-ONLY: # DYLD_LIBRARY_PATH=/RSRC/macosx{{$}}
1919

2020
// 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
21-
// CHECK-RESOURCE-DIR-ONLY-LINUX: # LD_LIBRARY_PATH=/RSRC/linux{{$}}
22-
// CHECK-RESOURCE-DIR-ONLY-LINUX_LAX: # LD_LIBRARY_PATH=/RSRC/linux{{$|:}}
21+
// CHECK-RESOURCE-DIR-ONLY-LINUX: # LD_LIBRARY_PATH=/RSRC/linux/x86_64{{$}}
22+
// CHECK-RESOURCE-DIR-ONLY-LINUX_LAX: # LD_LIBRARY_PATH=/RSRC/linux/x86_64{{$|:}}
2323

2424
// RUN: %swift_driver -### -target x86_64-apple-macosx10.9 -L/foo/ %s | %FileCheck -check-prefix=CHECK-L %s
2525
// CHECK-L: # DYLD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/macosx$}}
@@ -59,9 +59,9 @@
5959
// CHECK-COMPLEX-DAG: DYLD_LIBRARY_PATH={{/foo2/:/bar2/:[^:]+/lib/swift/macosx($| )}}
6060

6161
// RUN: %swift_driver -### -target x86_64-unknown-linux-gnu -L/foo/ %s | %FileCheck -check-prefix=CHECK-L-LINUX${LD_LIBRARY_PATH+_LAX} %s
62-
// CHECK-L-LINUX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux$}}
63-
// CHECK-L-LINUX_LAX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux($|:)}}
62+
// CHECK-L-LINUX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux/x86_64$}}
63+
// CHECK-L-LINUX_LAX: # LD_LIBRARY_PATH={{/foo/:[^:]+/lib/swift/linux/x86_64($|:)}}
6464

6565
// 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
66-
// CHECK-LINUX-COMPLEX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux:/abc/$}}
67-
// CHECK-LINUX-COMPLEX_LAX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux:/abc/($|:)}}
66+
// CHECK-LINUX-COMPLEX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux/x86_64:/abc/$}}
67+
// CHECK-LINUX-COMPLEX_LAX: # LD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/linux/x86_64:/abc/($|:)}}

validation-test/execution/interpret-with-dependencies-linux.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// CHECK: {{okay}}
99

1010
// Now test a dependency on a library in the compiler's resource directory.
11-
// RUN: %empty-directory(%t/rsrc/%target-sdk-name)
12-
// RUN: ln -s %t/libabc.so %t/rsrc/%target-sdk-name/
13-
// RUN: ln -s %platform-module-dir/../* %t/rsrc/%target-sdk-name/
11+
// RUN: %empty-directory(%t/rsrc/%target-sdk-name/%target-cpu)
12+
// RUN: ln -s %t/libabc.so %t/rsrc/%target-sdk-name/%target-cpu/
13+
// RUN: ln -s %platform-module-dir/../%target-cpu/* %t/rsrc/%target-sdk-name/%target-cpu
1414
// RUN: ln -s %platform-module-dir/../../shims %t/rsrc/
1515
// RUN: %empty-directory(%t/other)
1616
// RUN: ln -s %t/libfoo.so %t/other

0 commit comments

Comments
 (0)