Skip to content

Commit 0c0bcbb

Browse files
RLovelettjrose-apple
authored andcommitted
Convert "armv7l" to "armv7" for the architecture component of paths (#2369)
On the Raspberry Pi 2 when trying to import Glibc, without this patch, it will attempt to find the module map at "/usr/lib/swift/linux/armv7l/glibc.modulemap" and fail to do so. With this patch it will attempt to find the module map at "/usr/lib/swift/linux/armv7/glibc.modulemap" where it will succeed in finding the module map. Similar behavior currently happens in the Driver and Frontend. To DRY up this behavior it has been extracted to the Swift platform.
1 parent 06fe6b0 commit 0c0bcbb

File tree

5 files changed

+37
-46
lines changed

5 files changed

+37
-46
lines changed

include/swift/Basic/Platform.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ namespace swift {
5757

5858
/// Returns the platform Kind for Darwin triples.
5959
DarwinPlatformKind getDarwinPlatformKind(const llvm::Triple &triple);
60+
61+
/// Returns the architecture component of the path for a given target triple.
62+
///
63+
/// Typically this is used for mapping the architecture component of the
64+
/// path.
65+
///
66+
/// For example, on Linux "armv6l" and "armv7l" are mapped to "armv6" and
67+
/// "armv7", respectively, within LLVM. Therefore the component path for the
68+
/// architecture specific objects will be found in their "mapped" paths.
69+
///
70+
/// This is a stop-gap until full Triple support (ala Clang) exists within swiftc.
71+
StringRef getMajorArchitectureName(const llvm::Triple &triple);
6072
} // end namespace swift
6173

6274
#endif // SWIFT_BASIC_PLATFORM_H

lib/Basic/Platform.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,21 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
102102

103103
return "";
104104
}
105+
106+
StringRef swift::getMajorArchitectureName(const llvm::Triple &Triple) {
107+
if (Triple.isOSLinux()) {
108+
switch(Triple.getSubArch()) {
109+
default:
110+
return Triple.getArchName();
111+
break;
112+
case llvm::Triple::SubArchType::ARMSubArch_v7:
113+
return "armv7";
114+
break;
115+
case llvm::Triple::SubArchType::ARMSubArch_v6:
116+
return "armv6";
117+
break;
118+
}
119+
} else {
120+
return Triple.getArchName();
121+
}
122+
}

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
398398

399399
llvm::sys::path::append(
400400
GlibcModuleMapPath,
401-
swift::getPlatformNameForTriple(triple), triple.getArchName(),
401+
swift::getPlatformNameForTriple(triple),
402+
swift::getMajorArchitectureName(triple),
402403
"glibc.modulemap");
403404

404405
// Only specify the module map if that file actually exists.

lib/Driver/ToolChains.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,28 +1171,6 @@ toolchains::GenericUnix::constructInvocation(const AutolinkExtractJobAction &job
11711171
return {"swift-autolink-extract", Arguments};
11721172
}
11731173

1174-
// This function maps triples to the architecture component of the path
1175-
// where the swift_begin.o and swift_end.o objects can be found. This
1176-
// is a stop-gap until full Triple support (ala Clang) exists within swiftc.
1177-
StringRef
1178-
getSectionMagicArch(const llvm::Triple &Triple) {
1179-
if (Triple.isOSLinux()) {
1180-
switch(Triple.getSubArch()) {
1181-
default:
1182-
return Triple.getArchName();
1183-
break;
1184-
case llvm::Triple::SubArchType::ARMSubArch_v7:
1185-
return "armv7";
1186-
break;
1187-
case llvm::Triple::SubArchType::ARMSubArch_v6:
1188-
return "armv6";
1189-
break;
1190-
}
1191-
} else {
1192-
return Triple.getArchName();
1193-
}
1194-
}
1195-
11961174
std::string toolchains::GenericUnix::getDefaultLinker() const {
11971175
switch(getTriple().getArch()) {
11981176
case llvm::Triple::arm:
@@ -1223,15 +1201,17 @@ std::string toolchains::GenericUnix::getPreInputObjectPath(
12231201
// On Linux and FreeBSD (really, ELF binaries) we need to add objects
12241202
// to provide markers and size for the metadata sections.
12251203
SmallString<128> PreInputObjectPath = RuntimeLibraryPath;
1226-
llvm::sys::path::append(PreInputObjectPath, getSectionMagicArch(getTriple()));
1204+
llvm::sys::path::append(PreInputObjectPath,
1205+
swift::getMajorArchitectureName(getTriple()));
12271206
llvm::sys::path::append(PreInputObjectPath, "swift_begin.o");
12281207
return PreInputObjectPath.str();
12291208
}
12301209

12311210
std::string toolchains::GenericUnix::getPostInputObjectPath(
12321211
StringRef RuntimeLibraryPath) const {
12331212
SmallString<128> PostInputObjectPath = RuntimeLibraryPath;
1234-
llvm::sys::path::append(PostInputObjectPath, getSectionMagicArch(getTriple()));
1213+
llvm::sys::path::append(PostInputObjectPath,
1214+
swift::getMajorArchitectureName(getTriple()));
12351215
llvm::sys::path::append(PostInputObjectPath, "swift_end.o");
12361216
return PostInputObjectPath.str();
12371217
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,7 @@ static void updateRuntimeLibraryPath(SearchPathOptions &SearchPathOpts,
4848
llvm::sys::path::append(LibPath, getPlatformNameForTriple(Triple));
4949
SearchPathOpts.RuntimeLibraryPath = LibPath.str();
5050

51-
// The linux provided triple for ARM contains a trailing 'l'
52-
// denoting little-endian. This is not used in the path for
53-
// libraries. LLVM matches these SubArchTypes to the generic
54-
// ARMSubArch_v7 (for example) type. If that is the case,
55-
// use the base of the architecture type in the library path.
56-
if (Triple.isOSLinux()) {
57-
switch(Triple.getSubArch()) {
58-
default:
59-
llvm::sys::path::append(LibPath, Triple.getArchName());
60-
break;
61-
case llvm::Triple::SubArchType::ARMSubArch_v7:
62-
llvm::sys::path::append(LibPath, "armv7");
63-
break;
64-
case llvm::Triple::SubArchType::ARMSubArch_v6:
65-
llvm::sys::path::append(LibPath, "armv6");
66-
break;
67-
}
68-
} else {
69-
llvm::sys::path::append(LibPath, Triple.getArchName());
70-
}
71-
51+
llvm::sys::path::append(LibPath, swift::getMajorArchitectureName(Triple));
7252
SearchPathOpts.RuntimeLibraryImportPath = LibPath.str();
7353
}
7454

0 commit comments

Comments
 (0)