Use Default visibility for rustc-generated C symbol declarations · rust-lang/rust@42c0494 (original) (raw)

File tree

2 files changed

lines changed

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -84,10 +84,9 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
84 84 unnamed: llvm::UnnamedAddr,
85 85 fn_type: &'ll Type,
86 86 ) -> &'ll Value {
87 -// Declare C ABI functions with the visibility used by C by default.
88 -let visibility = Visibility::from_generic(self.tcx.sess.default_visibility());
89 -
90 -declare_raw_fn(self, name, llvm::CCallConv, unnamed, visibility, fn_type)
87 +// Visibility should always be default for declarations, otherwise the linker may report an
88 +// error.
89 +declare_raw_fn(self, name, llvm::CCallConv, unnamed, Visibility::Default, fn_type)
91 90 }
92 91
93 92 /// Declare an entry Function
Original file line number Diff line number Diff line change
@@ -31,3 +31,19 @@ pub static tested_symbol: [u8; 6] = *b"foobar";
31 31 // PROTECTED: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = protected constant
32 32 // INTERPOSABLE: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = constant
33 33 // DEFAULT: @{{.*}}default_visibility{{.*}}tested_symbol{{.*}} = constant
34 +
35 +pub fn do_memcmp(left: &[u8], right: &[u8]) -> i32 {
36 + left.cmp(right) as i32
37 +}
38 +
39 +// CHECK: define {{.*}} @{{.*}}do_memcmp{{.*}} {
40 +// CHECK: }
41 +
42 +// `do_memcmp` should invoke core::intrinsic::compare_bytes which emits a call
43 +// to the C symbol `memcmp` (at least on x86_64-unknown-linux-gnu). This symbol
44 +// should *not* be declared hidden or protected.
45 +
46 +// HIDDEN: declare i32 @memcmp
47 +// PROTECTED: declare i32 @memcmp
48 +// INTERPOSABLE: declare i32 @memcmp
49 +// DEFAULT: declare i32 @memcmp