Skip to content

offload: automate manual clang-linker-wrapper step - #162309

Draft
sgasho wants to merge 1 commit into
rust-lang:mainfrom
sgasho:offload-clang-linker-wrapper
Draft

offload: automate manual clang-linker-wrapper step#162309
sgasho wants to merge 1 commit into
rust-lang:mainfrom
sgasho:offload-clang-linker-wrapper

Conversation

@sgasho

@sgasho sgasho commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

automate manual clang-linker-wrapper step from https://rustc-dev-guide.rust-lang.org/offload/usage.html
extract bitcode from device.bin and then wraps it into the host module.
needs some refactoring.

r? @ZuseZ4

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 4, 2026
pub(crate) struct OffloadEmbedFailed;

#[derive(Diagnostic)]
#[diag("call to WrapImages failed, `wrapper.o` was not created")]

@sgasho sgasho Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TODO(before merge): I forgot to fix the diag comment. wrapper.o no longer exists.

View changes since the review

);

if sess.opts.unstable_opts.offload.iter().any(|o| matches!(o, config::Offload::Host(_))) {
cmd.link_dylib_by_name("omptarget", false, true);

@ZuseZ4 ZuseZ4 Sep 4, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks to your last PR, we should ship these in our sysroot. Is it guaranteed to be on our default search path? If not, we might want to add an rpath or -L, or?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, looking at walk_native_lib_search_dirs, it is on our default linker search path, so we don't need an additional -L, but we need an rpath for runtime. I also checked this on a UofT server.

@sgasho

sgasho commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

I'm looking into this issue I encountered while testing on a gpu server

shotasugano@gpunode1:/w/333/shotasugano/sample-offload$ ./target/x86_64-unknown-linux-gnu/release/sample-offload 
PluginInterface error: Failure to load binary image 0x62597fffacf0 on device 0: "jit compile failure while processing binary image" failure to jit IR image: Unable to find target for this triple (no targets are registered)
omptarget error: Failed to load image "a provided binary image is malformed" failed to load binary 0x62597fffacf0
omptarget fatal error 0: "the plugin backend is in an invalid or unsupported state" failed to load images on device '0'
Aborted                    ./target/x86_64-unknown-linux-gnu/release/sample-offload

update:
fixing by bringin more logic from ClangLinerWrapper.cpp...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants