Skip to content

Commit aebd771

Browse files
authored
Merge pull request #40368 from apple/revert-40357-obfuscate-searialized-paths
Revert "serialization: obfuscate the serialized search paths"
2 parents 5b8714e + 11d5d6d commit aebd771

21 files changed

+27
-139
lines changed

include/swift/AST/FileUnit.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,6 @@ class LoadedFile : public FileUnit {
405405
virtual void collectBasicSourceFileInfo(
406406
llvm::function_ref<void(const BasicSourceFileInfo &)> callback) const {}
407407

408-
virtual void collectSerializedSearchPath(
409-
llvm::function_ref<void(StringRef)> callback) const {}
410408
static bool classof(const FileUnit *file) {
411409
return file->getKind() == FileUnitKind::SerializedAST ||
412410
file->getKind() == FileUnitKind::ClangModule ||

include/swift/AST/Module.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,6 @@ class ModuleDecl
833833
void collectBasicSourceFileInfo(
834834
llvm::function_ref<void(const BasicSourceFileInfo &)> callback) const;
835835

836-
void collectSerializedSearchPath(
837-
llvm::function_ref<void(StringRef)> callback) const;
838836
/// Retrieve a fingerprint value that summarizes the contents of this module.
839837
///
840838
/// This interface hash a of a module is guaranteed to change if the interface

include/swift/AST/SearchPathOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ class SearchPathOptions {
103103
/// specified in LLDB from the target.source-map entries.
104104
PathRemapper SearchPathRemapper;
105105

106-
/// Recover the search paths deserialized from .swiftmodule files to their
107-
/// original form.
108-
PathObfuscator DeserializedPathRecoverer;
109-
110106
private:
111107
static StringRef
112108
pathStringFromFrameworkSearchPath(const FrameworkSearchPath &next) {

include/swift/Basic/PathRemapper.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,6 @@ class PathRemapper {
5858
}
5959
};
6060

61-
class PathObfuscator {
62-
PathRemapper obfuscator, recoverer;
63-
public:
64-
void addMapping(StringRef FromPrefix, StringRef ToPrefix) {
65-
obfuscator.addMapping(FromPrefix, ToPrefix);
66-
recoverer.addMapping(ToPrefix, FromPrefix);
67-
}
68-
std::string obfuscate(StringRef Path) const {
69-
return obfuscator.remapPath(Path);
70-
}
71-
std::string recover(StringRef Path) const {
72-
return recoverer.remapPath(Path);
73-
}
74-
};
75-
7661
} // end namespace swift
7762

7863
#endif // SWIFT_BASIC_PATHREMAPPER_H

include/swift/Frontend/FrontendOptions.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "swift/Basic/FileTypes.h"
1717
#include "swift/Basic/Version.h"
18-
#include "swift/Basic/PathRemapper.h"
1918
#include "swift/Frontend/FrontendInputsAndOutputs.h"
2019
#include "swift/Frontend/InputFile.h"
2120
#include "llvm/ADT/Hashing.h"
@@ -438,10 +437,6 @@ class FrontendOptions {
438437
/// Whether to include symbols with SPI information in the symbol graph.
439438
bool IncludeSPISymbolsInSymbolGraph = false;
440439

441-
/// This is used to obfuscate the serialized search paths so we don't have
442-
/// to encode the actual paths into the .swiftmodule file.
443-
PathObfuscator serializedPathObfuscator;
444-
445440
private:
446441
static bool canActionEmitDependencies(ActionType);
447442
static bool canActionEmitReferenceDependencies(ActionType);

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ def print_clang_stats : Flag<["-"], "print-clang-stats">,
165165

166166
def serialize_debugging_options : Flag<["-"], "serialize-debugging-options">,
167167
HelpText<"Always serialize options for debugging (default: only for apps)">;
168-
169-
def serialized_path_obfuscate : Separate<["-"], "serialized-path-obfuscate">,
170-
HelpText<"Remap source paths in debug info">, MetaVarName<"<prefix=replacement>">;
171-
172168
def no_serialize_debugging_options :
173169
Flag<["-"], "no-serialize-debugging-options">,
174170
HelpText<"Never serialize options for debugging (default: only for apps)">;

include/swift/Serialization/SerializationOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ namespace swift {
4545
/// Path prefixes that should be rewritten in debug info.
4646
PathRemapper DebuggingOptionsPrefixMap;
4747

48-
/// Obfuscate the serialized paths so we don't have the actual paths encoded
49-
/// in the .swiftmodule file.
50-
PathObfuscator PathObfuscator;
51-
5248
/// Describes a single-file dependency for this module, along with the
5349
/// appropriate strategy for how to verify if it's up-to-date.
5450
class FileDependency {

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,6 @@ class SerializedASTFile final : public LoadedFile {
465465
virtual void collectBasicSourceFileInfo(
466466
llvm::function_ref<void(const BasicSourceFileInfo &)>) const override;
467467

468-
virtual void collectSerializedSearchPath(
469-
llvm::function_ref<void(StringRef)> callback) const override;
470-
471468
static bool classof(const FileUnit *file) {
472469
return file->getKind() == FileUnitKind::SerializedAST;
473470
}

include/swift/Serialization/Validation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct ValidationInfo {
104104
/// \sa validateSerializedAST()
105105
class ExtendedValidationInfo {
106106
SmallVector<StringRef, 4> ExtraClangImporterOpts;
107-
std::string SDKPath;
107+
StringRef SDKPath;
108108
StringRef ModuleABIName;
109109
struct {
110110
unsigned ArePrivateImportsEnabled : 1;
@@ -121,7 +121,7 @@ class ExtendedValidationInfo {
121121
ExtendedValidationInfo() : Bits() {}
122122

123123
StringRef getSDKPath() const { return SDKPath; }
124-
void setSDKPath(std::string path) {
124+
void setSDKPath(StringRef path) {
125125
assert(SDKPath.empty());
126126
SDKPath = path;
127127
}

lib/AST/Module.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,15 +1808,6 @@ void ModuleDecl::collectBasicSourceFileInfo(
18081808
}
18091809
}
18101810

1811-
void ModuleDecl::collectSerializedSearchPath(
1812-
llvm::function_ref<void(StringRef)> callback) const {
1813-
for (const FileUnit *fileUnit : getFiles()) {
1814-
if (auto *serialized = dyn_cast<LoadedFile>(fileUnit)) {
1815-
serialized->collectSerializedSearchPath(callback);
1816-
}
1817-
}
1818-
}
1819-
18201811
Fingerprint ModuleDecl::getFingerprint() const {
18211812
StableHasher hasher = StableHasher::defaultHasher();
18221813
SmallVector<Fingerprint, 16> FPs;

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,6 @@ bool ArgsToFrontendOptionsConverter::convert(
292292

293293
Opts.HermeticSealAtLink = Args.hasArg(OPT_experimental_hermetic_seal_at_link);
294294

295-
for (auto A : Args.getAllArgValues(options::OPT_serialized_path_obfuscate)) {
296-
auto SplitMap = StringRef(A).split('=');
297-
Opts.serializedPathObfuscator.addMapping(SplitMap.first, SplitMap.second);
298-
}
299295
return false;
300296
}
301297

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,11 +1214,6 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
12141214
Opts.PlaceholderDependencyModuleMap = A->getValue();
12151215
if (const Arg *A = Args.getLastArg(OPT_batch_scan_input_file))
12161216
Opts.BatchScanInputFilePath = A->getValue();
1217-
1218-
for (auto A : Args.getAllArgValues(options::OPT_serialized_path_obfuscate)) {
1219-
auto SplitMap = StringRef(A).split('=');
1220-
Opts.DeserializedPathRecoverer.addMapping(SplitMap.first, SplitMap.second);
1221-
}
12221217
// Opts.RuntimeIncludePath is set by calls to
12231218
// setRuntimeIncludePath() or setMainExecutablePath().
12241219
// Opts.RuntimeImportPath is set by calls to

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
164164
opts.SerializeOptionsForDebugging.getValueOr(
165165
!module->isExternallyConsumed());
166166

167-
serializationOpts.PathObfuscator = opts.serializedPathObfuscator;
168167
if (serializationOpts.SerializeOptionsForDebugging &&
169168
opts.DebugPrefixSerializedDebuggingOptions) {
170169
serializationOpts.DebuggingOptionsPrefixMap =

lib/Serialization/ModuleFile.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ ModuleFile::getModuleName(ASTContext &Ctx, StringRef modulePath,
361361
serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load(
362362
modulePath.str(), std::move(newBuf), nullptr, nullptr,
363363
/*isFramework*/ isFramework, Ctx.SILOpts.EnableOSSAModules,
364-
Ctx.SearchPathOpts.DeserializedPathRecoverer,
365364
loadedModuleFile);
366365
Name = loadedModuleFile->Name.str();
367366
return std::move(moduleBuf.get());
@@ -1000,13 +999,6 @@ Optional<CommentInfo> ModuleFile::getCommentForDecl(const Decl *D) const {
1000999
return getCommentForDeclByUSR(USRBuffer.str());
10011000
}
10021001

1003-
void ModuleFile::collectSerializedSearchPath(
1004-
llvm::function_ref<void(StringRef)> callback) const {
1005-
for (auto path: Core->SearchPaths) {
1006-
callback(path.Path);
1007-
}
1008-
}
1009-
10101002
void ModuleFile::collectBasicSourceFileInfo(
10111003
llvm::function_ref<void(const BasicSourceFileInfo &)> callback) const {
10121004
if (Core->SourceFileListData.empty())

lib/Serialization/ModuleFile.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,7 @@ class ModuleFile
743743
Optional<Fingerprint> loadFingerprint(const IterableDeclContext *IDC) const;
744744
void collectBasicSourceFileInfo(
745745
llvm::function_ref<void(const BasicSourceFileInfo &)> callback) const;
746-
void collectSerializedSearchPath(
747-
llvm::function_ref<void(StringRef)> callback) const;
746+
748747

749748
// MARK: Deserialization interface
750749

lib/Serialization/ModuleFileSharedCore.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor,
8484
/// Returns true on success.
8585
static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
8686
SmallVectorImpl<uint64_t> &scratch,
87-
ExtendedValidationInfo &extendedInfo,
88-
PathObfuscator &pathRecoverer) {
87+
ExtendedValidationInfo &extendedInfo) {
8988
while (!cursor.AtEndOfStream()) {
9089
Expected<llvm::BitstreamEntry> maybeEntry = cursor.advance();
9190
if (!maybeEntry) {
@@ -120,7 +119,7 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
120119
unsigned kind = maybeKind.get();
121120
switch (kind) {
122121
case options_block::SDK_PATH:
123-
extendedInfo.setSDKPath(pathRecoverer.recover(blobData));
122+
extendedInfo.setSDKPath(blobData);
124123
break;
125124
case options_block::XCC:
126125
extendedInfo.addExtraClangImporterOption(blobData);
@@ -172,8 +171,7 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
172171
static ValidationInfo validateControlBlock(
173172
llvm::BitstreamCursor &cursor, SmallVectorImpl<uint64_t> &scratch,
174173
std::pair<uint16_t, uint16_t> expectedVersion, bool requiresOSSAModules,
175-
ExtendedValidationInfo *extendedInfo,
176-
PathObfuscator &pathRecoverer) {
174+
ExtendedValidationInfo *extendedInfo) {
177175
// The control block is malformed until we've at least read a major version
178176
// number.
179177
ValidationInfo result;
@@ -204,7 +202,7 @@ static ValidationInfo validateControlBlock(
204202
result.status = Status::Malformed;
205203
return result;
206204
}
207-
if (!readOptionsBlock(cursor, scratch, *extendedInfo, pathRecoverer)) {
205+
if (!readOptionsBlock(cursor, scratch, *extendedInfo)) {
208206
result.status = Status::Malformed;
209207
return result;
210208
}
@@ -467,11 +465,10 @@ ValidationInfo serialization::validateSerializedAST(
467465
result.status = Status::Malformed;
468466
return result;
469467
}
470-
PathObfuscator localObfuscator;
471468
result = validateControlBlock(
472469
cursor, scratch,
473470
{SWIFTMODULE_VERSION_MAJOR, SWIFTMODULE_VERSION_MINOR},
474-
requiresOSSAModules, extendedInfo, localObfuscator);
471+
requiresOSSAModules, extendedInfo);
475472
if (result.status == Status::Malformed)
476473
return result;
477474
} else if (dependencies &&
@@ -941,7 +938,7 @@ getActualImportControl(unsigned rawValue) {
941938
}
942939
}
943940

944-
bool ModuleFileSharedCore::readModuleDocIfPresent(PathObfuscator &pathRecoverer) {
941+
bool ModuleFileSharedCore::readModuleDocIfPresent() {
945942
if (!this->ModuleDocInputBuffer)
946943
return true;
947944

@@ -980,7 +977,7 @@ bool ModuleFileSharedCore::readModuleDocIfPresent(PathObfuscator &pathRecoverer)
980977
info = validateControlBlock(
981978
docCursor, scratch, {SWIFTDOC_VERSION_MAJOR, SWIFTDOC_VERSION_MINOR},
982979
RequiresOSSAModules,
983-
/*extendedInfo*/ nullptr, pathRecoverer);
980+
/*extendedInfo*/ nullptr);
984981
if (info.status != Status::Valid)
985982
return false;
986983
// Check that the swiftdoc is actually for this module.
@@ -1086,7 +1083,7 @@ bool ModuleFileSharedCore::readDeclLocsBlock(llvm::BitstreamCursor &cursor) {
10861083
return false;
10871084
}
10881085

1089-
bool ModuleFileSharedCore::readModuleSourceInfoIfPresent(PathObfuscator &pathRecoverer) {
1086+
bool ModuleFileSharedCore::readModuleSourceInfoIfPresent() {
10901087
if (!this->ModuleSourceInfoInputBuffer)
10911088
return true;
10921089

@@ -1124,8 +1121,7 @@ bool ModuleFileSharedCore::readModuleSourceInfoIfPresent(PathObfuscator &pathRec
11241121
infoCursor, scratch,
11251122
{SWIFTSOURCEINFO_VERSION_MAJOR, SWIFTSOURCEINFO_VERSION_MINOR},
11261123
RequiresOSSAModules,
1127-
/*extendedInfo*/ nullptr,
1128-
pathRecoverer);
1124+
/*extendedInfo*/ nullptr);
11291125
if (info.status != Status::Valid)
11301126
return false;
11311127
// Check that the swiftsourceinfo is actually for this module.
@@ -1200,7 +1196,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
12001196
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
12011197
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
12021198
bool isFramework, bool requiresOSSAModules,
1203-
serialization::ValidationInfo &info, PathObfuscator &pathRecoverer)
1199+
serialization::ValidationInfo &info)
12041200
: ModuleInputBuffer(std::move(moduleInputBuffer)),
12051201
ModuleDocInputBuffer(std::move(moduleDocInputBuffer)),
12061202
ModuleSourceInfoInputBuffer(std::move(moduleSourceInfoInputBuffer)),
@@ -1251,7 +1247,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
12511247
info = validateControlBlock(
12521248
cursor, scratch,
12531249
{SWIFTMODULE_VERSION_MAJOR, SWIFTMODULE_VERSION_MINOR},
1254-
RequiresOSSAModules, &extInfo, pathRecoverer);
1250+
RequiresOSSAModules, &extInfo);
12551251
if (info.status != Status::Valid) {
12561252
error(info.status);
12571253
return;
@@ -1376,8 +1372,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
13761372
bool isSystem;
13771373
input_block::SearchPathLayout::readRecord(scratch, isFramework,
13781374
isSystem);
1379-
SearchPaths.push_back({pathRecoverer.recover(blobData), isFramework,
1380-
isSystem});
1375+
SearchPaths.push_back({blobData, isFramework, isSystem});
13811376
break;
13821377
}
13831378
case input_block::MODULE_INTERFACE_PATH: {
@@ -1577,8 +1572,8 @@ ModuleFileSharedCore::ModuleFileSharedCore(
15771572
return;
15781573
}
15791574
// Read source info file.
1580-
readModuleSourceInfoIfPresent(pathRecoverer);
1581-
if (!readModuleDocIfPresent(pathRecoverer)) {
1575+
readModuleSourceInfoIfPresent();
1576+
if (!readModuleDocIfPresent()) {
15821577
info.status = error(Status::MalformedDocumentation);
15831578
return;
15841579
}

lib/Serialization/ModuleFileSharedCore.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class ModuleFileSharedCore {
149149
SmallVector<Dependency, 8> Dependencies;
150150

151151
struct SearchPath {
152-
std::string Path;
152+
StringRef Path;
153153
bool IsFramework;
154154
bool IsSystem;
155155
};
@@ -374,7 +374,7 @@ class ModuleFileSharedCore {
374374
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
375375
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
376376
bool isFramework, bool requiresOSSAModules,
377-
serialization::ValidationInfo &info, PathObfuscator &pathRecoverer);
377+
serialization::ValidationInfo &info);
378378

379379
/// Change the status of the current module.
380380
Status error(Status issue) {
@@ -464,7 +464,7 @@ class ModuleFileSharedCore {
464464
/// Loads data from #ModuleDocInputBuffer.
465465
///
466466
/// Returns false if there was an error.
467-
bool readModuleDocIfPresent(PathObfuscator &pathRecoverer);
467+
bool readModuleDocIfPresent();
468468

469469
/// Reads the source loc block, which contains USR to decl location mapping.
470470
///
@@ -474,7 +474,7 @@ class ModuleFileSharedCore {
474474
/// Loads data from #ModuleSourceInfoInputBuffer.
475475
///
476476
/// Returns false if there was an error.
477-
bool readModuleSourceInfoIfPresent(PathObfuscator &pathRecoverer);
477+
bool readModuleSourceInfoIfPresent();
478478

479479
/// Read an on-disk decl hash table stored in
480480
/// \c sourceinfo_block::DeclUSRSLayout format.
@@ -510,13 +510,12 @@ class ModuleFileSharedCore {
510510
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
511511
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
512512
bool isFramework, bool requiresOSSAModules,
513-
PathObfuscator &pathRecoverer,
514513
std::shared_ptr<const ModuleFileSharedCore> &theModule) {
515514
serialization::ValidationInfo info;
516515
auto *core = new ModuleFileSharedCore(
517516
std::move(moduleInputBuffer), std::move(moduleDocInputBuffer),
518517
std::move(moduleSourceInfoInputBuffer), isFramework,
519-
requiresOSSAModules, info, pathRecoverer);
518+
requiresOSSAModules, info);
520519
if (!moduleInterfacePath.empty()) {
521520
ArrayRef<char> path;
522521
core->allocateBuffer(path, moduleInterfacePath);

0 commit comments

Comments
 (0)