Skip to content

Commit 30b458e

Browse files
committed
disallow export_name starting with "llvm."
1 parent 16db0e2 commit 30b458e

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+11
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,17 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
258258
// so it may not contain any null characters.
259259
tcx.dcx().emit_err(errors::NullOnExport { span: attr.span() });
260260
}
261+
if s.as_str().starts_with("llvm."){
262+
let mut diag = tcx.dcx().struct_span_err(
263+
attr.value_span().expect("attibute has value but not a span"),
264+
"exported name must not start with \"llvm.\"",
265+
);
266+
diag.note(
267+
"symbols starting with \"llvm.\" are reserved for LLVM intrinsics \
268+
and cannot be defined in user code",
269+
);
270+
diag.emit();
271+
}
261272
codegen_fn_attrs.export_name = Some(s);
262273
mixed_export_name_no_mangle_lint_state.track_export_name(attr.span());
263274
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![crate_type = "lib"]
2+
3+
// rdtsc is an existing LLVM intrinsic
4+
#[export_name = "llvm.x86.rdtsc"]
5+
//~^ ERROR: exported name must not start with "llvm."
6+
pub unsafe fn foo(a: u8) -> u8 {
7+
2 * a
8+
}
9+
10+
// qwerty is not a real llvm intrinsic
11+
#[export_name = "llvm.x86.qwerty"]
12+
//~^ ERROR: exported name must not start with "llvm."
13+
pub unsafe fn bar(a: u8) -> u8 {
14+
2 * a
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: exported name must not start with "llvm."
2+
--> $DIR/export_name-prefix.rs:4:17
3+
|
4+
LL | #[export_name = "llvm.x86.rdtsc"]
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= note: symbols starting with "llvm." are reserved for LLVM intrinsics and cannot be defined in user code
8+
9+
error: exported name must not start with "llvm."
10+
--> $DIR/export_name-prefix.rs:11:17
11+
|
12+
LL | #[export_name = "llvm.x86.qwerty"]
13+
| ^^^^^^^^^^^^^^^^^
14+
|
15+
= note: symbols starting with "llvm." are reserved for LLVM intrinsics and cannot be defined in user code
16+
17+
error: aborting due to 2 previous errors
18+

0 commit comments

Comments
 (0)