Skip to content

Commit bfbc3a7

Browse files
committed
[Test] Run __swift5_entry test on all Apple platforms.
Previously, the test was limited to only x86_64 macos. Remove that limitation by introducing the appropriate cross-platform typedef for mach_header and signing the pointer before casting it to a function pointer.
1 parent 28cc144 commit bfbc3a7

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

test/IRGen/entrypoint-section-run.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %clang %s -isysroot %sdk -o %t/main
2+
// RUN: %target-clang %s -std=c++11 -isysroot %sdk -o %t/main
33
// RUN: %target-codesign %t/main
44
// RUN: %target-build-swift %S/Inputs/at-main-struct-simple.swift -O -parse-as-library -emit-library -o %t/libHowdy.dylib -module-name Howdy
5+
// RUN: %target-codesign %t/libHowdy.dylib
56
// RUN: %target-run %t/main %t/libHowdy.dylib | %FileCheck %s
67

7-
// REQUIRES: OS=macosx,CPU=x86_64
8+
// REQUIRES: VENDOR=apple
89
// REQUIRES: executable_test
910
// UNSUPPORTED: remote_run
1011

@@ -13,6 +14,13 @@
1314
#include <mach-o/getsect.h>
1415
#include <stdio.h>
1516
#include <string.h>
17+
#include <ptrauth.h>
18+
19+
#if __POINTER_WIDTH__ == 64
20+
using mach_header_platform = mach_header_64;
21+
#else
22+
using mach_header_platform = mach_header;
23+
#endif
1624

1725
int main(int argc, char *argv[]) {
1826
if (argc != 2) {
@@ -35,12 +43,19 @@ int main(int argc, char *argv[]) {
3543
continue;
3644
}
3745
auto *header =
38-
reinterpret_cast<const mach_header_64 *>(_dyld_get_image_header(index));
46+
reinterpret_cast<const mach_header_platform *>(_dyld_get_image_header(index));
3947
size_t size;
4048
auto *data = getsectiondata(header, "__TEXT", "__swift5_entry", &size);
4149
int32_t offset = *reinterpret_cast<int32_t *>(data);
4250
mainFunction = reinterpret_cast<MainFunction *>(
43-
reinterpret_cast<int64_t>(data) + offset);
51+
ptrauth_sign_unauthenticated(
52+
reinterpret_cast<void *>(
53+
reinterpret_cast<long>(data) + offset
54+
),
55+
ptrauth_key_function_pointer,
56+
ptrauth_function_pointer_type_discriminator(MainFunction)
57+
)
58+
);
4459

4560
break;
4661
}

0 commit comments

Comments
 (0)