Skip to content

[Reflection] Prevent symbolic reference mangling induced crash #37732

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

Conversation

kastiglione
Copy link
Contributor

Based on lldb crash logs, TypeRefBuilder is crashing on instances of symbolic references in mangled names.

The crash happens when a symbolic reference is attempted to be mangled (via mangleNode()), which leads to a call to unreachable which aborts. For library usage, such as from lldb, these cases need to be handled without an abort.

The improvements to gracefully handle symbolic references are:

  1. Change the return type of normalizeReflectionName from std::string to llvm::Optional<std::string>
  2. Thread through a bool flag named useOpaqueTypeSymbolicReferences

Both of these start in normalizeReflectionName.

First, the call to demangleTypeRef() now sets useOpaqueTypeSymbolicReferences to false. Without this, demangleTypeRef() can return a node of kind OpaqueTypeDescriptorSymbolicReference, which is guaranteed to fail in this code path when in subsequent call to mangleNode().

Second, if the result of demangleTypeRef() is one of the symbolic reference kinds, then the function exits early with a value of None. Callers of normalizeReflectionName() are now forced to handle such cases, where the mangled name could not be normalized.

In TypeRefBuilder::getFieldTypeInfo(), if normalizeReflectionName() fails, then the corresponding field is not supported, or in other words, dropped.

rdar://77613304

(cherry picked from #37514)

@kastiglione
Copy link
Contributor Author

See #37514 for original context.

@kastiglione
Copy link
Contributor Author

@swift-ci test

@kastiglione kastiglione merged commit 330f040 into main Jun 2, 2021
@kastiglione kastiglione deleted the Reflection-Prevent-type-reference-manlging-induced-creash-main branch June 2, 2021 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants