Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono][aot] Improve toolchain configuration in Mono AOT compiler #93052

Closed
kotlarmilos opened this issue Oct 5, 2023 · 2 comments
Closed

[mono][aot] Improve toolchain configuration in Mono AOT compiler #93052

kotlarmilos opened this issue Oct 5, 2023 · 2 comments
Assignees
Milestone

Comments

@kotlarmilos
Copy link
Member

The Mono AOT compiler comes with a predefined set of toolchain configurations for particular platforms.

#ifdef TARGET_WIN32_MSVC
#define AS_OPTIONS "--target=x86_64-pc-windows-msvc -c -x assembler"
#elif defined(TARGET_AMD64) && !defined(TARGET_MACH)
#define AS_OPTIONS "--64"
#elif defined(TARGET_POWERPC64)
#define AS_OPTIONS "-a64 -mppc64"
#elif defined(TARGET_X86) && defined(TARGET_MACH)
#define AS_OPTIONS "-arch i386"
#elif defined(TARGET_X86) && !defined(TARGET_MACH)
#define AS_OPTIONS "--32"
#elif defined(MONO_ARCH_ENABLE_PTRAUTH)
#define AS_OPTIONS "-arch arm64e"
#else
#define AS_OPTIONS ""
#endif

The current implementation does not allow for full extensibility in cases when the default toolchain is not available. To mitigate this, the #92057 introduces the as_name and as_options, along with ld_name and ld_options to allow specific toolchain configuration.

However, there are cases where the default properties are combined with parameters. For example, even though the ld-name is passed as an argument, if the LD_NAME is not defined, the default configuration is used:

#if defined(LD_NAME)
if (ld_binary_name == NULL) {
ld_binary_name = LD_NAME;
}
if (acfg->aot_opts.tool_prefix)
g_string_append_printf (str, "\"%s%s\" %s", tool_prefix, ld_binary_name, LD_OPTIONS);
else if (acfg->aot_opts.llvm_only)
g_string_append_printf (str, "%s", acfg->aot_opts.clangxx);
else
g_string_append_printf (str, "\"%s%s\" %s", tool_prefix, ld_binary_name, LD_OPTIONS);
#else
if (ld_binary_name == NULL) {
ld_binary_name = "ld";
}
// Default (linux)
if (acfg->aot_opts.tool_prefix)
/* Cross compiling */
g_string_append_printf (str, "\"%s%s\" %s", tool_prefix, ld_binary_name, LD_OPTIONS);
else if (acfg->aot_opts.llvm_only)
g_string_append_printf (str, "%s", acfg->aot_opts.clangxx);
else
g_string_append_printf (str, "\"%s%s\"", tool_prefix, ld_binary_name);
g_string_append_printf (str, " -shared");
#endif

In order to enable easier code maintenance and to improve flexibility in utilizing different toolchains, the proposal is to introduce the PlatformConfig struct:

typedef struct {
    const char* as_name;
    const char* as_options;
    const char* as_object_file_suffix;
    const char* ld_name;
    const char* ld_options;
} PlatformConfig;

It can be defined as follows:

void compile_asm(MonoAotCompile* acfg, const CompileConfig* config)

And utilized as below:

compile_asm(acfg, &CONFIG_WIN32_MSVC);
// or
compile_asm(acfg, &CONFIG_LINUX);

The structs may be defined in a separate configuration file that is linked with the AOT compiler. This approach would enable the creation of default configurations according to the host OS and architecture in a structured manner and allow parameterizing these options.

/cc: @vargaz @lambdageek

@kotlarmilos kotlarmilos added this to the 9.0.0 milestone Oct 5, 2023
@kotlarmilos kotlarmilos self-assigned this Oct 5, 2023
@vargaz
Copy link
Contributor

vargaz commented Oct 5, 2023

We have an utils/options-def.h file with some support for options which are compile time constants, perhaps this stuff can be added there ?

@kotlarmilos kotlarmilos modified the milestones: 9.0.0, Future Feb 9, 2024
@kotlarmilos kotlarmilos linked a pull request Feb 9, 2024 that will close this issue
@kotlarmilos
Copy link
Member Author

Lower priority compared to other tasks.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants