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

cglobal: Add an option to bypass jlplt mechanism #51108

Closed
wants to merge 1 commit into from
Closed

Conversation

Keno
Copy link
Member

@Keno Keno commented Aug 30, 2023

This adds an extra argument to cglobal to opt out of the jlplt runtime symbol resolution mechanism. This is necessary for StaticCompiler-like code that needs to function in environments that do not provide the julia runtime symbol resolution support code. Symbol resolution is deferred to the host linker (static or dynamic, where the latter may of course use its own PLT).

This adds an extra argument to `cglobal` to opt out of the jlplt
runtime symbol resolution mechanism. This is necessary for
StaticCompiler-like code that needs to function in environments
that do not provide the julia runtime symbol resolution support
code. Symbol resolution is deferred to the host linker (static
or dynamic, where the latter may of course use its own PLT).
@Keno Keno requested review from vtjnash and pchintalapudi August 30, 2023 06:44
@gbaraldi
Copy link
Member

Is this so it can work without LLVM, or is the goal to allow for an even simpler runtime?

@Keno
Copy link
Member Author

Keno commented Aug 30, 2023

This is for when you don't have the julia runtime at all.

if ((sym.f_lib && !((sym.f_lib == JL_EXE_LIBNAME) ||
(sym.f_lib == JL_LIBJULIA_INTERNAL_DL_LIBNAME) ||
(sym.f_lib == JL_LIBJULIA_DL_LIBNAME))) || sym.lib_expr) {
jl_printf(JL_STDERR,"WARNING: Attempted to use library expression for symbol %s while disabling jlplt. Library expression was ignored.\n", sym.f_name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codegen shouldn't be printing, except when there is a bug in codegen

@gbaraldi
Copy link
Member

So instead of doing a dlopen it just emits a call to a symbol/load from a symbol?

@vtjnash
Copy link
Member

vtjnash commented Aug 30, 2023

I don't really like the idea of a dynamic flag to control static behavior. LLVM does that sometimes (immarg or metadata), and it always looks like an implementation mistake to me whenever I see it (especially when I see them add an enum option that tells the optimizer that the immarg is actually a runtime value).

In normal execution, this is handled by this optimization passes here:

if (!Callee || Callee->getName() != XSTR(jl_load_and_lookup))
Perhaps there are cases where we could detect that can be done from codegen, though I worry it would get our semantics wrong and ending up linking to the wrong libjulia-internal–just after Cody created #49010 and #50162 so that we would link against the correct ones.

@Keno
Copy link
Member Author

Keno commented Aug 31, 2023

don't really like the idea of a dynamic flag to control static behavior.

Would you prefer a codegen option instead? I think that could work and I'm moving into that direction anyway with some of the other static-ness restrictions. I don't think there's ever a situation where you want to mix and match jlplt and non-jlplt within the same function (though possibly within the same compilation unit).

@vtjnash
Copy link
Member

vtjnash commented Aug 31, 2023

Having a codegen option seems probably to be fine. I am somewhat surprised now that the GPUCompiler folks hadn't already added that option, but I think they have been using a number of workarounds with "extern llvmcall".

Keno added a commit that referenced this pull request Aug 31, 2023
Keno added a commit that referenced this pull request Sep 1, 2023
Alternative to #51108 with the
same objectives.
@Keno
Copy link
Member Author

Keno commented Sep 1, 2023

Replaced by #51123

@Keno Keno closed this Sep 1, 2023
@giordano giordano deleted the kf/cglobalnoplt2 branch February 25, 2024 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants