Skip to content

Don't emit module metadata for non-toplevel modules. #58508

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented May 23, 2025

Instead, rely on the linker automatically inheriting the metadata from the parent module. This avoids warnings and aborts with external users such as GPUCompiler.jl.

@maleadt maleadt requested a review from gbaraldi May 23, 2025 12:13
@maleadt maleadt added compiler:codegen Generation of LLVM IR and native code gpu Affects running Julia on a GPU labels May 23, 2025
Instead, rely on the linker automatically inheriting the metadata
from the parent module. This avoids warnings and aborts with
external users such as GPUCompiler.jl.
@maleadt maleadt force-pushed the tb/module_metadata branch from c8760c3 to a7df949 Compare May 23, 2025 12:59
@gbaraldi
Copy link
Member

Looks fine to me. I guess our adhoc linker was fine with this but LLVMs default one complained?

@maleadt
Copy link
Member Author

maleadt commented May 23, 2025

Yeah, IIUC another thing that landed as part of #57010.

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

The concept that there is a "parent module" seems unsound to me. Does your linker not handle these correctly? I'd expect the LTO linker we're using here to combine these properly.

@maleadt
Copy link
Member Author

maleadt commented May 23, 2025

I'm not linking these, that happens as part of jl_emit_native calling jl_merge_module in a loop. And yeah LLVM's linker complains with warnings like:

warning: linking module flags 'Dwarf Version': IDs have conflicting values ('i32 4' from kernel with 'i32 2' from start)

... or an abort when there's a mismatch in stack-protector flags.

I considered alternative approaches, either (1) having the fresh modules in the jl_emit_native loop being clones of the initial llvmmod passed into it (which works for GPUCompiler.jl but isn't compatible with how precompilation invokes staticcompilation), and (2) adding additional flags to jl_new_ts_module to copy the flags from the llvmmod passed in (but that would result in those prototypes getting very complicated; simply omitting the "optional" metadata seemed more straightforward).

@vtjnash
Copy link
Member

vtjnash commented May 23, 2025

jl_new_ts_module to copy the flags from the llvmmod passed in

I think this option makes the most sense. In theory LLVM already implements it because it uses this same operation in many places. In practice, it isn't exactly optimal, but it is just CloneModule with a lambda that returns false, followed by a pass to remove all globals (alternatively, just copying out the 10 lines from that function which are relevant) as here: https://llvm.org/doxygen/namespacellvm.html#a61553b705fc9be3d8d0a18a8af1bc152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code gpu Affects running Julia on a GPU
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants