Skip to content

Commit 8d5eac2

Browse files
author
Jesus Checa Hidalgo
committed
tests: Fix cdylib-export-c-library-symbols to work with LTO-enabled CFLAGS
The test fails on systems where default CFLAGS include LTO flags (e.g., `-flto=auto -ffat-lto-objects`), which is common in RHEL, Fedora, and CentOS distributions. The issue occurs because `build_native_static_lib()` recompiles the C source using system CFLAGS, which may include LTO. When rustc tries to process this static library with the `+export-symbols` modifier, it correctly rejects it as LTO objects in C static libraries are not supported. Fix by manually compiling the C code with `-fno-lto` to override system defaults, then using llvm-ar directly to create the static library. This ensures the test validates the `+export-symbols` feature rather than LTO compatibility.
1 parent f53b654 commit 8d5eac2

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

  • tests/run-make/cdylib-export-c-library-symbols

tests/run-make/cdylib-export-c-library-symbols/rmake.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
//@ ignore-apple
88
// Reason: the compiled binary is executed
99

10-
use run_make_support::{build_native_static_lib, cc, dynamic_lib_name, is_darwin, llvm_nm, rustc};
10+
use run_make_support::{cc, dynamic_lib_name, is_darwin, llvm_ar, llvm_nm, rustc, static_lib_name};
1111

1212
fn main() {
13-
cc().input("foo.c").arg("-c").out_exe("foo.o").run();
14-
build_native_static_lib("foo");
13+
// Compile C code without LTO
14+
cc().input("foo.c").arg("-c").arg("-fno-lto").out_exe("foo.o").run();
15+
llvm_ar().obj_to_ar().output_input(&static_lib_name("foo"), "foo.o").run();
1516

1617
rustc().input("foo.rs").arg("-lstatic=foo").crate_type("cdylib").run();
1718

0 commit comments

Comments
 (0)