Skip to content

Commit 7681e87

Browse files
committed
[GR-62790] Multitarget changes for Espresso and toolchain detection for BOOTSTRAP_GRAALVM
PullRequest: graal/21258
2 parents b2fcb9b + 34b8412 commit 7681e87

File tree

9 files changed

+170
-58
lines changed

9 files changed

+170
-58
lines changed

espresso-compiler-stub/mx.espresso-compiler-stub/mx_espresso_compiler_stub.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from mx_espresso import _espresso_stability, _has_native_espresso_standalone, _send_sigquit, get_java_home_dep, _jdk_lib_dir, jvm_standalone_with_llvm
3131
from mx_sdk_vm_ng import _find_native_image_command, ThinLauncherProject # pylint: disable=unused-import
32-
from mx_sdk_vm_impl import get_final_graalvm_distribution, has_component
32+
from mx_sdk_vm_impl import get_final_graalvm_distribution, has_component, graalvm_skip_archive
3333

3434
_suite = mx.suite('espresso-compiler-stub')
3535

@@ -57,14 +57,14 @@ def create_ni_standalone(base_standalone_name, register_distribution):
5757
layout = deepcopy(base_standalone.layout)
5858
if '_NATIVE_' in base_standalone_name:
5959
# avoid dependency on project, copy from base standalone
60-
idx = layout['<jdk_lib_dir>/truffle/'].index('dependency:espresso:com.oracle.truffle.espresso.mokapot/<lib:jvm>')
60+
idx = layout['<jdk_lib_dir>/truffle/'].index('dependency:espresso:com.oracle.truffle.espresso.mokapot/*/<multitarget_libc_selection>/<lib:jvm>')
6161
layout['<jdk_lib_dir>/truffle/'][idx] = f'dependency:espresso:{base_standalone_name}/{_jdk_lib_dir()}/truffle/<lib:jvm>'
6262
assert len(layout['languages/java/lib/']) == 1
6363
layout['languages/java/lib/'] = [
6464
f'dependency:espresso:{base_standalone_name}/languages/java/lib/<lib:javavm>'
6565
]
6666
else:
67-
idx = layout['languages/java/lib/'].index('dependency:espresso:com.oracle.truffle.espresso.mokapot/<lib:jvm>')
67+
idx = layout['languages/java/lib/'].index('dependency:espresso:com.oracle.truffle.espresso.mokapot/*/<multitarget_libc_selection>/<lib:jvm>')
6868
layout['languages/java/lib/'][idx] = f'dependency:espresso:{base_standalone_name}/languages/java/lib/<lib:jvm>'
6969
idx = layout['bin/'].index('dependency:espresso:espresso')
7070
del layout['bin/'][idx]
@@ -80,6 +80,9 @@ def create_ni_standalone(base_standalone_name, register_distribution):
8080
# ESPRESSO_JAVA_HOME has native-image, keep that
8181
pass
8282
elif has_component('ni') and espresso_java_home.java_home == mx_sdk_vm.base_jdk().home:
83+
if graalvm_skip_archive():
84+
mx.abort("Cannot build NI standalones with GRAALVM_SKIP_ARCHIVE enabled")
85+
8386
# substratevm is available and ESPRESSO_JAVA_HOME is JAVA_HOME, use GraalVM
8487
layout['./'][0]['source_type'] = 'extracted-dependency'
8588
layout['./'][0]['dependency'] = get_final_graalvm_distribution().qualifiedName()

espresso/mx.espresso/mx_espresso.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ def javavm_build_args():
115115
result += mx_sdk_vm_impl.svm_experimental_options(['-H:+DumpThreadStacksOnSignal', '-H:+CopyLanguageResources'])
116116
if mx_sdk_vm_ng.get_bootstrap_graalvm_version() >= mx.VersionSpec("25.0"):
117117
result.append('-H:-IncludeLanguageResources')
118-
if mx.is_linux() and mx.get_os_variant() != "musl":
118+
if mx.is_linux() and (mx.get_os_variant() != "musl" and mx_subst.path_substitutions.substitute("<multitarget_libc_selection>") == "glibc"):
119+
# Currently only enabled if the native image build runs on glibc and also targets glibc.
120+
# In practice it's enough that host and target are matching, but we do not get this info out of mx.
119121
result += [
120122
'-Dpolyglot.image-build-time.PreinitializeContexts=java',
121123
'-Dpolyglot.image-build-time.PreinitializeContextsWithNative=true',

espresso/mx.espresso/suite.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,27 @@
248248
"windows": {
249249
"<others>": {
250250
"cflags": ["-g", "-O3", "-Wall"],
251+
"multitarget": {
252+
"libc": ["default"],
253+
},
251254
},
252255
},
253256
"linux-musl": {
254257
"<others>": {
255258
"cflags": ["-Wall", "-Werror", "-Wno-error=cpp"],
256-
"toolchain": "sulong:SULONG_BOOTSTRAP_TOOLCHAIN",
259+
"multitarget": {
260+
"libc": ["musl", "default"],
261+
"compiler": ["sulong-bitcode", "host", "*"]
262+
},
257263
},
258264
},
259265
"<others>": {
260266
"<others>": {
261267
"cflags": ["-Wall", "-Werror"],
262-
"toolchain": "sulong:SULONG_BOOTSTRAP_TOOLCHAIN",
268+
"multitarget": {
269+
"libc": ["glibc", "musl", "default"],
270+
"compiler": ["sulong-bitcode", "host", "*"]
271+
},
263272
},
264273
},
265274
},
@@ -312,7 +321,9 @@
312321
"-Wl,-current_version,1.0.0",
313322
"-Wl,-compatibility_version,1.0.0"
314323
],
315-
"toolchain": "sulong:SULONG_BOOTSTRAP_TOOLCHAIN",
324+
"multitarget": {
325+
"compiler": ["sulong-bitcode", "host", "*"]
326+
},
316327
},
317328
},
318329
"linux": {
@@ -321,10 +332,11 @@
321332
"ldflags": [
322333
"-Wl,-soname,libjvm.so",
323334
"-Wl,--version-script,<path:espresso:com.oracle.truffle.espresso.mokapot>/mapfile-vers",
324-
# newer LLVM versions default to --no-undefined-version
325-
"-Wl,--undefined-version",
326335
],
327-
"toolchain": "sulong:SULONG_BOOTSTRAP_TOOLCHAIN",
336+
"multitarget": {
337+
"libc": ["glibc", "musl", "default"],
338+
"compiler": ["sulong-bitcode", "host", "*"]
339+
},
328340
},
329341
},
330342
"linux-musl": {
@@ -333,15 +345,19 @@
333345
"ldflags": [
334346
"-Wl,-soname,libjvm.so",
335347
"-Wl,--version-script,<path:espresso:com.oracle.truffle.espresso.mokapot>/mapfile-vers",
336-
# newer LLVM versions default to --no-undefined-version
337-
"-Wl,--undefined-version",
338348
],
339-
"toolchain": "sulong:SULONG_BOOTSTRAP_TOOLCHAIN",
349+
"multitarget": {
350+
"libc": ["musl", "default"],
351+
"compiler": ["sulong-bitcode", "host", "*"]
352+
},
340353
},
341354
},
342355
"windows": {
343356
"<others>": {
344357
"cflags": ["-g", "-O3", "-Wall"],
358+
"multitarget": {
359+
"libc": ["default"],
360+
},
345361
},
346362
}
347363
},
@@ -562,7 +578,7 @@
562578
"dependency:espresso:ESPRESSO_STANDALONE_COMMON/*",
563579
],
564580
"<jdk_lib_dir>/truffle/": [
565-
"dependency:espresso:com.oracle.truffle.espresso.mokapot/<lib:jvm>",
581+
"dependency:espresso:com.oracle.truffle.espresso.mokapot/*/<multitarget_libc_selection>/<lib:jvm>",
566582
],
567583
"lib/jvm.cfg": {
568584
"source_type": "string",
@@ -625,7 +641,7 @@
625641
],
626642
"languages/java/lib/": [
627643
# Copy of libjvm.so, accessible by Sulong via the default Truffle file system.
628-
"dependency:espresso:com.oracle.truffle.espresso.mokapot/<lib:jvm>",
644+
"dependency:espresso:com.oracle.truffle.espresso.mokapot/*/<multitarget_libc_selection>/<lib:jvm>",
629645
],
630646
"languages/java/": [
631647
{
@@ -710,7 +726,7 @@
710726
"layout": {
711727
"META-INF/resources/java/espresso-libs/<os>/<arch>/lib/": [
712728
# Copy of libjvm.so, accessible by Sulong via the default Truffle file system.
713-
"dependency:espresso:com.oracle.truffle.espresso.mokapot/<lib:jvm>",
729+
"dependency:espresso:com.oracle.truffle.espresso.mokapot/*/<multitarget_libc_selection>/<lib:jvm>",
714730
],
715731
"META-INF/resources/java/espresso-libs/<os>/<arch>/": "dependency:espresso:ESPRESSO_SUPPORT/*",
716732
},
@@ -755,7 +771,7 @@
755771
"platforms": "local",
756772
"layout": {
757773
"lib/": [
758-
"dependency:espresso:com.oracle.truffle.espresso.native/<lib:nespresso>",
774+
"dependency:espresso:com.oracle.truffle.espresso.native/*/<multitarget_libc_selection>/<lib:nespresso>",
759775
"dependency:espresso:ESPRESSO_POLYGLOT/*",
760776
"dependency:espresso:HOTSWAP/*",
761777
"dependency:espresso:CONTINUATIONS/*",
@@ -782,7 +798,7 @@
782798
"./": "dependency:espresso:ESPRESSO_SUPPORT/*",
783799
"lib/": [
784800
# Copy of libjvm.so, accessible by Sulong via the default Truffle file system.
785-
"dependency:espresso:com.oracle.truffle.espresso.mokapot/<lib:jvm>",
801+
"dependency:espresso:com.oracle.truffle.espresso.mokapot/*/<multitarget_libc_selection>/<lib:jvm>",
786802
]
787803
},
788804
"maven": False,
@@ -794,7 +810,7 @@
794810
"platformDependent": True,
795811
"layout": {
796812
"truffle/": [
797-
"dependency:espresso:com.oracle.truffle.espresso.mokapot/<lib:jvm>",
813+
"dependency:espresso:com.oracle.truffle.espresso.mokapot/*/<multitarget_libc_selection>/<lib:jvm>",
798814
],
799815
},
800816
"maven": False,

espresso/src/com.oracle.truffle.espresso.mokapot/mapfile-vers

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,6 @@ SUNWprivate_1.1 {
340340
JVM_SetStackWalkContinuation;
341341
JVM_ReportFinalizationComplete;
342342
JVM_IsFinalizationEnabled;
343-
JVM_VirtualThreadMountBegin;
344-
JVM_VirtualThreadMountEnd;
345-
JVM_VirtualThreadUnmountBegin;
346-
JVM_VirtualThreadUnmountEnd;
347343

348344
# JDK 20
349345
JVM_VirtualThreadHideFrames;
@@ -378,19 +374,9 @@ SUNWprivate_1.1 {
378374

379375
# miscellaneous functions
380376
jio_fprintf;
381-
jio_printf;
382377
jio_snprintf;
383378
jio_vfprintf;
384379
jio_vsnprintf;
385-
fork1;
386-
numa_warn;
387-
numa_error;
388-
389-
# Needed because there is no JVM interface for this.
390-
sysThreadAvailableStackWithSlack;
391-
392-
# This is for Forte Analyzer profiling support.
393-
AsyncGetCallTrace;
394380

395381
# INSERT VTABLE SYMBOLS HERE
396382

espresso/src/com.oracle.truffle.espresso.mokapot/src/os_posix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <unistd.h>
3030
#include <sys/socket.h>
3131
#include <sys/ioctl.h>
32-
#include <sys/poll.h>
32+
#include <poll.h>
3333
#include <sys/time.h>
3434
#include <dlfcn.h>
3535
#include <stdatomic.h>

sdk/mx.sdk/mx_sdk_vm_impl.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,6 +3544,17 @@ def _image_profiles(image):
35443544
profiles += arg[prefix_len:].split(',')
35453545
return profiles
35463546

3547+
def _multitarget_libc_selection():
3548+
full_spec = mx_native.TargetSelection.get_selection()
3549+
if len(full_spec) > 1:
3550+
mx.logv(f"Multiple targets selected: {full_spec} (first one wins)")
3551+
full_spec = full_spec[0]
3552+
ret = full_spec.libc
3553+
if full_spec.variant is not None:
3554+
ret = f"{ret}-{full_spec.variant}"
3555+
return ret
3556+
3557+
mx_subst.results_substitutions.register_no_arg('multitarget_libc_selection', _multitarget_libc_selection)
35473558

35483559
def _no_licenses():
35493560
return mx.get_opts().no_licenses or _env_var_to_bool('NO_LICENSES')

sdk/mx.sdk/mx_sdk_vm_ng.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,60 @@ def mx_register_dynamic_suite_constituents(register_project, register_distributi
868868
register_distribution(mx_pomdistribution.POMDistribution(_suite, "TOOLS_FOR_STANDALONE", [], tools_dists, None, maven=False))
869869

870870

871+
# register toolchains shipped by BOOTSTRAP_GRAALVM, if any
872+
if _external_bootstrap_graalvm:
873+
toolchain_dir = join(_external_bootstrap_graalvm, "lib", "toolchains")
874+
if exists(toolchain_dir):
875+
for e in listdir(toolchain_dir):
876+
if not (e == "musl" or e.startswith("musl-")):
877+
# currently only variants of musl are detected
878+
continue
879+
880+
binpath = join(toolchain_dir, e, "bin")
881+
ninja_layout = {
882+
"toolchain.ninja" : {
883+
"source_type": "string",
884+
"value": f'''
885+
include <ninja-toolchain:GCC_NINJA_TOOLCHAIN>
886+
CC={binpath}/clang
887+
CXX={binpath}/clang++
888+
AR={binpath}/ar
889+
'''
890+
},
891+
}
892+
ninja_dependencies = ['mx:GCC_NINJA_TOOLCHAIN']
893+
ninja_native_toolchain = {
894+
'kind': 'ninja',
895+
'compiler': 'llvm',
896+
'target': {
897+
'os': mx.get_os(),
898+
'arch': mx.get_arch(),
899+
'libc': 'musl',
900+
'variant': e.split('-', 1)[1] if '-' in e else None
901+
}
902+
}
903+
ninja_name = 'BOOTSTRAP_' + e.upper().replace('-', '_') + '_NINJA_TOOLCHAIN'
904+
register_distribution(mx.LayoutDirDistribution(_suite, ninja_name, ninja_dependencies, ninja_layout, path=None, theLicense=None, platformDependent=True, native_toolchain=ninja_native_toolchain, native=True, maven=False))
905+
906+
cmake_layout = {
907+
"toolchain.cmake" : {
908+
"source_type": "string",
909+
"value": f'''
910+
set(CMAKE_C_COMPILER {binpath}/clang)
911+
set(CMAKE_CXX_COMPILER {binpath}/clang++)
912+
set(CMAKE_AR {binpath}/ar)
913+
'''
914+
},
915+
}
916+
cmake_dependencies = []
917+
cmake_native_toolchain = dict(**ninja_native_toolchain)
918+
cmake_native_toolchain['kind'] = 'cmake'
919+
cmake_name = 'BOOTSTRAP_' + e.upper().replace('-', '_') + '_CMAKE_TOOLCHAIN'
920+
register_distribution(mx.LayoutDirDistribution(_suite, cmake_name, cmake_dependencies, cmake_layout, path=None, theLicense=None, platformDependent=True, native_toolchain=cmake_native_toolchain, native=True, maven=False))
921+
922+
mx.logv(f'Registered toolchain for {e} from bootstrap GraalVM {_external_bootstrap_graalvm}')
923+
924+
871925
class DynamicPOMDistribution(mx_pomdistribution.POMDistribution):
872926
def __init__(self, suite, name, deps, excl, platformDependent, theLicense, **kw_args):
873927
dist_deps = _pop_list(kw_args, 'distDependencies', suite, name)

sulong/mx.sulong/suite.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,66 @@
22592259
"license": "BSD-new",
22602260
},
22612261

2262+
"SULONG_NINJA_TOOLCHAIN": {
2263+
"native" : True,
2264+
"platformDependent" : True,
2265+
"native_toolchain": {
2266+
"kind": "ninja",
2267+
"compiler": "sulong-bitcode",
2268+
# empty, so it defaults everything to host properties
2269+
"target": {},
2270+
},
2271+
2272+
"os_arch": {
2273+
"windows": {
2274+
"<others>": {
2275+
"layout": {
2276+
"toolchain.ninja" : {
2277+
"source_type": "string",
2278+
"value": '''
2279+
include <ninja-toolchain:MSVC_NINJA_TOOLCHAIN>
2280+
CL=<path:SULONG_BOOTSTRAP_TOOLCHAIN>\\bin\\<cmd:clang-cl>
2281+
LINK=<path:SULONG_BOOTSTRAP_TOOLCHAIN>\\bin\\<cmd:lld-link>
2282+
LIB=<path:SULONG_BOOTSTRAP_TOOLCHAIN>\\bin\\<cmd:llvm-lib>
2283+
ML=<path:SULONG_BOOTSTRAP_TOOLCHAIN>\\bin\\<cmd:llvm-ml>
2284+
CFLAGS=
2285+
CXXFLAGS=
2286+
LDFLAGS=
2287+
'''
2288+
},
2289+
},
2290+
"dependencies": [
2291+
"SULONG_BOOTSTRAP_TOOLCHAIN",
2292+
"mx:MSVC_NINJA_TOOLCHAIN",
2293+
],
2294+
},
2295+
},
2296+
"<others>": {
2297+
"<others>": {
2298+
"layout": {
2299+
"toolchain.ninja" : {
2300+
"source_type": "string",
2301+
"value": '''
2302+
include <ninja-toolchain:GCC_NINJA_TOOLCHAIN>
2303+
CC=<path:SULONG_BOOTSTRAP_TOOLCHAIN>/bin/gcc
2304+
CXX=<path:SULONG_BOOTSTRAP_TOOLCHAIN>/bin/g++
2305+
AR=<path:SULONG_BOOTSTRAP_TOOLCHAIN>/bin/ar
2306+
CFLAGS=
2307+
CXXFLAGS=
2308+
LDFLAGS=
2309+
'''
2310+
},
2311+
},
2312+
"dependencies": [
2313+
"SULONG_BOOTSTRAP_TOOLCHAIN",
2314+
"mx:GCC_NINJA_TOOLCHAIN",
2315+
],
2316+
},
2317+
},
2318+
},
2319+
"maven" : False,
2320+
},
2321+
22622322
"SULONG_BOOTSTRAP_TOOLCHAIN_NO_HOME": {
22632323
"description" : "Bootstrap toolchain without an llvm.home. Use for bootstrapping libraries that should be contained in llvm.home.",
22642324
"native": True,

0 commit comments

Comments
 (0)