[vm/compiler] Support obfuscation of record field names

TEST=language/records/simple/* on vm-aot-obfuscate-linux-release-x64

Fixes https://github.com/dart-lang/sdk/issues/52124
Fixes https://github.com/flutter/flutter/issues/125289

Cq-Include-Trybots: luci.dart.try:vm-aot-obfuscate-linux-release-x64-try
Change-Id: Ic53ae5282ba1d30b395fa706840393fd467abf2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296920
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
This commit is contained in:
Alexander Markov 2023-04-21 15:14:58 +00:00 committed by Commit Queue
parent df63c24638
commit d83caf1c0c
3 changed files with 8 additions and 1 deletions

View file

@ -3985,6 +3985,12 @@ StringPtr Obfuscator::ObfuscationState::NewAtomicRename(
StringPtr Obfuscator::ObfuscationState::BuildRename(const String& name,
bool atomic) {
// Do not rename record positional field names $1, $2 etc
// in order to handle them properly during dynamic invocations.
if (Record::GetPositionalFieldIndexFromFieldName(name) >= 0) {
return name.ptr();
}
if (atomic) {
return NewAtomicRename(name.CharAt(0) == '_');
}

View file

@ -4210,7 +4210,7 @@ Fragment StreamingFlowGraphBuilder::BuildRecordFieldGet(TokenPosition* p,
const intptr_t num_positional_fields =
record_type.NumFields() - field_names.Length();
if (is_named) {
const String& field_name = H.DartSymbolPlain(ReadStringReference());
const String& field_name = H.DartSymbolObfuscate(ReadStringReference());
for (intptr_t i = 0, n = field_names.Length(); i < n; ++i) {
if (field_names.At(i) == field_name.ptr()) {
field_index = i;

View file

@ -19,6 +19,7 @@ generic/no_such_method_dispatcher_test: SkipByDesign # Relies on symbol names
generic/recursive_generic_test: SkipByDesign # Relies on symbol names
nnbd/syntax/late_modifier_runtime_error_test: SkipByDesign # Names are obfuscated in error messages
no_such_method/native_test: SkipByDesign # Relies on symbol names
records/simple/to_string_test: SkipByDesign # Relies on symbol names
regress/regress45529_test: SkipByDesign # Relies on symbol names
stack_trace/demangle_ctors_test: SkipByDesign # Relies on symbol names
type_object/literal_type_literal_test: SkipByDesign # Relies on symbol names