Skip to content

Commit c410a25

Browse files
committed
deps: add missing static linking targets for libffi
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 130398a commit c410a25

10 files changed

Lines changed: 263 additions & 71 deletions

File tree

configure.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,17 +2310,20 @@ def without_sqlite_error(option):
23102310
configure_library('sqlite', o, pkgname='sqlite3')
23112311

23122312
def bundled_ffi_supported(os_name, target_arch):
2313-
supported = {
2314-
'freebsd': {'arm', 'arm64', 'x64'},
2315-
'linux': {'arm', 'arm64', 'x64'},
2316-
'mac': {'arm64', 'x64'},
2317-
'win': {'arm64', 'x64'},
2318-
}
2319-
23202313
if target_arch == 'x86':
23212314
target_arch = 'ia32'
23222315

2323-
return target_arch in supported.get(os_name, set())
2316+
if target_arch in {'arm', 'arm64', 'ia32', 'x64', 'x86_64',
2317+
'riscv64', 'loong64'}:
2318+
return True
2319+
2320+
if target_arch in {'mips', 'mipsel', 'mips64el'}:
2321+
return os_name in {'freebsd', 'linux', 'openbsd'}
2322+
2323+
if target_arch == 'ppc64':
2324+
return os_name in {'aix', 'freebsd', 'linux', 'mac', 'openbsd'}
2325+
2326+
return False
23242327

23252328
def configure_ffi(o):
23262329
use_ffi = not options.without_ffi

deps/libffi/generate-headers.py

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,63 @@
1010
LIBFFI_VERSION = '3.5.2'
1111
LIBFFI_VERSION_NUMBER = '30502'
1212

13-
TARGETS = {
14-
('freebsd', 'arm'): ('ARM', 'arm'),
15-
('freebsd', 'arm64'): ('AARCH64', 'aarch64'),
16-
('freebsd', 'x64'): ('X86_64', 'x86'),
17-
('linux', 'arm'): ('ARM', 'arm'),
18-
('linux', 'arm64'): ('AARCH64', 'aarch64'),
19-
('linux', 'x64'): ('X86_64', 'x86'),
20-
('mac', 'arm64'): ('AARCH64', 'aarch64'),
21-
('mac', 'x64'): ('X86_64', 'x86'),
22-
('win', 'arm'): ('ARM_WIN32', 'arm'),
23-
('win', 'arm64'): ('ARM_WIN64', 'aarch64'),
24-
('win', 'x64'): ('X86_WIN64', 'x86'),
25-
}
13+
def normalize_arch(target_arch):
14+
aliases = {
15+
'x86': 'ia32',
16+
'x86_64': 'x64',
17+
'arm64': 'arm64',
18+
'aarch64': 'arm64',
19+
}
20+
return aliases.get(target_arch, target_arch)
2621

2722

2823
def get_target(os_name, target_arch):
29-
try:
30-
return TARGETS[(os_name, target_arch)]
31-
except KeyError as exc:
32-
supported = ', '.join(
33-
f'{os_name}/{arch}' for os_name, arch in sorted(TARGETS))
34-
raise ValueError(
35-
f'Unsupported libffi target {os_name}/{target_arch}. '
36-
f'Supported targets: {supported}.') from exc
24+
target_arch = normalize_arch(target_arch)
25+
26+
if target_arch == 'arm':
27+
return ('ARM_WIN32' if os_name == 'win' else 'ARM', 'arm')
28+
29+
if target_arch == 'arm64':
30+
return ('ARM_WIN64' if os_name == 'win' else 'AARCH64', 'aarch64')
31+
32+
if target_arch == 'ia32':
33+
if os_name in ('freebsd', 'openbsd'):
34+
return ('X86_FREEBSD', 'x86')
35+
if os_name in ('ios', 'mac'):
36+
return ('X86_DARWIN', 'x86')
37+
if os_name == 'win':
38+
return ('X86_WIN32', 'x86')
39+
return ('X86', 'x86')
40+
41+
if target_arch == 'x64':
42+
return ('X86_WIN64' if os_name == 'win' else 'X86_64', 'x86')
43+
44+
if target_arch == 'riscv64':
45+
return ('RISCV', 'riscv')
46+
47+
if target_arch == 'loong64':
48+
return ('LOONGARCH64', 'loongarch64')
49+
50+
if target_arch in ('mips', 'mipsel', 'mips64el'):
51+
if os_name in ('freebsd', 'linux', 'openbsd'):
52+
return ('MIPS', 'mips')
53+
54+
if target_arch == 'ppc64':
55+
if os_name == 'aix':
56+
return ('POWERPC_AIX', 'powerpc')
57+
if os_name == 'mac':
58+
return ('POWERPC_DARWIN', 'powerpc')
59+
if os_name in ('freebsd', 'openbsd'):
60+
return ('POWERPC_FREEBSD', 'powerpc')
61+
if os_name == 'linux':
62+
return ('POWERPC', 'powerpc')
63+
64+
raise ValueError(f'Unsupported libffi target {os_name}/{target_arch}.')
3765

3866

3967
def has_long_double(os_name, target_arch):
68+
target_arch = normalize_arch(target_arch)
69+
4070
if os_name == 'win':
4171
return '0'
4272

@@ -50,6 +80,7 @@ def has_long_double(os_name, target_arch):
5080

5181

5282
def uses_exec_trampoline_table(os_name, target_arch):
83+
target_arch = normalize_arch(target_arch)
5384
return os_name == 'mac' and target_arch in ('arm', 'arm64')
5485

5586

@@ -72,6 +103,7 @@ def render_ffi_header(base_dir, os_name, target_arch, target):
72103

73104

74105
def render_fficonfig(os_name, target_arch):
106+
target_arch = normalize_arch(target_arch)
75107
lines = [
76108
'/* Auto-generated by generate-headers.py. */',
77109
'#ifndef LIBFFI_FFICONFIG_H_',
@@ -94,15 +126,15 @@ def render_fficonfig(os_name, target_arch):
94126
'#define EH_FRAME_FLAGS "a"',
95127
])
96128

97-
if target_arch in ('x64', 'x86') and os_name != 'win':
129+
if target_arch in ('ia32', 'x64') and os_name != 'win':
98130
lines.append('#define HAVE_AS_X86_PCREL 1')
99131

100132
if uses_exec_trampoline_table(os_name, target_arch):
101133
lines.append('#define FFI_EXEC_TRAMPOLINE_TABLE 1')
102-
elif os_name in ('freebsd', 'mac'):
134+
elif os_name in ('freebsd', 'mac', 'openbsd'):
103135
lines.append('#define FFI_MMAP_EXEC_WRIT 1')
104136

105-
if os_name == 'linux':
137+
if os_name != 'win':
106138
lines.extend([
107139
'#define HAVE_DLFCN_H 1',
108140
'#define HAVE_MMAP 1',
@@ -111,15 +143,10 @@ def render_fficonfig(os_name, target_arch):
111143
'#define HAVE_SYS_MMAN_H 1',
112144
'#define HAVE_UNISTD_H 1',
113145
])
114-
elif os_name in ('freebsd', 'mac'):
146+
147+
if os_name in ('freebsd', 'ios', 'mac', 'openbsd'):
115148
lines.extend([
116-
'#define HAVE_DLFCN_H 1',
117-
'#define HAVE_MMAP 1',
118-
'#define HAVE_MMAP_ANON 1',
119149
'#define HAVE_MMAP_DEV_ZERO 1',
120-
'#define HAVE_MMAP_FILE 1',
121-
'#define HAVE_SYS_MMAN_H 1',
122-
'#define HAVE_UNISTD_H 1',
123150
])
124151

125152
if os_name == 'mac' and target_arch == 'arm64':
@@ -204,12 +231,19 @@ def detect_target_arch():
204231
'x86_64': 'x64',
205232
'x64': 'x64',
206233
'win32': 'x64',
207-
'i386': 'x86',
208-
'i686': 'x86',
209-
'x86': 'x86',
234+
'i386': 'ia32',
235+
'i686': 'ia32',
236+
'ia32': 'ia32',
237+
'x86': 'ia32',
210238
'arm64': 'arm64',
211239
'aarch64': 'arm64',
212240
'arm': 'arm',
241+
'riscv64': 'riscv64',
242+
'loong64': 'loong64',
243+
'ppc64': 'ppc64',
244+
'mips': 'mips',
245+
'mipsel': 'mipsel',
246+
'mips64el': 'mips64el',
213247
}
214248

215249
for candidate in candidates:

0 commit comments

Comments
 (0)