81 Commits (dc031d2741b47d2ddab00b542878ceea8577223b)

Author SHA1 Message Date
Hugo Melder dc031d2741
Windows on ARM64: Support Visual Studio ABI sret mechanism for non-trivial data types (#289)
* Add objc_msgSend_stret2

* Guard and Export objc_msgSend_stret2

* Remove architecture hackery in CMake

* Add objc_msgSend test for WoA64

* Add doc comment for objc_msgSend_stret2
2 years ago
David Chisnall 377a81d237 Add support for fast-path alloc / init methods and direct methods.
The fast paths follow the pattern that we established for fast ARC:
Framework base classes can opt in by implementing a `+_TrivialAllocInit`
method.

This opt-in behaviour is inherited and is removed implicitly in any
subclass that implements alloc or init methods (alloc and init are
treated independently).

Compilers can emit calls to `objc_alloc(cls)` instead of `[cls alloc]`,
`objc_allocWithZone(cls)` instead of `[cls allocWithZone: NULL]`, and
`objc_alloc_init` instead of `[[cls alloc] init]`.

Direct methods don't require very much support in the runtime.  Apple
reuses their fast path for `-self` (which is supported only in the Apple
fork of clang, not the upstream version) for a fast init.  Given that
the first few fields of the runtime's class structure have been stable
for around 30 years, I'm happy moving the flags word (and the
initialised bit, in particular) into the public ABI.  This lets us do a
fast-path check for whether a class is initialised in class methods and
call `objc_send_initialize` if it isn't.  This function is now exposed
as part of the public ABI, it was there already and does the relevant
checks without invoking any of the message-sending machinery.

Fixes #165 #169
2 years ago
Hugo Melder 3c42c64c14
Skip tests using objc_msgSend if not available (#263)
* Add __GNUSTEP_MSGSEND__ definition

* Mark test as skipped if return code is 77

* Skip tests using objc_msgSend if not available

* ManyManySelectors: Skip objc_msgSend if not available

* Skip UnexpectedException test on ARM and AArch64

* Add UnexpectedException.m to list of unit tests

* Call manyArgs with objc_msgSend directly
2 years ago
Hugo Melder 5cf2b7350e
AArch64 objc_msgSend: Fix argument corruption due to invalid stack pointer offset (#266)
* Fix argument corruption due to invalid sp offset

* Bump runtime version
2 years ago
Frederik Carlier 0771ddf3e5 Don't -fobjc-runtime=gnustep-2.0 as a global flag
The legacy tests will override this flag.
2 years ago
Frederik Carlier d34e066483 Tests: Append CMAKE_BINARY_DIR to PATH on Windows
Avoids copying objc.dll to the tests directory.
2 years ago
Hugo Melder ab23f14fd7
Initial Windows on ARM (AArch64) Support (#249)
* Conditionally include ntdll.dll

* Use text relocation instead of GOT

* Use FlushInstructionCache instead of clear_cache for arm64

* Load address in two stages (adrp, add)

* objc_msgSend.aarch64.S add comments

* Add seh directives

* Move .seh_proc into slow sloop section

* Comment out cfi directives

* Substitute raw .seh directives with macros

* Add documentation of SEH annotations

* Detect CPU Architecture with preprocessor

* Cleanup CMakeLists.txt

Co-authored-by: David Chisnall <davidchisnall@users.noreply.github.com>

* Remove line in objc_msgSend.aarch64.S

Co-authored-by: David Chisnall <davidchisnall@users.noreply.github.com>

* Change Test CMakeList to use ARCHITECTURE var

* Use existing clear cache macro

* Change _WIN64 to _WIN32 and reorder labels

* Remove macro and replace _WIN64 with _WIN32

* Remove argument from non-win32 macro

---------

Co-authored-by: David Chisnall <davidchisnall@users.noreply.github.com>
2 years ago
Frederik Seiffert 226455bd10 Tests: disable failing UnexpectedException test on ARM architectures 2 years ago
Frederik Seiffert ca46e42516 Add test for unexpected exception hook 2 years ago
David Chisnall 7c23a07bb4 Various CMake cleanups and modernisations.
This adds a dependency on a version of CMake with support for Objective-C,
removing a number of hacks to make CMake work and introduces a few
modernisations:

 - Options use CMake's `option` mechanism.
 - A lot of things now use generator expressions, which should improve the
   things like the multi-config Ninja generator.
 - We no longer depend on hacks to build in CI.

At the same time, a few other things are simplified:

 - There is no longer support for building without C++ support and we depend on
   a C++ standard library, not just a runtime. This makes it possible to use
   more C++ features inside the runtime.
 - We no longer support clang-cl on Windows and instead require clang.exe.
 - Support for the Boehm GC has been removed.
3 years ago
Stefan Gränitz 8c600f5b56
Enable test ObjCXXEHInterop_arc on Windows for Clang 16+ (#233)
This test used to fail on Windows, because Clang's codegen and transformation haven't been in-line with the requirements of the WinEH backend in LLVM. The following changes implement the missing pieces and let the test to pass in both debug and release mode:

https://reviews.llvm.org/D128190 [WinEH] Apply funclet operand bundles to nounwind intrinsics that lower to function calls in the course of IR transforms
https://reviews.llvm.org/D134441 [ObjC][ARC] Fix target register for call expanded from CALL_RVMARKER on Windows
https://reviews.llvm.org/D137939 [CGObjC] Open cleanup scope before SaveAndRestore CurrentFuncletPad and push CatchRetScope early
https://reviews.llvm.org/D137944 [ObjC][ARC] Teach the OptimizeSequences step of ObjCARCOpts about WinEH funclet tokens
3 years ago
Frederik Seiffert a357cb999c
tests: Test that we can throw and catch the same exception multiple times sequentially. (#188)
This originally came up as an issue with libc++abi support (#152), but is not specific to that ABI.

* Use the C++ runtime to check for uncaught C++ exceptions.

As discussed in #152, use the function defined in the Itanium C++ ABI to
check whether the thrown exception is the current caught C++ exception
and needs rethrowing via `__cxa_rethrow()`.

Co-authored-by: Niels Grewe <grewe@ocean-insights.com>
Co-authored-by: David Chisnall <gnustep@theravensnest.org>
4 years ago
Graham--M 14619f2905
Fix autorelease pool emptying when new references are added (#218)
* Add test for emptying autorelease pool

* Fix arc autorelease pool emptying when adding further references
When releasing a reference in the arc autorelease pool, it is
possible and anticipated that new references may added to the pool.
This fix addresses an edge case where releasing a reference in the
same pool page as the stop position can add more references which
cause the insertion of a new page and emptyPool() returns early
after emptying the new page.
4 years ago
Graham--M 73132a6c98
Avoid dangling weak references to deallocating objects. (#200)
The previous checks for a deallocating object with negative reference count did not work because:
    1. the sign bit has to be recreated as was happening in objc_delete_weak_refs()
    2. there was no distinction between a saturated count and a negative reference count

refcount_max now indicates when the refcount has saturated and should no longer be mutated.
An underflow to -1 still maps to refcount_mask, allowing us to detect when an object is supposed to be deallocated.
Neither objc_release_fast_no_destroy_np() nor objc_retain_fast_np() mutate the refcount when it is one of those values, so the comment in objc_delete_weak_refs() was adjusted.
5 years ago
David Chisnall 5a35fff19d Add test for checking whether a class supports fast ARC. 6 years ago
David Chisnall 78ff24516c Fix invoking missing superclass methods.
The lookup functions for the superclass paths were silently ignoring
missing methods, rather than calling the forwarding hook.

Fixes #153
6 years ago
David Chisnall 249acabbf4 Disable a test on Windows.
This is failing (and needs fixing) but it's unhelpful for CI to report
failures on Windows for PRs.
6 years ago
David Chisnall aa775cf835 Fix ObjC++ interop bug.
The reworked wrapping of C++ exceptions meant that we were missing a
dereference of the result of __cxa_begin_catch.

Add a test that triggers this issue.  It would have occurred in the
non-ARC version if we actually did anything with the exception, but
compiling it in ARC mode makes the compiler insert retain / autorelease
around the exception object to ensure that it remains live.
6 years ago
David Chisnall 2fb1194cec Add test case for weak ref issue.
This test now fails deterministically, which should make fixing it
easier.
6 years ago
Frederik Seiffert 5917514ac1 Added test for atomic ivars. 7 years ago
David Chisnall 945bbd760d Mark some tests as big.
Setting these tests to use 3 processors is weird, but it means that in
CI (where we do 4 tests in parallel), we won't ever run more than one of
these at a time (though we can run any other one test at the same time
as these).  This should fix the intermittent failure.
7 years ago
David Chisnall afee197c67 Rework some of the ivar offset calculations.
We now correctly handle ivars that overlap with the end of what the
compiler thinks is the start of the superclass and bitfields at the
start of a class.
7 years ago
David Chisnall 0da21d5064 Add some more Windows build tweaks.
This enables building on Windows with Ninja.
7 years ago
David Chisnall bab334acd4 Fix cmake configuration for Windows builds. 8 years ago
David Chisnall aa558900bd Fix an off-by-one error in the hash table.
When removing a hash entry that was in the cell assigned to its hash, we
would clear the first bit in the second maps.  If this entry was a
secondary value with the same hash, then this value became unreachable.

This very rarely showed up for two reasons.  First, most of the tables
are insert-only and so we never try to remove things from them.  Second,
it requires a particular sequence of inserts.  It occasionally caused
weak references to be susceptible to use after free.
8 years ago
David Chisnall 934cd13a7a Initial pass at Windows support.
All tests now pass with the new ABI on x86-64, with the new ABI.  Some
of the code is ugly and other platforms are probably broken.
8 years ago
David Chisnall c6aaf560c1 Fix dangling reference in weak ref code.
Another test added as a result of coverage analysis.
8 years ago
David Chisnall 29a35ab8ba Set profiling environment variable when tests are run.
This has no effect most of the time, but if the runtime is built with
llvm-cov support, then this will cause each test to emit a .profraw
file, which can be merged with:

$ llvm-profdata merge -sparse Test/*.profraw -o libobjc.profdata

This can then be used to generate coverage reports from the test suite
and find code paths that are not currently being tested.
8 years ago
David Chisnall 2934a98503 Support building without support for old ABIs. 8 years ago
David Chisnall b81df02b91 Merge branch 'master' into newabi
Simplify the setSubclass dtable updating mechanism.
8 years ago
David Chisnall bfe9475204 Add constant string test. 8 years ago
David Chisnall 5148d043d8 Add a test for weak import. 8 years ago
David Chisnall ab84589b5d Improve protocol method metadata.
Methods now include a selector and extended type encoding, rather than a
method name and lgacy type encoding.  Older ones are auto-upgraded.

Expose the extended type encoding via a function that JavaScriptCore
expects to exist.
8 years ago
David Chisnall 45d0b8e4c9 Add support for registering aliases.
Also add a test.
8 years ago
David Chisnall 33dc69387e Add test for category methods replacing class methods. 8 years ago
David Chisnall 8b6793aa52 Add a test for forward declared protocols.
Check that a protocol accessed by forward definition in one compilation
unit is the one defined in another compilation unit.
8 years ago
Dustin Howett 7fb4f5684f Merge remote-tracking branch 'upstream/master' into HEAD 8 years ago
Dustin Howett 14cb893509 Add a test for class_setSuperclass 8 years ago
Dustin Howett 45f6572379 Add a test for a0eec52 8 years ago
David Chisnall db5d8f7f64 Don't compile Test.m 122 times.
All tests now link one of a small number of .o files compiled from Test.m.
8 years ago
David Chisnall 91a1baae48 Fix errors made in merging. 8 years ago
David Chisnall 76e7d4b07f Merge branch 'master' into newabi 8 years ago
David Chisnall dc9b8313a4 Rework C++ library detection.
macOS ships with libc++abi, which doesn't provide the hooks required
for interop, so this was causing all of the tests to fail to link in
the Travis macOS test.  We're now correctly detecting that it won't
work on macOS and disabling those tests.
8 years ago
David Chisnall 760bb785aa Rename files.
minRep is not actually an informative name for a test case.
8 years ago
David Chisnall 8f03e62a84 Delete a lot of redundant code. 8 years ago
David Chisnall 1f2d35006b Make the ObjC++ interop test compile 8 years ago
David Lobron c036265ece Remove changes introduced accidentally because I was using an older
version of this file (sync with 0b5f66393a).
8 years ago
David Lobron 44d05e58a6 Minimal reproducing test case. This creates a test number 47 in the unit
test suite, which fails with an exception.  The exception reproduces the
bug.
8 years ago
David Chisnall 79395aebec Refactor test cmake to reduce copying and pasting.
Also ensures that multi-file tests are run in all combinations.
8 years ago
David Chisnall a54272c1ab Merge origin/master into newabi (using imerge) 8 years ago