Changing the name of ErrorProtocol to Error broke this runtime test —
causing a buffer overflow.
The mangled name changed from _TtPs13ErrorProtocol_->_TtPs5Error_ but
the strlen didn’t change from 21 to 12; I update the callers to use
static string length instead of a literal string & length.
Error reported is:
=================================================================
==88865==ERROR: AddressSanitizer: global-buffer-overflow on address
0x0001028ba40d at pc 0x000103291a1f bp 0x7fff5d3492c0 sp 0x7fff5d348a80
READ of size 9 at 0x0001028ba40d thread T0
(libclang_rt.asan_osx_dynamic.dylib+0x42a1e)
std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char
const*, unsigned long) (libc++.1.dylib+0x3f224)
swift::Demangle::NodeFactory::create(swift::Demangle::Node::Kind,
llvm::StringRef) string:2044
namespace)::Demangler::demangleTopLevel() Demangle.cpp:358
unsigned long, swift::Demangle::DemangleOptions const&)
Demangle.cpp:2288
MetadataReader.h:772
0x0001028ba40d is located 51 bytes to the left of global variable
'<string literal>' defined in
'/Users/buildslave/jenkins/workspace/swift-incremental-asan-RDA/swift/to
ols/swift-reflection-test/swift-reflection-test.c:458:19' (0x1028ba440)
of size 41
'<string literal>' is ascii string 'swift-reflection-test <binary
filename>
'
0x0001028ba40d is located 0 bytes to the right of global variable
'<string literal>' defined in
'/Users/buildslave/jenkins/workspace/swift-incremental-asan-RDA/swift/to
ols/swift-reflection-test/swift-reflection-test.c:435:15' (0x1028ba400)
of size 13
'<string literal>' is ascii string '_TtPs5Error_'
SUMMARY: AddressSanitizer: global-buffer-overflow
(libclang_rt.asan_osx_dynamic.dylib+0x42a1e) in wrap_memmove
They would think the type 'addr_t' is defined in the standard library
because it has the same name format with the types in <cstdint>. In
addition, the definition conflicts in Cygwin which defines it differently
in the system library.
Remote metadata for closure contexts points to a capture descriptor.
We have a local copy of all capture descriptors. Translate the
address by recording the local and remote start address of
reflection metadata.
Implement the ReflectionContext's implementation of:
swift_reflection_projectExistential.
First, we get the type info of the existential typeref - it should be a
record type info. If it's a class existential, it has trivial layout:
the first word is a pointer to the class instance. Otherwise, if the
value fits in the 3-word buffer of the existential container, it
trivially is also at the start of the container. Otherwise, the value is
off in a heap box somewhere, but the first word of the container is a
pointer to that box.
Closure context layout will depend on the instance itself as well
as the isa pointer, because instead of instantiating metadata for
closures that capture generic parameters, we store the substitutions
inside the context itself.
For classes, this entry point just reads the isa pointer, applies
the isa mask and proceeds down the metadata path.
For now, the only the latter is hooked up.
Also, use the instance layout entry point in swift-reflection-test,
so that we can dump the layout of a class instance and not the
lowering of the reference value.
These tools are always architecture-specific and always match the
architecture of the built Swift binary that links against
SwiftReflectionTest, so they can statically reference the size of their
pointer types.
This tool should test the usage from SwiftRemoteMirror dylib and
the C API, since that is the public interface from which we're
vending the remote reflection functionality.