diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-03-22 12:04:33 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-22 12:04:33 -0400 |
| commit | d4f99c8bac8b28f18c864a717d8833db6a1c872d (patch) | |
| tree | ebea06c019130d8248d5e4f6bccf5e4b2649e3cb /source/slang/slang-lower-to-ir.cpp | |
| parent | d8a40abba5223fbcb56c52b04ccb88c02bbaf79f (diff) | |
Source map obfuscation (#2717)
* #include an absolute path didn't work - because paths were taken to always be relative.
* WIP source map.
* Split out handling of RttiTypeFuncs to a map type.
* Make RttiTypeFuncsMap hold default impls.
* Slightly more sophisticated RttiTypeFuncsMap
* Source map decoding.
* Fix tabs.
* Fix asserts due to negative values.
* Use less obscure mechanisms in SourceMap.
* Source map decoding.
Simplifying SourceMap usage.
* First attempt at ouputting a source map as part of emit.
* Added support for -source-map option. SourceMap is added to the artifact.
* Small improvements around column calculation in SourceWriter.
* Source Loc obuscation WIP.
* Fix some issues around SourceMap obfuscation.
* Split out obfuscation into its own file.
* Keep obfuscated SourceMap even through serialization bottleneck.
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 86df89702..f84f17886 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -3,6 +3,10 @@ #include "../../slang.h" +#include "../core/slang-random-generator.h" +#include "../core/slang-hash.h" +#include "../core/slang-char-util.h" + #include "slang-check.h" #include "slang-ir.h" #include "slang-ir-constexpr.h" @@ -21,6 +25,8 @@ #include "slang-ir-string-hash.h" #include "slang-ir-clone.h" #include "slang-ir-lower-error-handling.h" +#include "slang-ir-obfuscate-loc.h" + #include "slang-mangle.h" #include "slang-type-layout.h" #include "slang-visitor.h" @@ -9299,10 +9305,17 @@ RefPtr<IRModule> generateIRForTranslationUnit( Linkage* linkage = compileRequest->getLinkage(); stripOptions.shouldStripNameHints = linkage->m_obfuscateCode; - stripOptions.stripSourceLocs = linkage->m_obfuscateCode; + // If we are generating an obfuscated source map, we don't want to strip locs, + // we want to generate *new* locs that can be mapped (via source map) + // back to *actual* source. + // + // We don't do the obfuscation remapping here, because DCE and other passes may + // change what locs are actually needed, we need to be sure + // that if we have obfuscation enabled we don't forget to obfuscate. + stripOptions.stripSourceLocs = linkage->m_obfuscateCode && !linkage->m_generateSourceMap; stripFrontEndOnlyInstructions(module, stripOptions); - + // Stripping out decorations could leave some dead code behind // in the module, and in some cases that extra code is also // undesirable (e.g., the string literals referenced by name-hint @@ -9314,6 +9327,12 @@ RefPtr<IRModule> generateIRForTranslationUnit( IRDeadCodeEliminationOptions options; options.keepExportsAlive = true; eliminateDeadCode(module, options); + + if (linkage->m_obfuscateCode && linkage->m_generateSourceMap) + { + // The obfuscated source map is stored on the module + obfuscateModuleLocs(module, compileRequest->getSourceManager()); + } } // TODO: consider doing some more aggressive optimizations |
