Skip to content

tests: Fix cdylib-export-c-library-symbols to work with LTO-enabled CFLAGS#156012

Open
jchecahi wants to merge 1 commit intorust-lang:mainfrom
jchecahi:cdylib-export-c-library-symbols-lto-fix
Open

tests: Fix cdylib-export-c-library-symbols to work with LTO-enabled CFLAGS#156012
jchecahi wants to merge 1 commit intorust-lang:mainfrom
jchecahi:cdylib-export-c-library-symbols-lto-fix

Conversation

@jchecahi
Copy link
Copy Markdown

@jchecahi jchecahi commented Apr 30, 2026

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:

=== STDERR ===
error: failed to process C static library `foo`: LTO object in C static library is not supported
error: aborting due to 1 previous error

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 (see #150992).

Fix by manually compiling the C code passing -fno-lto to cc() 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.

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 30, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 30, 2026

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

@rustbot

This comment has been minimized.

…FLAGS

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.
@jchecahi jchecahi force-pushed the cdylib-export-c-library-symbols-lto-fix branch from b503a5d to 8d5eac2 Compare April 30, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants