Skip to content

fix: Implement plugin callsbacks required for thin LTO#1902

Merged
davidlattimore merged 1 commit into
mainfrom
push-yyolmwsrynpx
May 8, 2026
Merged

fix: Implement plugin callsbacks required for thin LTO#1902
davidlattimore merged 1 commit into
mainfrom
push-yyolmwsrynpx

Conversation

@davidlattimore

Copy link
Copy Markdown
Member

Fixes #1571

@mati865 mati865 left a comment

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.

Such a lovely interface.

Comment on lines -259 to 273
let name = CString::new(input_ref.file.filename.as_os_str().as_encoded_bytes())?;
let file = LdPluginInputFile {
name: name.as_ptr(),

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.

Wasn't that use-after-free previously?
CString created allocation and unless I'm missing something due to viewing this on my phone, we only used pointer to it. So the name would be dropped when going out of scope.

With the new code name is stored within the struct, so the allocation is kept alive.

Borrow checker doesn't catch such issues because it's legal and safe to create dangling pointers. The part requiring unsafe code is reading from the pointers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The pointer to name would previously have been valid for the duration of the call into the plugin's claim-file hook. But if the claim-file hook stored the pointer and used it later, then yes, it would have been a use-after-free. AFAIK though it doesn't, but the linker plugin API docs are pretty absent of any mentions of required lifetimes, so who knows.

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.

Ah, this function returns LtoInputInfo, not LdPluginInputFile. Line wrapping in the mobile view tricked me.

@davidlattimore davidlattimore merged commit 828f437 into main May 8, 2026
24 checks passed
@davidlattimore davidlattimore deleted the push-yyolmwsrynpx branch May 8, 2026 21:31
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.

lto: wild's LTO plugin doesn't work with LLVM's thin LTO (wild: error: Linker plugin error: Failed to release file information)

2 participants