Skip to content

Revert "serialization: obfuscate the serialized search paths" #40368

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

Merged
merged 1 commit into from
Dec 2, 2021
Merged
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
2 changes: 0 additions & 2 deletions include/swift/AST/FileUnit.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,6 @@ class LoadedFile : public FileUnit {
virtual void collectBasicSourceFileInfo(
llvm::function_ref<void(const BasicSourceFileInfo &)> callback) const {}

virtual void collectSerializedSearchPath(
llvm::function_ref<void(StringRef)> callback) const {}
static bool classof(const FileUnit *file) {
return file->getKind() == FileUnitKind::SerializedAST ||
file->getKind() == FileUnitKind::ClangModule ||
Expand Down
2 changes: 0 additions & 2 deletions include/swift/AST/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,6 @@ class ModuleDecl
void collectBasicSourceFileInfo(
llvm::function_ref<void(const BasicSourceFileInfo &)> callback) const;

void collectSerializedSearchPath(
llvm::function_ref<void(StringRef)> callback) const;
/// Retrieve a fingerprint value that summarizes the contents of this module.
///
/// This interface hash a of a module is guaranteed to change if the interface
Expand Down
4 changes: 0 additions & 4 deletions include/swift/AST/SearchPathOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ class SearchPathOptions {
/// specified in LLDB from the target.source-map entries.
PathRemapper SearchPathRemapper;

/// Recover the search paths deserialized from .swiftmodule files to their
/// original form.
PathObfuscator DeserializedPathRecoverer;

private:
static StringRef
pathStringFromFrameworkSearchPath(const FrameworkSearchPath &next) {
Expand Down
15 changes: 0 additions & 15 deletions include/swift/Basic/PathRemapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,6 @@ class PathRemapper {
}
};

class PathObfuscator {
PathRemapper obfuscator, recoverer;
public:
void addMapping(StringRef FromPrefix, StringRef ToPrefix) {
obfuscator.addMapping(FromPrefix, ToPrefix);
recoverer.addMapping(ToPrefix, FromPrefix);
}
std::string obfuscate(StringRef Path) const {
return obfuscator.remapPath(Path);
}
std::string recover(StringRef Path) const {
return recoverer.remapPath(Path);
}
};

} // end namespace swift

#endif // SWIFT_BASIC_PATHREMAPPER_H
5 changes: 0 additions & 5 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include "swift/Basic/FileTypes.h"
#include "swift/Basic/Version.h"
#include "swift/Basic/PathRemapper.h"
#include "swift/Frontend/FrontendInputsAndOutputs.h"
#include "swift/Frontend/InputFile.h"
#include "llvm/ADT/Hashing.h"
Expand Down Expand Up @@ -438,10 +437,6 @@ class FrontendOptions {
/// Whether to include symbols with SPI information in the symbol graph.
bool IncludeSPISymbolsInSymbolGraph = false;

/// This is used to obfuscate the serialized search paths so we don't have
/// to encode the actual paths into the .swiftmodule file.
PathObfuscator serializedPathObfuscator;

private:
static bool canActionEmitDependencies(ActionType);
static bool canActionEmitReferenceDependencies(ActionType);
Expand Down
4 changes: 0 additions & 4 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ def print_clang_stats : Flag<["-"], "print-clang-stats">,

def serialize_debugging_options : Flag<["-"], "serialize-debugging-options">,
HelpText<"Always serialize options for debugging (default: only for apps)">;

def serialized_path_obfuscate : Separate<["-"], "serialized-path-obfuscate">,
HelpText<"Remap source paths in debug info">, MetaVarName<"<prefix=replacement>">;

def no_serialize_debugging_options :
Flag<["-"], "no-serialize-debugging-options">,
HelpText<"Never serialize options for debugging (default: only for apps)">;
Expand Down
4 changes: 0 additions & 4 deletions include/swift/Serialization/SerializationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ namespace swift {
/// Path prefixes that should be rewritten in debug info.
PathRemapper DebuggingOptionsPrefixMap;

/// Obfuscate the serialized paths so we don't have the actual paths encoded
/// in the .swiftmodule file.
PathObfuscator PathObfuscator;

/// Describes a single-file dependency for this module, along with the
/// appropriate strategy for how to verify if it's up-to-date.
class FileDependency {
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Serialization/SerializedModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,6 @@ class SerializedASTFile final : public LoadedFile {
virtual void collectBasicSourceFileInfo(
llvm::function_ref<void(const BasicSourceFileInfo &)>) const override;

virtual void collectSerializedSearchPath(
llvm::function_ref<void(StringRef)> callback) const override;

static bool classof(const FileUnit *file) {
return file->getKind() == FileUnitKind::SerializedAST;
}
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Serialization/Validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct ValidationInfo {
/// \sa validateSerializedAST()
class ExtendedValidationInfo {
SmallVector<StringRef, 4> ExtraClangImporterOpts;
std::string SDKPath;
StringRef SDKPath;
StringRef ModuleABIName;
struct {
unsigned ArePrivateImportsEnabled : 1;
Expand All @@ -121,7 +121,7 @@ class ExtendedValidationInfo {
ExtendedValidationInfo() : Bits() {}

StringRef getSDKPath() const { return SDKPath; }
void setSDKPath(std::string path) {
void setSDKPath(StringRef path) {
assert(SDKPath.empty());
SDKPath = path;
}
Expand Down
9 changes: 0 additions & 9 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1808,15 +1808,6 @@ void ModuleDecl::collectBasicSourceFileInfo(
}
}

void ModuleDecl::collectSerializedSearchPath(
llvm::function_ref<void(StringRef)> callback) const {
for (const FileUnit *fileUnit : getFiles()) {
if (auto *serialized = dyn_cast<LoadedFile>(fileUnit)) {
serialized->collectSerializedSearchPath(callback);
}
}
}

Fingerprint ModuleDecl::getFingerprint() const {
StableHasher hasher = StableHasher::defaultHasher();
SmallVector<Fingerprint, 16> FPs;
Expand Down
4 changes: 0 additions & 4 deletions lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,6 @@ bool ArgsToFrontendOptionsConverter::convert(

Opts.HermeticSealAtLink = Args.hasArg(OPT_experimental_hermetic_seal_at_link);

for (auto A : Args.getAllArgValues(options::OPT_serialized_path_obfuscate)) {
auto SplitMap = StringRef(A).split('=');
Opts.serializedPathObfuscator.addMapping(SplitMap.first, SplitMap.second);
}
return false;
}

Expand Down
5 changes: 0 additions & 5 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,11 +1214,6 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
Opts.PlaceholderDependencyModuleMap = A->getValue();
if (const Arg *A = Args.getLastArg(OPT_batch_scan_input_file))
Opts.BatchScanInputFilePath = A->getValue();

for (auto A : Args.getAllArgValues(options::OPT_serialized_path_obfuscate)) {
auto SplitMap = StringRef(A).split('=');
Opts.DeserializedPathRecoverer.addMapping(SplitMap.first, SplitMap.second);
}
// Opts.RuntimeIncludePath is set by calls to
// setRuntimeIncludePath() or setMainExecutablePath().
// Opts.RuntimeImportPath is set by calls to
Expand Down
1 change: 0 additions & 1 deletion lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
opts.SerializeOptionsForDebugging.getValueOr(
!module->isExternallyConsumed());

serializationOpts.PathObfuscator = opts.serializedPathObfuscator;
if (serializationOpts.SerializeOptionsForDebugging &&
opts.DebugPrefixSerializedDebuggingOptions) {
serializationOpts.DebuggingOptionsPrefixMap =
Expand Down
8 changes: 0 additions & 8 deletions lib/Serialization/ModuleFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ ModuleFile::getModuleName(ASTContext &Ctx, StringRef modulePath,
serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load(
modulePath.str(), std::move(newBuf), nullptr, nullptr,
/*isFramework*/ isFramework, Ctx.SILOpts.EnableOSSAModules,
Ctx.SearchPathOpts.DeserializedPathRecoverer,
loadedModuleFile);
Name = loadedModuleFile->Name.str();
return std::move(moduleBuf.get());
Expand Down Expand Up @@ -1000,13 +999,6 @@ Optional<CommentInfo> ModuleFile::getCommentForDecl(const Decl *D) const {
return getCommentForDeclByUSR(USRBuffer.str());
}

void ModuleFile::collectSerializedSearchPath(
llvm::function_ref<void(StringRef)> callback) const {
for (auto path: Core->SearchPaths) {
callback(path.Path);
}
}

void ModuleFile::collectBasicSourceFileInfo(
llvm::function_ref<void(const BasicSourceFileInfo &)> callback) const {
if (Core->SourceFileListData.empty())
Expand Down
3 changes: 1 addition & 2 deletions lib/Serialization/ModuleFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,7 @@ class ModuleFile
Optional<Fingerprint> loadFingerprint(const IterableDeclContext *IDC) const;
void collectBasicSourceFileInfo(
llvm::function_ref<void(const BasicSourceFileInfo &)> callback) const;
void collectSerializedSearchPath(
llvm::function_ref<void(StringRef)> callback) const;


// MARK: Deserialization interface

Expand Down
33 changes: 14 additions & 19 deletions lib/Serialization/ModuleFileSharedCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ static bool enterTopLevelModuleBlock(llvm::BitstreamCursor &cursor,
/// Returns true on success.
static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
SmallVectorImpl<uint64_t> &scratch,
ExtendedValidationInfo &extendedInfo,
PathObfuscator &pathRecoverer) {
ExtendedValidationInfo &extendedInfo) {
while (!cursor.AtEndOfStream()) {
Expected<llvm::BitstreamEntry> maybeEntry = cursor.advance();
if (!maybeEntry) {
Expand Down Expand Up @@ -120,7 +119,7 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
unsigned kind = maybeKind.get();
switch (kind) {
case options_block::SDK_PATH:
extendedInfo.setSDKPath(pathRecoverer.recover(blobData));
extendedInfo.setSDKPath(blobData);
break;
case options_block::XCC:
extendedInfo.addExtraClangImporterOption(blobData);
Expand Down Expand Up @@ -172,8 +171,7 @@ static bool readOptionsBlock(llvm::BitstreamCursor &cursor,
static ValidationInfo validateControlBlock(
llvm::BitstreamCursor &cursor, SmallVectorImpl<uint64_t> &scratch,
std::pair<uint16_t, uint16_t> expectedVersion, bool requiresOSSAModules,
ExtendedValidationInfo *extendedInfo,
PathObfuscator &pathRecoverer) {
ExtendedValidationInfo *extendedInfo) {
// The control block is malformed until we've at least read a major version
// number.
ValidationInfo result;
Expand Down Expand Up @@ -204,7 +202,7 @@ static ValidationInfo validateControlBlock(
result.status = Status::Malformed;
return result;
}
if (!readOptionsBlock(cursor, scratch, *extendedInfo, pathRecoverer)) {
if (!readOptionsBlock(cursor, scratch, *extendedInfo)) {
result.status = Status::Malformed;
return result;
}
Expand Down Expand Up @@ -467,11 +465,10 @@ ValidationInfo serialization::validateSerializedAST(
result.status = Status::Malformed;
return result;
}
PathObfuscator localObfuscator;
result = validateControlBlock(
cursor, scratch,
{SWIFTMODULE_VERSION_MAJOR, SWIFTMODULE_VERSION_MINOR},
requiresOSSAModules, extendedInfo, localObfuscator);
requiresOSSAModules, extendedInfo);
if (result.status == Status::Malformed)
return result;
} else if (dependencies &&
Expand Down Expand Up @@ -941,7 +938,7 @@ getActualImportControl(unsigned rawValue) {
}
}

bool ModuleFileSharedCore::readModuleDocIfPresent(PathObfuscator &pathRecoverer) {
bool ModuleFileSharedCore::readModuleDocIfPresent() {
if (!this->ModuleDocInputBuffer)
return true;

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

bool ModuleFileSharedCore::readModuleSourceInfoIfPresent(PathObfuscator &pathRecoverer) {
bool ModuleFileSharedCore::readModuleSourceInfoIfPresent() {
if (!this->ModuleSourceInfoInputBuffer)
return true;

Expand Down Expand Up @@ -1124,8 +1121,7 @@ bool ModuleFileSharedCore::readModuleSourceInfoIfPresent(PathObfuscator &pathRec
infoCursor, scratch,
{SWIFTSOURCEINFO_VERSION_MAJOR, SWIFTSOURCEINFO_VERSION_MINOR},
RequiresOSSAModules,
/*extendedInfo*/ nullptr,
pathRecoverer);
/*extendedInfo*/ nullptr);
if (info.status != Status::Valid)
return false;
// Check that the swiftsourceinfo is actually for this module.
Expand Down Expand Up @@ -1200,7 +1196,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
bool isFramework, bool requiresOSSAModules,
serialization::ValidationInfo &info, PathObfuscator &pathRecoverer)
serialization::ValidationInfo &info)
: ModuleInputBuffer(std::move(moduleInputBuffer)),
ModuleDocInputBuffer(std::move(moduleDocInputBuffer)),
ModuleSourceInfoInputBuffer(std::move(moduleSourceInfoInputBuffer)),
Expand Down Expand Up @@ -1251,7 +1247,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
info = validateControlBlock(
cursor, scratch,
{SWIFTMODULE_VERSION_MAJOR, SWIFTMODULE_VERSION_MINOR},
RequiresOSSAModules, &extInfo, pathRecoverer);
RequiresOSSAModules, &extInfo);
if (info.status != Status::Valid) {
error(info.status);
return;
Expand Down Expand Up @@ -1376,8 +1372,7 @@ ModuleFileSharedCore::ModuleFileSharedCore(
bool isSystem;
input_block::SearchPathLayout::readRecord(scratch, isFramework,
isSystem);
SearchPaths.push_back({pathRecoverer.recover(blobData), isFramework,
isSystem});
SearchPaths.push_back({blobData, isFramework, isSystem});
break;
}
case input_block::MODULE_INTERFACE_PATH: {
Expand Down Expand Up @@ -1577,8 +1572,8 @@ ModuleFileSharedCore::ModuleFileSharedCore(
return;
}
// Read source info file.
readModuleSourceInfoIfPresent(pathRecoverer);
if (!readModuleDocIfPresent(pathRecoverer)) {
readModuleSourceInfoIfPresent();
if (!readModuleDocIfPresent()) {
info.status = error(Status::MalformedDocumentation);
return;
}
Expand Down
11 changes: 5 additions & 6 deletions lib/Serialization/ModuleFileSharedCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ModuleFileSharedCore {
SmallVector<Dependency, 8> Dependencies;

struct SearchPath {
std::string Path;
StringRef Path;
bool IsFramework;
bool IsSystem;
};
Expand Down Expand Up @@ -374,7 +374,7 @@ class ModuleFileSharedCore {
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
bool isFramework, bool requiresOSSAModules,
serialization::ValidationInfo &info, PathObfuscator &pathRecoverer);
serialization::ValidationInfo &info);

/// Change the status of the current module.
Status error(Status issue) {
Expand Down Expand Up @@ -464,7 +464,7 @@ class ModuleFileSharedCore {
/// Loads data from #ModuleDocInputBuffer.
///
/// Returns false if there was an error.
bool readModuleDocIfPresent(PathObfuscator &pathRecoverer);
bool readModuleDocIfPresent();

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

/// Read an on-disk decl hash table stored in
/// \c sourceinfo_block::DeclUSRSLayout format.
Expand Down Expand Up @@ -510,13 +510,12 @@ class ModuleFileSharedCore {
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
std::unique_ptr<llvm::MemoryBuffer> moduleSourceInfoInputBuffer,
bool isFramework, bool requiresOSSAModules,
PathObfuscator &pathRecoverer,
std::shared_ptr<const ModuleFileSharedCore> &theModule) {
serialization::ValidationInfo info;
auto *core = new ModuleFileSharedCore(
std::move(moduleInputBuffer), std::move(moduleDocInputBuffer),
std::move(moduleSourceInfoInputBuffer), isFramework,
requiresOSSAModules, info, pathRecoverer);
requiresOSSAModules, info);
if (!moduleInterfacePath.empty()) {
ArrayRef<char> path;
core->allocateBuffer(path, moduleInterfacePath);
Expand Down
Loading