-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Handle statics and TLS in raw-dylib for ELF #153580
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
Merged
rust-bors
merged 6 commits into
rust-lang:main
from
mati865:elf-raw-dylib-static-and-tls
Mar 18, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82727b0
Refactor DllImport to better differentiate types
mati865 2fad36b
Extend raw-dylib to handle statics and TLS for ELF
mati865 f365432
Set symbol size in raw-dylib for ELF
mati865 3638155
Put statics in .data section in raw-dylib for ELF
mati865 ed4afa5
Set symbols value in raw-dylib for ELF
mati865 3531ed9
Extend raw-dylib test for ELF with reloc models
mati865 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| int global_variable = 3; | ||
| __thread int tls_variable = 33; | ||
| const long const_array[] = {795, 906}; | ||
| const char *const_string = "sums of three cubes"; | ||
|
|
||
| int this_is_a_library_function() { | ||
| return 42; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,29 @@ | ||
| #![feature(raw_dylib_elf)] | ||
| #![feature(thread_local)] | ||
| #![allow(incomplete_features)] | ||
|
|
||
| use std::ffi::{CStr, c_char, c_int, c_long}; | ||
|
|
||
| #[link(name = "library", kind = "raw-dylib")] | ||
| unsafe extern "C" { | ||
| safe fn this_is_a_library_function() -> core::ffi::c_int; | ||
| safe fn this_is_a_library_function() -> c_int; | ||
| static mut global_variable: c_int; | ||
| #[thread_local] | ||
| static mut tls_variable: c_int; | ||
| safe static const_array: [c_long; 2]; | ||
| safe static const_string: *const c_char; | ||
| } | ||
|
|
||
| fn main() { | ||
| println!("{}", this_is_a_library_function()) | ||
| unsafe { | ||
| println!( | ||
| "{} {} {} {} {} {}", | ||
| this_is_a_library_function(), | ||
| global_variable, | ||
| tls_variable, | ||
| const_array[0], | ||
| const_array[1], | ||
| CStr::from_ptr(const_string).to_str().unwrap(), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 42 | ||
| 42 3 33 795 906 sums of three cubes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is reachable via #154111
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I have tried to use type there, but only as a definition. Not as a declaration, I'll look into it tomorrow.