Commit Graph

57 Commits

Author SHA1 Message Date
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
Erik Eckstein
7d7dc5aaac Demangler: Use a bump-pointer allocator for node allocation.
This makes the demangler about 10 times faster.
It also changes the lifetimes of nodes. Previously nodes were reference-counted.
Now the returned demangle  node-tree is owned by the Demangler class and it’s lifetime ends with the lifetime of the Demangler.

Therefore the old (and already deprecated) global functions demangleSymbolAsNode and demangleTypeAsNode are no longer available.

Another change is that the demangling for reflection now only supports the new mangling (which should be no problem because
we are generating only new mangled names for reflection).
2017-02-24 19:04:13 -08:00
Greg Parker
b71f2fd871 [test] Fix error handling in swift-reflection-test.
* Fix handling of EINTR return from read().
* Don't print errno after errors that do not set errno.
2017-01-20 17:51:23 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Joe
d82ad0357f Fixed buffer overflow in demangler
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
2016-07-20 18:54:23 +01:00
David Farler
787b0dcc3f Merge pull request #3419 from bitjammer/remote-mirror-metadata-version
SwiftRemoteMirror: Add reflection metadata version query API
2016-07-14 08:30:18 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
David Farler
941ec1e043 SwiftRemoteMirror: Add reflection metadata version query API
rdar://problem/27251582
2016-07-08 14:12:59 -07:00
Slava Pestov
da40b5e566 Merge pull request #2285 from tinysun212/pr-portability-1
[SwiftRemoteMirror] Renamed addr_t to swift_addr_t
2016-06-02 10:59:46 -07:00
David Farler
9dddc6492b SwiftRemoteMirror: Project error existentials
Error existentials have a kind of special heap layout and can also
be compatible as NSError instances, too.
2016-05-10 12:50:31 -07:00
Han Sangjin
675de4048d [SwiftRemoteMirror] Renamed addr_t to swift_addr_t
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.
2016-05-11 04:02:11 +09:00
David Farler
2fd0b39751 SwiftRemoteMirror: move dump APIs to print to stdout instead of stderr
Rather than move file descriptors around in the tools, just tell the
underlying ::dump methods to print to stdout instead.
2016-05-09 14:29:33 -07:00
Slava Pestov
06dc666b49 Reflection: Small cleanups for swift-reflection-test 2016-05-09 13:40:57 -07:00
Slava Pestov
5cc4ce1760 Reflection: Looking up CaptureDescriptors by remote address
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.
2016-05-09 13:40:57 -07:00
David Farler
8a005e6335 swift-reflection-test: Funnel all test output to stdout
Some test harnesses may print stdout/stderr in batches, which can
complicate FileCheck. Just funnel everything through stdout.
2016-05-09 13:39:39 -07:00
David Farler
86f2886f17 swift-reflection-test: Send target-specific sizes
There were some unconditional 64-bit values getting sent which
was hanging up on the 32-bit iOS simulator.
2016-05-03 21:04:31 -07:00
David Farler
5f5ce39a1d SwiftRemoteMirror: Wire up existential projection API
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.
2016-05-03 21:04:31 -07:00
David Farler
b8cb128a17 swift-reflection-test: Make it possible to call reflect multiple times
This allows you to test multiple class instances in the same file.
2016-05-03 21:04:31 -07:00
Slava Pestov
71d28691ef Reflection: Plumb through capture descriptor section 2016-05-02 01:16:25 -07:00
Slava Pestov
ddc81e1b68 Reflection: Some more refactoring for swift-reflection-test, NFC 2016-05-02 01:16:24 -07:00
practicalswift
8e3ba900b0 [gardening] Fix recently introduced headers. 2016-05-01 12:59:13 +02:00
Slava Pestov
faecfda594 Reflection: Consolidate some code for passing around reflection sections
I'm about to add a new section, and I'd like to update as few
places as possible.
2016-04-30 15:12:38 -07:00
Slava Pestov
1d5b9b09ac Reflection: Add instance-specific layout entry point, and do some refactoring
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.
2016-04-29 15:39:49 -07:00
David Farler
11faafe65e swift-reflection-test: Spread out the printing a little 2016-04-29 12:10:52 -07:00
Slava Pestov
ce1c30b1bc Reflection: Support reading the remote process's isaMask
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.
2016-04-28 22:56:15 -07:00
David Farler
bd9fd053ed swift-reflection-test: Remove stray debug print 2016-04-28 19:38:06 -07:00
David Farler
d769eb328f swift-reflection-test: Reference sizeof pointer/size types statically
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.
2016-04-28 19:38:06 -07:00
David Farler
210f8dfe63 swift-reflection-test: Target SwiftRemoteMirror C API
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.
2016-04-28 19:38:03 -07:00
Slava Pestov
7a9a4dca83 Reflection: Preliminary C API entry points for class instance layout
Tested by manually running swift-reflection-test, no automated
tests yet, but coming soon.
2016-04-27 23:15:08 -07:00
Slava Pestov
95d648779b Reflection: Fix some bugs in swift-reflection-test
- Improper handling of read() returning an incomplete read
- Update SwiftReflectionTest library for new builtin types section

Only tested manually so far; automated tests coming soon.
2016-04-27 18:17:25 -07:00
David Farler
0c83fce1c6 Link swift-reflection-test* with swiftRemoteMirror
Eventually this tool will test solely with the C API, so wire up
the dependencies now. This also fixes an annoying dependency issue
when building some testing configurations.

rdar://problem/25943881
2016-04-27 14:42:41 -07:00
practicalswift
02088ebe40 [gardening] Fix spacing. 2016-04-15 20:07:22 +02:00
Slava Pestov
824bd7544d IRGen: Emit typerefs for all builtin types referenced from reflection metadata sections
In order to perform layout, the remote mirrors library needs to know
about the size, alignment and extra inhabitants of builtin types.

Ideally we would emit a reflection info section in libswiftRuntime.o,
but in the meantime just duplicate builtin type metadata for all
builtin types referenced from the current module instead.

In practice only the stdlib and a handful of overlays like the SIMD
overlay use builtin types, and only a few at a time.

Tested manually by running swift-reflection-tool on the standard
library -- I'll add automated tests by using -parse-stdlib to
reference Builtin types in a subsequent patch that adds more layout
logic.

NFC if -enable-reflection-metadata is off.
2016-04-15 00:12:11 -07:00
John McCall
7ff15dd075 Progress towards marking ReflectionContext templated over the builder. 2016-04-14 13:39:35 -07:00
John McCall
91f02848df Organize the MemoryReader interface headers to better support
multiple clients.
2016-04-12 16:05:29 -07:00
David Farler
3c4f059c0f Provide shims for fork/execv for watchOS and tvOS
These functions are marked as unavailable but can be linked. This
is a temporary hack.
2016-04-05 16:59:17 -07:00
David Farler
358a0fefe8 Add SwiftRemoteMirror library
This will wrap the ./lib/Reflection functionality in a C
interface.
2016-04-05 13:45:46 -07:00
practicalswift
cd41538162 [gardening] Fix file header formatting. 2016-03-30 18:20:50 +02:00
David Farler
5ea5bb06a3 Split swift-refleciton-test into host and target test targets
swift-reflection-test is now the test that forks a swift executable
and performs remote reflection, making it runnable on other targets,
such as the iOS simulator.

swift-reflection-dump is now a host-side tool that dumps the remote
reflection sections for any platform binary and will continue to
link in LLVM object file support.

This necessitates finally moving lib/Refleciton into stdlib/public,
since we're linking target-specific versions of the test tool and
we would eventually like to adopt some of this functionality in
the runtime anyway.
2016-03-28 16:34:44 -07:00
David Farler
76b31a9343 swift-reflection-test: Increase reading robustness
- Check return values from `read`
- Make the reflstr section optional, as it can be stripped by
  -strip-reflection-names.
2016-03-24 12:05:18 -07:00
David Farler
23a823a3ed Remote Mirrors: Make MemoryReader a real class
Make the reader a class interface internally, with the
bag-of-function pointers via the eventual C API being the
special case.
2016-03-24 12:05:18 -07:00
David Farler
579ce977f0 swift-reflection-test: Replace Mach IPC with pipes
This is more amenable to cross-platform remote reflection tests.

Also add a new callback to the memory reader: getSymbolAddress,
which will be used for getting the addresses of nominal type
descriptors for concrete and fixed generic types.
2016-03-17 19:02:01 -07:00
David Farler
834b03b6cd [Reflection] Substitute generics and resolve dependent members
Once an unsubstituted typeref for a field is built, we substitute
`GenericTypeParameterTypeRef`s with concrete ones built from the generic
arguments of concrete bound generic metadata.

During that process, if we run into a `DependentMemberTypeRef` (e.g.
something of type T.Index), we substitute the base (T) using the current
list of substitutions, and then resolve what `Index` is for the base
using the associated type metadata in the 'assocty' data section.
2016-03-07 17:43:13 -08:00
David Farler
ce3ed51485 swift-reflection-test: Don't leave test process hanging 2016-03-04 17:10:40 -08:00
David Farler
5196f5b89c Get typerefs for nominal type metadata
and read their generic arguments, if there are any, too.
2016-03-04 17:10:39 -08:00
practicalswift
48193eff1d [gardening] Fix recently introduced typo: "exectuable" → "executable" 2016-03-03 23:40:25 +01:00
Slava Pestov
768f6da949 swift-reflection-test: Fix warnings 2016-03-03 06:59:55 -08:00
Slava Pestov
acca688e3f Fix compile error in swift-reflection-test.cpp 2016-03-02 22:12:20 -08:00
David Farler
f73223aba5 swift-reflection-test: Guard Mach-specific remote tests
These won't build on Linux.
2016-03-02 21:25:05 -08:00