Skip to content

Commit 1244799

Browse files
committed
fix: 最后一个厂商 SDK 的 include —— <pthread.h> 在这个系统上会赢过图里的那份
…/MacOSX.sdk/usr/include/mach/mach_time.h:61:1: error: a type specifier is required for all declarations (× 19) 在**这个系统上**构建本包、而目标侧来自依赖图时,SDK 的 <pthread.h> 赢过了图里 C 库的那份,并拉进一个自身前提没有到位的 Mach 头。从 Linux 宿主出发的同一次构建取到 的是图里那份,一声不吭 —— 所以这是宿主差异,只在这里才现形。 ⭐ 而本包的其余部分早就不这样做:pthread_create_from_mach_thread 一直是自己声明的 (因为没有头声明它)。openkal-linux 写系统调用号,openkal-opensbi 写 SBI 标识, openkal-windows 写 Win32 声明 —— 这三个普通名字是最后一处例外。 ⭐ pthread_t 在两个 C 库上都是指针(musl 的 struct __pthread*、这个系统的 struct _opaque_pthread_t*),所以 void* 在 ABI 这一层是同一个参数,而 extern "C" 匹配的正是这一层。值在两种情况下都以整数存放。 本机复验:从 Linux 交叉到 aarch64-macos 仍然产出 Mach-O。
1 parent c4dd442 commit 1244799

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

src/task.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,39 @@
2222
// and the default --- there is no such constraint and the ordinary names are
2323
// used, which also avoids the cost the other arrangement pays.
2424

25-
#ifndef OKM_STANDALONE
26-
#include <pthread.h>
27-
#endif
28-
25+
// ⚠️ DECLARED, NOT INCLUDED — AND THAT IS THE SAME RULE THE BRANCH BELOW
26+
// ALREADY FOLLOWS.
27+
//
28+
// `pthread_create_from_mach_thread` has always been declared here rather than
29+
// taken from a header, because no header declares it. The three ordinary names
30+
// were taken from `<pthread.h>`, and that header is this system's SDK — the one
31+
// thing every other implementation in this ecosystem avoids: openkal-linux
32+
// writes the system-call numbers, openkal-opensbi the SBI identifiers,
33+
// openkal-windows the Win32 declarations.
34+
//
35+
// ⚠️ Measured 2026-08-23, building this package ON this system with the target
36+
// side coming from the graph:
37+
//
38+
// …/MacOSX.sdk/usr/include/mach/mach_time.h:61:1:
39+
// error: a type specifier is required for all declarations (× 19)
40+
//
41+
// The SDK's `<pthread.h>` won the search over the C library's in the graph, and
42+
// pulled in a Mach header that its own prerequisites were not there for. On a
43+
// Linux host the same build had taken the graph's copy and said nothing, which
44+
// is why the difference is a HOST difference and shows up only here.
45+
//
46+
// ⭐ `pthread_t` IS A POINTER ON BOTH C LIBRARIES — `struct __pthread*` in musl
47+
// and `struct _opaque_pthread_t*` on this system — so `void*` is the same
48+
// argument at the ABI, which is the level `extern "C"` matches at. The value is
49+
// stored as an integer below in either case.
2950
extern "C" {
3051
#ifdef OKM_STANDALONE
3152
int pthread_create_from_mach_thread(void** thread, const void* attr,
3253
void* (*start)(void*), void* arg);
54+
#else
55+
int pthread_create(void** thread, const void* attr,
56+
void* (*start)(void*), void* arg);
57+
int pthread_join(void* thread, void** value);
3358
#endif
3459
}
3560

@@ -83,7 +108,7 @@ int kal_task_start(void (*entry)(void*), void* arg, kal_task* out) {
83108
void* thread = nullptr;
84109
const int rc = pthread_create_from_mach_thread(&thread, nullptr, run, c);
85110
#else
86-
pthread_t id{};
111+
void* id = nullptr;
87112
const int rc = ::pthread_create(&id, nullptr, run, c);
88113
if (rc == 0) c->thread = static_cast<unsigned long>(reinterpret_cast<okm_uptr>(id));
89114
#endif
@@ -105,7 +130,8 @@ int kal_task_join(kal_task h) {
105130
reinterpret_cast<okm_long>(const_cast<okm_u32*>(&c->finished)), 0, 0);
106131
}
107132
#else
108-
const int rc = ::pthread_join(reinterpret_cast<pthread_t>(c->thread), nullptr);
133+
const int rc = ::pthread_join(reinterpret_cast<void*>(
134+
static_cast<okm_uptr>(c->thread)), nullptr);
109135
if (rc != 0) return translate_posix(rc);
110136
#endif
111137
kal_free(c, sizeof(context), alignof(context));

0 commit comments

Comments
 (0)