-
Notifications
You must be signed in to change notification settings - Fork 120
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
Windows on ARM64: Support Visual Studio ABI sret mechanism for non-trivial data types #289
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ed4eff8
Add objc_msgSend_stret2_np
hmelder d87cbd5
Guard and Export objc_msgSend_stret2_np
hmelder 51b99f2
Fix moving of return type
hmelder abbcb9d
Make architecture detection more resilient
hmelder d36008c
Remove architecture hackery in CMake
hmelder 50c00de
Add objc_msgSend test for WoA64
hmelder 8caaf46
Wrap objc_msgSend_stret2_np in win32 ifdef
hmelder 21c2ac5
Rename objc_msgSend_stret2_np to objc_msgSend_stret2
hmelder 0a0ae52
Add doc comment for objc_msgSend_stret2
hmelder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
#include <string.h> | ||
#include <assert.h> | ||
#include "../objc/runtime.h" | ||
#include "../objc/hooks.h" | ||
|
||
// Pass and return for type size <= 8 bytes. | ||
struct S1 { | ||
int a[2]; | ||
}; | ||
|
||
// Pass and return hfa <= 8 bytes | ||
struct F1 { | ||
float a[2]; | ||
}; | ||
|
||
// Pass and return type size <= 16 bytes | ||
struct S2 { | ||
int a[4]; | ||
}; | ||
|
||
// Pass and return for type size > 16 bytes. | ||
struct S3 { | ||
int a[5]; | ||
}; | ||
|
||
// Pass and return aggregate (of size < 16 bytes) with non-trivial destructor. | ||
// Sret and inreg: Returned in x0 | ||
struct S4 { | ||
int a[3]; | ||
~S4(); | ||
}; | ||
S4::~S4() { | ||
} | ||
|
||
// Pass and return an object with a user-provided constructor (passed directly, | ||
// returned indirectly) | ||
struct S5 { | ||
S5(); | ||
int x; | ||
}; | ||
S5::S5() { | ||
x = 42; | ||
} | ||
|
||
Class TestCls; | ||
#ifdef __has_attribute | ||
#if __has_attribute(objc_root_class) | ||
__attribute__((objc_root_class)) | ||
#endif | ||
#endif | ||
@interface MsgTest { id isa; } @end | ||
@implementation MsgTest | ||
+ (S1) smallS1 { | ||
assert(TestCls == self); | ||
assert(strcmp("smallS1", sel_getName(_cmd)) == 0); | ||
|
||
S1 x; | ||
x.a[0] = 0; | ||
x.a[1] = 1; | ||
return x; | ||
|
||
} | ||
+ (F1) smallF1 { | ||
assert(TestCls == self); | ||
assert(strcmp("smallF1", sel_getName(_cmd)) == 0); | ||
|
||
F1 x; | ||
x.a[0] = 0.2f; | ||
x.a[1] = 0.5f; | ||
return x; | ||
} | ||
+ (S2) smallS2 { | ||
assert(TestCls == self); | ||
assert(strcmp("smallS2", sel_getName(_cmd)) == 0); | ||
|
||
S2 x; | ||
for (int i = 0; i < 4; i++) { | ||
x.a[i] = i; | ||
} | ||
return x; | ||
} | ||
+ (S3) stretS3 { | ||
assert(TestCls == self); | ||
assert(strcmp("stretS3", sel_getName(_cmd)) == 0); | ||
|
||
S3 x; | ||
for (int i = 0; i < 5; i++) { | ||
x.a[i] = i; | ||
} | ||
return x; | ||
} | ||
+ (S4) stretInRegS4 { | ||
assert(TestCls == self); | ||
assert(strcmp("stretInRegS4", sel_getName(_cmd)) == 0); | ||
|
||
S4 x; | ||
for (int i = 0; i < 3; i++) { | ||
x.a[i] = i; | ||
} | ||
return x; | ||
} | ||
+ (S5) stretInRegS5 { | ||
assert(TestCls == self); | ||
assert(strcmp("stretInRegS5", sel_getName(_cmd)) == 0); | ||
|
||
return S5(); | ||
} | ||
@end | ||
|
||
int main(int argc, char *argv[]) { | ||
#ifdef __GNUSTEP_MSGSEND__ | ||
TestCls = objc_getClass("MsgTest"); | ||
|
||
// Returned in x0 | ||
S1 ret = ((S1(*)(id, SEL))objc_msgSend)(TestCls, @selector(smallS1)); | ||
assert(ret.a[0] == 0); | ||
assert(ret.a[1] == 1); | ||
|
||
F1 retF1 = ((F1(*)(id, SEL))objc_msgSend)(TestCls, @selector(smallF1)); | ||
assert(retF1.a[0] == 0.2f); | ||
assert(retF1.a[1] == 0.5f); | ||
|
||
// Returned in x0 and x1 | ||
S2 ret2 = ((S2(*)(id, SEL))objc_msgSend)(TestCls, @selector(smallS2)); | ||
for (int i = 0; i < 4; i++) { | ||
assert(ret2.a[i] == i); | ||
} | ||
|
||
// Indirect result register x8 used | ||
S3 ret3 = ((S3(*)(id, SEL))objc_msgSend_stret)(TestCls, @selector(stretS3)); | ||
for (int i = 0; i < 5; i++) { | ||
assert(ret3.a[i] == i); | ||
} | ||
|
||
// Stret with inreg. Returned in x0. | ||
S4 ret4 = ((S4(*)(id, SEL))objc_msgSend_stret2)(TestCls, @selector(stretInRegS4)); | ||
for (int i = 0; i < 3; i++) { | ||
assert(ret4.a[i] == i); | ||
} | ||
|
||
// Stret with inreg. Returned in x0. | ||
S5 ret5 = ((S5(*)(id, SEL))objc_msgSend_stret2)(TestCls, @selector(stretInRegS5)); | ||
assert(ret5.x == 42); | ||
|
||
return 0; | ||
#endif // __GNUSTEP_MSGSEND__ | ||
return 77; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can’t remember why this was needed, are you sure it no longer is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is still an issue when using CMake x86_64 on Windows on ARM64, as CMake reports AMD64 while using an ARM64 compiler.
The problem with this hack is that it searches for any occurrence in the output of the compiler. Other paths (like
/c/Program Files/python3-arm/
) are erroneously selected.I think we should stick to the standard
CMAKE_SYSTEM_PROCESSOR
variable, but put a warning inREADME.md
orINSTALL
. CMake is not willing to fix this broken behaviour on Windows.