-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbuilding-linux-on-macos.patch
More file actions
90 lines (78 loc) · 2.77 KB
/
Copy pathbuilding-linux-on-macos.patch
File metadata and controls
90 lines (78 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
From 774c044b810b044e444f2ce854eddff8608bf017 Mon Sep 17 00:00:00 2001
From: Seiya Nuta <nuta@seiya.me>
Date: Wed, 2 Jul 2025 12:55:09 +0900
Subject: [PATCH] Build Linux on macOS
Note: This patch is GPLv2 licensed.
This patch enables building Linux on macOS 15.5 (Sequoia) natively using Homebrew packages:
brew install make llvm lld findutils gnu-sed libelf
export PATH="$(brew --prefix findutils)/libexec/gnubin:$(brew --prefix gnu-sed)/libexec/gnubin:$(brew --prefix llvm)/bin:$PATH"
export ARCH=riscv LLVM=1 HOSTCFLAGS="-Iscripts/macos-include -I $(brew --prefix libelf)/include"
gmake Image -j$(nproc)
Interestingly, changes are only applied to build scripts, not kernel source code:
- Add missing byteswap.h.
- Add missing elf.h - libelf is installed via Homebrew, however, it's too old
and needs some definitions from newer elf.h headers.
- Work around uuid_t definition issue in file2alias.c [1].
Tested with v6.12.34 and v6.1.141, riscv and arm64 allnoconfig builds.
---
scripts/macos-include/byteswap.h | 4 ++++
scripts/macos-include/elf.h | 24 ++++++++++++++++++++++++
scripts/mod/file2alias.c | 3 +++
3 files changed, 31 insertions(+)
create mode 100644 scripts/macos-include/byteswap.h
create mode 100644 scripts/macos-include/elf.h
diff --git a/scripts/macos-include/byteswap.h b/scripts/macos-include/byteswap.h
new file mode 100644
index 000000000..fd97ed5e1
--- /dev/null
+++ b/scripts/macos-include/byteswap.h
@@ -0,0 +1,4 @@
+#pragma once
+#define bswap_16 __builtin_bswap16
+#define bswap_32 __builtin_bswap32
+#define bswap_64 __builtin_bswap64
diff --git a/scripts/macos-include/elf.h b/scripts/macos-include/elf.h
new file mode 100644
index 000000000..5d42ed858
--- /dev/null
+++ b/scripts/macos-include/elf.h
@@ -0,0 +1,24 @@
+#pragma once
+#include <libelf/gelf.h>
+
+#define STT_SPARC_REGISTER 3
+#define R_386_32 1
+#define R_386_PC32 2
+#define R_MIPS_HI16 5
+#define R_MIPS_LO16 6
+#define R_MIPS_26 4
+#define R_MIPS_32 2
+#define R_ARM_ABS32 2
+#define R_ARM_REL32 3
+#define R_ARM_PC24 1
+#define R_ARM_CALL 28
+#define R_ARM_JUMP24 29
+#define R_ARM_THM_JUMP24 30
+#define R_ARM_THM_PC22 10
+#define R_ARM_MOVW_ABS_NC 43
+#define R_ARM_MOVT_ABS 44
+#define R_ARM_THM_MOVW_ABS_NC 47
+#define R_ARM_THM_MOVT_ABS 48
+#define R_ARM_THM_JUMP19 51
+#define R_AARCH64_ABS64 257
+#define R_AARCH64_PREL64 260
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 721e0e9f1..fd043c1e9 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -10,7 +10,10 @@
* of the GNU General Public License, incorporated herein by reference.
*/
+#define _UUID_T
+#define uuid_t int
#include "modpost.h"
+#undef uuid_t
#include "devicetable-offsets.h"
/* We use the ELF typedefs for kernel_ulong_t but bite the bullet and
--
2.46.0