mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add -prefix-serialized-debugging-options
This commit adds the `-prefix-serialized-debugging-options` flag, which is used to apply the debug prefix map to serialized debugging options embedded in the swiftmodule files.
This commit is contained in:
@@ -182,6 +182,11 @@ public:
|
||||
/// module appears to not be a public module.
|
||||
Optional<bool> SerializeOptionsForDebugging;
|
||||
|
||||
/// When true the debug prefix map entries will be applied to debugging
|
||||
/// options before serialization. These can be reconstructed at debug time by
|
||||
/// applying the inverse map in SearchPathOptions.SearchPathRemapper.
|
||||
bool DebugPrefixSerializedDebuggingOptions = false;
|
||||
|
||||
/// When true, check if all required SwiftOnoneSupport symbols are present in
|
||||
/// the module.
|
||||
bool CheckOnoneSupportCompleteness = false;
|
||||
|
||||
@@ -815,6 +815,10 @@ def debug_info_format : Joined<["-"], "debug-info-format=">,
|
||||
Flags<[FrontendOption]>,
|
||||
HelpText<"Specify the debug info format type to either 'dwarf' or 'codeview'">;
|
||||
|
||||
def prefix_serialized_debugging_options : Flag<["-"], "prefix-serialized-debugging-options">,
|
||||
Flags<[FrontendOption]>,
|
||||
HelpText<"Apply debug prefix mappings to serialized debug info in Swiftmodule files">;
|
||||
|
||||
// Verify debug info
|
||||
def verify_debug_info : Flag<["-"], "verify-debug-info">,
|
||||
Flags<[NoInteractiveOption, DoesNotAffectIncrementalBuild]>,
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#define SWIFT_SERIALIZATION_SERIALIZATIONOPTIONS_H
|
||||
|
||||
#include "swift/Basic/LLVM.h"
|
||||
#include "swift/Basic/PathRemapper.h"
|
||||
#include "llvm/Support/VersionTuple.h"
|
||||
|
||||
namespace swift {
|
||||
@@ -42,7 +43,10 @@ namespace swift {
|
||||
StringRef ImportedHeader;
|
||||
StringRef ModuleLinkName;
|
||||
StringRef ModuleInterface;
|
||||
ArrayRef<std::string> ExtraClangOptions;
|
||||
std::vector<std::string> ExtraClangOptions;
|
||||
|
||||
/// Path prefixes that should be rewritten in debug info.
|
||||
PathRemapper DebuggingOptionsPrefixMap;
|
||||
|
||||
/// Describes a single-file dependency for this module, along with the
|
||||
/// appropriate strategy for how to verify if it's up-to-date.
|
||||
|
||||
@@ -258,6 +258,8 @@ bool ArgsToFrontendOptionsConverter::convert(
|
||||
A->getOption().matches(OPT_serialize_debugging_options);
|
||||
}
|
||||
|
||||
Opts.DebugPrefixSerializedDebuggingOptions |=
|
||||
Args.hasArg(OPT_prefix_serialized_debugging_options);
|
||||
Opts.EnableSourceImport |= Args.hasArg(OPT_enable_source_import);
|
||||
Opts.ImportUnderlyingModule |= Args.hasArg(OPT_import_underlying_module);
|
||||
Opts.EnableIncrementalDependencyVerifier |= Args.hasArg(OPT_verify_incremental_dependencies);
|
||||
|
||||
@@ -147,7 +147,7 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
|
||||
serializationOpts.ImportedHeader = opts.ImplicitObjCHeaderPath;
|
||||
serializationOpts.ModuleLinkName = opts.ModuleLinkName;
|
||||
serializationOpts.UserModuleVersion = opts.UserModuleVersion;
|
||||
serializationOpts.ExtraClangOptions = getClangImporterOptions().ExtraArgs;
|
||||
|
||||
serializationOpts.PublicDependentLibraries =
|
||||
getIRGenOptions().PublicLinkLibraries;
|
||||
serializationOpts.SDKName = getLangOptions().SDKName;
|
||||
@@ -176,6 +176,20 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
|
||||
opts.SerializeOptionsForDebugging.getValueOr(
|
||||
!module->isExternallyConsumed());
|
||||
|
||||
if (serializationOpts.SerializeOptionsForDebugging &&
|
||||
opts.DebugPrefixSerializedDebuggingOptions) {
|
||||
serializationOpts.DebuggingOptionsPrefixMap =
|
||||
getIRGenOptions().DebugPrefixMap;
|
||||
auto &remapper = serializationOpts.DebuggingOptionsPrefixMap;
|
||||
auto remapClangPaths = [&remapper](StringRef path) {
|
||||
return remapper.remapPath(path);
|
||||
};
|
||||
serializationOpts.ExtraClangOptions =
|
||||
getClangImporterOptions().getRemappedExtraArgs(remapClangPaths);
|
||||
} else {
|
||||
serializationOpts.ExtraClangOptions = getClangImporterOptions().ExtraArgs;
|
||||
}
|
||||
|
||||
serializationOpts.DisableCrossModuleIncrementalInfo =
|
||||
opts.DisableCrossModuleIncrementalBuild;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "swift/Basic/Defer.h"
|
||||
#include "swift/Basic/Dwarf.h"
|
||||
#include "swift/Basic/FileSystem.h"
|
||||
#include "swift/Basic/PathRemapper.h"
|
||||
#include "swift/Basic/STLExtras.h"
|
||||
#include "swift/Basic/Version.h"
|
||||
#include "swift/ClangImporter/ClangImporter.h"
|
||||
@@ -48,9 +49,9 @@
|
||||
#include "swift/Demangling/ManglingMacros.h"
|
||||
#include "swift/Serialization/SerializationOptions.h"
|
||||
#include "swift/Strings.h"
|
||||
#include "clang/AST/DeclTemplate.h"
|
||||
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
|
||||
#include "swift/SymbolGraphGen/SymbolGraphGen.h"
|
||||
#include "swift/SymbolGraphGen/SymbolGraphOptions.h"
|
||||
#include "clang/AST/DeclTemplate.h"
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
@@ -1058,25 +1059,35 @@ void Serializer::writeHeader(const SerializationOptions &options) {
|
||||
options_block::SDKPathLayout SDKPath(Out);
|
||||
options_block::XCCLayout XCC(Out);
|
||||
|
||||
SDKPath.emit(ScratchRecord, M->getASTContext().SearchPathOpts.SDKPath);
|
||||
const auto &PathRemapper = options.DebuggingOptionsPrefixMap;
|
||||
SDKPath.emit(
|
||||
ScratchRecord,
|
||||
PathRemapper.remapPath(M->getASTContext().SearchPathOpts.SDKPath));
|
||||
auto &Opts = options.ExtraClangOptions;
|
||||
for (auto Arg = Opts.begin(), E = Opts.end(); Arg != E; ++Arg) {
|
||||
StringRef arg(*Arg);
|
||||
if (arg.startswith("-ivfsoverlay")) {
|
||||
// FIXME: This is a hack and calls for a better design.
|
||||
//
|
||||
// Filter out any -ivfsoverlay options that include an
|
||||
// unextended-module-overlay.yaml overlay. By convention the Xcode
|
||||
// buildsystem uses these while *building* mixed Objective-C and Swift
|
||||
// frameworks; but they should never be used to *import* the module
|
||||
// defined in the framework.
|
||||
if (StringRef(*Arg).startswith("-ivfsoverlay")) {
|
||||
// buildsystem uses these while *building* mixed Objective-C and
|
||||
// Swift frameworks; but they should never be used to *import* the
|
||||
// module defined in the framework.
|
||||
auto Next = std::next(Arg);
|
||||
if (Next != E &&
|
||||
StringRef(*Next).endswith("unextended-module-overlay.yaml")) {
|
||||
++Arg;
|
||||
continue;
|
||||
}
|
||||
} else if (arg.startswith("-fdebug-prefix-map=")) {
|
||||
// We don't serialize the debug prefix map flags as these
|
||||
// contain absoute paths that are not usable on different
|
||||
// machines. These flags are not necessary to compile the
|
||||
// clang modules again so are safe to remove.
|
||||
continue;
|
||||
}
|
||||
XCC.emit(ScratchRecord, *Arg);
|
||||
XCC.emit(ScratchRecord, arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1127,14 +1138,16 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
|
||||
input_block::ModuleInterfaceLayout ModuleInterface(Out);
|
||||
|
||||
if (options.SerializeOptionsForDebugging) {
|
||||
const auto &PathMapper = options.DebuggingOptionsPrefixMap;
|
||||
const SearchPathOptions &searchPathOpts = M->getASTContext().SearchPathOpts;
|
||||
// Put the framework search paths first so that they'll be preferred upon
|
||||
// deserialization.
|
||||
for (auto &framepath : searchPathOpts.FrameworkSearchPaths)
|
||||
SearchPath.emit(ScratchRecord, /*framework=*/true, framepath.IsSystem,
|
||||
framepath.Path);
|
||||
PathMapper.remapPath(framepath.Path));
|
||||
for (auto &path : searchPathOpts.ImportSearchPaths)
|
||||
SearchPath.emit(ScratchRecord, /*framework=*/false, /*system=*/false, path);
|
||||
SearchPath.emit(ScratchRecord, /*framework=*/false, /*system=*/false,
|
||||
PathMapper.remapPath(path));
|
||||
}
|
||||
|
||||
// Note: We're not using StringMap here because we don't need to own the
|
||||
|
||||
51
test/Serialization/search-paths-prefix-map.swift
Normal file
51
test/Serialization/search-paths-prefix-map.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %empty-directory(%t/Frameworks/has_alias.framework/Modules/has_alias.swiftmodule)
|
||||
// RUN: %target-swift-frontend -emit-module -o %t/Frameworks/has_alias.framework/Modules/has_alias.swiftmodule/%target-swiftmodule-name %S/Inputs/alias.swift -module-name has_alias
|
||||
// RUN: %empty-directory(%t/secret)
|
||||
// RUN: %target-swift-frontend -emit-module -o %t/secret %S/Inputs/struct_with_operators.swift
|
||||
// RUN: %target-swift-frontend -emit-module -o %t -I %t/secret -F %t/Frameworks -Fsystem %t/SystemFrameworks %S/Inputs/has_xref.swift
|
||||
// RUN: %empty-directory(%t/workingdir)
|
||||
// RUN: cd %t/workingdir && %target-swift-frontend -sdk %t/sdk %s -emit-module -o %t/prefixed.swiftmodule \
|
||||
// RUN: -I %t -I %t/secret -F %t/Frameworks -Fsystem %t/SystemFrameworks \
|
||||
// RUN: -Xcc -I -Xcc %t/include -Xcc -isystem -Xcc %t/system -Xcc -F -Xcc %t/fw \
|
||||
// RUN: -Xcc -I%t/includejoined -Xcc -isystem%t/systemjoined -Xcc -F%t/fwjoined \
|
||||
// RUN: -Xcc -D -Xcc donotprefixme -prefix-serialized-debugging-options \
|
||||
// RUN: -debug-prefix-map %t/workingdir=WORKINGDIR -debug-prefix-map %t/sdk=SDKROOT -debug-prefix-map %t=SRC -debug-prefix-map donotprefixme=ERROR
|
||||
// RUN: llvm-bcanalyzer -dump %t/prefixed.swiftmodule | %FileCheck %s
|
||||
|
||||
import has_xref
|
||||
|
||||
numeric(42)
|
||||
|
||||
// CHECK-LABEL: <OPTIONS_BLOCK
|
||||
// CHECK: <SDK_PATH abbrevid={{[0-9]+}}/> blob data = 'SDKROOT'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = '-working-directory'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = 'WORKINGDIR'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = '-I'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = 'SRC/include'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = '-isystem'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = 'SRC/system'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = '-F'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = 'SRC/fw'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = '-ISRC/includejoined'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = '-isystemSRC/systemjoined'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = '-FSRC/fwjoined'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = '-D'
|
||||
// CHECK: <XCC abbrevid={{[0-9]+}}/> blob data = 'donotprefixme'
|
||||
// CHECK-NOT: <XCC abbrevid={{[0-9]+}}/> blob data = '-fdebug-prefix-map
|
||||
// CHECK: </OPTIONS_BLOCK>
|
||||
|
||||
// CHECK-LABEL: <INPUT_BLOCK
|
||||
// CHECK: <SEARCH_PATH abbrevid={{[0-9]+}} op0=1 op1=0/> blob data = 'SRC/Frameworks'
|
||||
// CHECK: <SEARCH_PATH abbrevid={{[0-9]+}} op0=1 op1=1/> blob data = 'SRC/SystemFrameworks'
|
||||
// CHECK: <SEARCH_PATH abbrevid={{[0-9]+}} op0=0 op1=0/> blob data = 'SRC'
|
||||
// CHECK: <SEARCH_PATH abbrevid={{[0-9]+}} op0=0 op1=0/> blob data = 'SRC/secret'
|
||||
// CHECK: </INPUT_BLOCK>
|
||||
|
||||
// RUN: cd %t/workingdir && %target-swift-frontend -sdk %t/sdk %s -emit-module -o %t/unprefixed.swiftmodule \
|
||||
// RUN: -I %t -F %t/Frameworks \
|
||||
// RUN: -Xcc -I -Xcc %t/include \
|
||||
// RUN: -debug-prefix-map %t=TESTPREFIX
|
||||
// RUN: llvm-bcanalyzer -dump %t/unprefixed.swiftmodule | %FileCheck --check-prefix=UNPREFIXED %s
|
||||
|
||||
// UNPREFIXED-NOT: TESTPREFIX
|
||||
Reference in New Issue
Block a user