Skip to content

Commit 03aa60c

Browse files
committed
Add open64 and rename symbol_name_without_mangling
1 parent e0952b2 commit 03aa60c

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

compiler/rustc_lint/src/redefining_runtime_symbols.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ declare_lint! {
2727
///
2828
/// The symbols currently checked are respectively:
2929
/// - from `core`[^1]: `memcpy`, `memmove`, `memset`, `memcmp`, `bcmp`, `strlen`
30-
/// - from `std`: `read`, `write`, `open`, `close`
30+
/// - from `std`: `open`/`open64`, `read`, `write`, `close`
3131
///
3232
/// [^1]: https://doc.rust-lang.org/core/index.html#how-to-use-the-core-library
3333
pub REDEFINING_RUNTIME_SYMBOLS,
@@ -39,7 +39,7 @@ declare_lint_pass!(RedefiningRuntimeSymbols => [REDEFINING_RUNTIME_SYMBOLS]);
3939

4040
static CORE_RUNTIME_SYMBOLS: &[&str] = &["memcpy", "memmove", "memset", "memcmp", "bcmp", "strlen"];
4141

42-
static STD_RUNTIME_SYMBOLS: &[&str] = &["open", "read", "write", "close"];
42+
static STD_RUNTIME_SYMBOLS: &[&str] = &["open", "open64", "read", "write", "close"];
4343

4444
impl<'tcx> LateLintPass<'tcx> for RedefiningRuntimeSymbols {
4545
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
@@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for RedefiningRuntimeSymbols {
5252

5353
// Compute the symbol name of our item (without mangling, as our mangling cannot ever
5454
// conflict with runtime symbols).
55-
let Some(symbol_name) = rustc_symbol_mangling::symbol_name_without_mangling(
55+
let Some(symbol_name) = rustc_symbol_mangling::symbol_name_from_attrs(
5656
cx.tcx,
5757
rustc_middle::ty::InstanceKind::Item(item.owner_id.to_def_id()),
5858
) else {

compiler/rustc_symbol_mangling/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn typeid_for_trait_ref<'tcx>(
158158
v0::mangle_typeid_for_trait_ref(tcx, trait_ref)
159159
}
160160

161-
pub fn symbol_name_without_mangling<'tcx>(
161+
pub fn symbol_name_from_attrs<'tcx>(
162162
tcx: TyCtxt<'tcx>,
163163
instance_kind: InstanceKind<'tcx>,
164164
) -> Option<String> {
@@ -252,7 +252,7 @@ fn compute_symbol_name<'tcx>(
252252

253253
debug!("symbol_name(def_id={:?}, args={:?})", def_id, args);
254254

255-
if let Some(symbol) = symbol_name_without_mangling(tcx, instance.def) {
255+
if let Some(symbol) = symbol_name_from_attrs(tcx, instance.def) {
256256
return symbol;
257257
}
258258

tests/ui/lint/redefining-runtime-symbols.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ pub static strlen: () = ();
3939
pub fn open() {}
4040
//~^ WARN redefinition of the runtime `open` symbol
4141

42+
#[no_mangle]
43+
pub fn open64() {}
44+
//~^ WARN redefinition of the runtime `open64` symbol
45+
4246
#[export_name = "read"]
4347
pub async fn read1() {}
4448
//~^ WARN redefinition of the runtime `read` symbol

tests/ui/lint/redefining-runtime-symbols.stderr

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,19 @@ LL | pub fn open() {}
7373
= note: see <https://doc.rust-lang.org/core/index.html#how-to-use-the-core-library> for the more details
7474
= help: either allow this lint or remove any `#[unsafe(no_mangle)]` or `#[unsafe(export_name = "open")]`
7575

76-
warning: redefinition of the runtime `read` symbol used by the standard library
76+
warning: redefinition of the runtime `open64` symbol used by the standard library
7777
--> $DIR/redefining-runtime-symbols.rs:43:1
7878
|
79+
LL | pub fn open64() {}
80+
| ^^^^^^^^^^^^^^^^^^
81+
|
82+
= note: extra care must be taken when redefining those symbols, they must match exactly (ABI, function arguments, function return type, behavior, ...)
83+
= note: see <https://doc.rust-lang.org/core/index.html#how-to-use-the-core-library> for the more details
84+
= help: either allow this lint or remove any `#[unsafe(no_mangle)]` or `#[unsafe(export_name = "open64")]`
85+
86+
warning: redefinition of the runtime `read` symbol used by the standard library
87+
--> $DIR/redefining-runtime-symbols.rs:47:1
88+
|
7989
LL | pub async fn read1() {}
8090
| ^^^^^^^^^^^^^^^^^^^^^^^
8191
|
@@ -84,7 +94,7 @@ LL | pub async fn read1() {}
8494
= help: either allow this lint or remove any `#[unsafe(no_mangle)]` or `#[unsafe(export_name = "read")]`
8595

8696
warning: redefinition of the runtime `write` symbol used by the standard library
87-
--> $DIR/redefining-runtime-symbols.rs:47:1
97+
--> $DIR/redefining-runtime-symbols.rs:51:1
8898
|
8999
LL | pub fn write1() {}
90100
| ^^^^^^^^^^^^^^^^^^
@@ -94,7 +104,7 @@ LL | pub fn write1() {}
94104
= help: either allow this lint or remove any `#[unsafe(no_mangle)]` or `#[unsafe(export_name = "write")]`
95105

96106
warning: redefinition of the runtime `close` symbol used by the standard library
97-
--> $DIR/redefining-runtime-symbols.rs:51:1
107+
--> $DIR/redefining-runtime-symbols.rs:55:1
98108
|
99109
LL | pub fn close_() {}
100110
| ^^^^^^^^^^^^^^^^^^
@@ -103,5 +113,5 @@ LL | pub fn close_() {}
103113
= note: see <https://doc.rust-lang.org/core/index.html#how-to-use-the-core-library> for the more details
104114
= help: either allow this lint or remove any `#[unsafe(no_mangle)]` or `#[unsafe(export_name = "close")]`
105115

106-
warning: 10 warnings emitted
116+
warning: 11 warnings emitted
107117

0 commit comments

Comments
 (0)