-
Notifications
You must be signed in to change notification settings - Fork 13.6k
generate elf symbol version in raw-dylib #144221
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
+267
−29
Merged
Changes from all commits
Commits
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//@ only-x86_64-unknown-linux-gnu | ||
//@ needs-dynamic-linking | ||
//@ build-pass | ||
|
||
#![allow(incomplete_features)] | ||
#![feature(raw_dylib_elf)] | ||
|
||
#[link(name = "hack", kind = "raw-dylib")] | ||
unsafe extern "C" {} | ||
|
||
fn main() {} |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
//@ only-x86_64-unknown-linux-gnu | ||
//@ needs-dynamic-linking | ||
//@ run-pass | ||
//@ compile-flags: -Cpanic=abort | ||
//@ edition: 2024 | ||
usamoi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#![allow(incomplete_features)] | ||
#![feature(raw_dylib_elf)] | ||
#![no_std] | ||
#![no_main] | ||
|
||
use core::ffi::{c_char, c_int}; | ||
|
||
extern "C" fn callback( | ||
_fpath: *const c_char, | ||
_sb: *const (), | ||
_tflag: c_int, | ||
_ftwbuf: *const (), | ||
) -> c_int { | ||
0 | ||
} | ||
|
||
// `libc.so` is a linker script that provides the paths to `libc.so.6` and `libc_nonshared.a`. | ||
// In earlier versions of glibc, `libc_nonshared.a` provides the symbols `__libc_csu_init` and | ||
// `__libc_csu_fini` required by `Scrt1.o`. | ||
#[link(name = "c_nonshared", kind = "static")] | ||
unsafe extern "C" {} | ||
|
||
#[link(name = "libc.so.6", kind = "raw-dylib", modifiers = "+verbatim")] | ||
unsafe extern "C" { | ||
#[link_name = "nftw@GLIBC_2.2.5"] | ||
unsafe fn nftw_2_2_5( | ||
dirpath: *const c_char, | ||
f: extern "C" fn(*const c_char, *const (), c_int, *const ()) -> c_int, | ||
nopenfd: c_int, | ||
flags: c_int, | ||
) -> c_int; | ||
#[link_name = "nftw@GLIBC_2.3.3"] | ||
unsafe fn nftw_2_3_3( | ||
dirpath: *const c_char, | ||
f: extern "C" fn(*const c_char, *const (), c_int, *const ()) -> c_int, | ||
nopenfd: c_int, | ||
flags: c_int, | ||
) -> c_int; | ||
#[link_name = "exit@GLIBC_2.2.5"] | ||
safe fn exit(status: i32) -> !; | ||
unsafe fn __libc_start_main() -> c_int; | ||
} | ||
|
||
#[unsafe(no_mangle)] | ||
extern "C" fn main() -> ! { | ||
unsafe { | ||
// The old `nftw` does not check whether unknown flags are set. | ||
let res = nftw_2_2_5(c".".as_ptr(), callback, 20, 1 << 30); | ||
assert_eq!(res, 0); | ||
} | ||
unsafe { | ||
// The new `nftw` does. | ||
let res = nftw_2_3_3(c".".as_ptr(), callback, 20, 1 << 30); | ||
assert_eq!(res, -1); | ||
} | ||
exit(0); | ||
} | ||
|
||
#[cfg(not(test))] | ||
#[panic_handler] | ||
fn panic_handler(_: &core::panic::PanicInfo<'_>) -> ! { | ||
exit(1); | ||
} | ||
|
||
#[unsafe(no_mangle)] | ||
extern "C" fn rust_eh_personality( | ||
_version: i32, | ||
_actions: i32, | ||
_exception_class: u64, | ||
_exception_object: *mut (), | ||
_context: *mut (), | ||
) -> i32 { | ||
exit(1); | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/ui/linkage-attr/raw-dylib/elf/malformed-link-name.rs
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//@ only-elf | ||
//@ needs-dynamic-linking | ||
//@ check-fail | ||
|
||
#![feature(raw_dylib_elf)] | ||
#![allow(incomplete_features)] | ||
|
||
#[link(name = "libc.so.6", kind = "raw-dylib", modifiers = "+verbatim")] | ||
unsafe extern "C" { | ||
#[link_name = "exit@"] | ||
pub safe fn exit_0(status: i32) -> !; //~ ERROR link name must be well-formed if link kind is `raw-dylib` | ||
#[link_name = "@GLIBC_2.2.5"] | ||
pub safe fn exit_1(status: i32) -> !; //~ ERROR link name must be well-formed if link kind is `raw-dylib` | ||
#[link_name = "ex\0it@GLIBC_2.2.5"] | ||
pub safe fn exit_2(status: i32) -> !; //~ ERROR link name must be well-formed if link kind is `raw-dylib` | ||
#[link_name = "exit@@GLIBC_2.2.5"] | ||
pub safe fn exit_3(status: i32) -> !; //~ ERROR link name must be well-formed if link kind is `raw-dylib` | ||
} | ||
|
||
fn main() {} |
26 changes: 26 additions & 0 deletions
26
tests/ui/linkage-attr/raw-dylib/elf/malformed-link-name.stderr
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error: link name must be well-formed if link kind is `raw-dylib` | ||
--> $DIR/malformed-link-name.rs:11:5 | ||
| | ||
LL | pub safe fn exit_0(status: i32) -> !; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: link name must be well-formed if link kind is `raw-dylib` | ||
--> $DIR/malformed-link-name.rs:13:5 | ||
| | ||
LL | pub safe fn exit_1(status: i32) -> !; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: link name must be well-formed if link kind is `raw-dylib` | ||
--> $DIR/malformed-link-name.rs:15:5 | ||
| | ||
LL | pub safe fn exit_2(status: i32) -> !; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: link name must be well-formed if link kind is `raw-dylib` | ||
--> $DIR/malformed-link-name.rs:17:5 | ||
| | ||
LL | pub safe fn exit_3(status: i32) -> !; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.