Skip to content

Report compile-only flags on CMake link lines as a warning - #43

Open
anakanemison wants to merge 1 commit into
mschaller/u07-align-executables-by-basenamefrom
mschaller/u08-compile-only-link-flags-warning
Open

anakanemison wants to merge 1 commit into
mschaller/u07-align-executables-by-basenamefrom
mschaller/u08-compile-only-link-flags-warning

Conversation

@anakanemison

Copy link
Copy Markdown

Part 8 of 23 of a stacked series (tracking issue: #35). Based on U07-align-executables-by-basename, the previous part: review and merge that first.

Kind: report. Lab proposal: P11.

What the migration runs showed

Every converged lensfun, jansson and pono migration suppressed the same compile flags by hand on link lines. After this change and its revision, neither lensfun (run 092) nor cmake (094) suppressed a link flag by hand.

The change

CMake passes CMAKE__FLAGS to the link line as well as the compile
line, so warning flags, -pedantic and -D/-U defines (including the -DNDEBUG
of Release builds) appear in the File API's link flags. The driver ignores
them when linking, and Bazel's link lines do not carry them, so each one was
a link_flags_diff error that every migration had to suppress by hand in
ignore.link_flags.

Measured in any2bazel-lab: every converged migration of three small
projects suppressed the same kinds of flag, each agent rediscovering and
justifying them in its own words (-Wall -Wextra -Wformat-security -pedantic
on one, -Wno-format-truncation on another, -DNDEBUG on a third). Agents also
suppressed front-end flags by hand: -fexceptions on lensfun, -w and
-fno-common on CMake's sources, -fvisibility=hidden on GDAL and QGIS. A hand
suppression is also where a reviewer can wave a real difference through.

_diff_link_flags now sends these missing CMake link flags to a new WARN
kind, link_compile_only_flags, which does not block converged:

  • warnings and -Wp, preprocessor pass-throughs (-W..., but not -Wl, or
    -Wa,, the latter because an LTO link runs the assembler), -w and
    -pedantic*;
  • -D and -U;
  • front-end -f flags that steer only the compiler, listed one by one:
    -fexceptions, -fno-exceptions, -fcommon, -fno-common,
    -fvisibility-inlines-hidden and -fvisibility=.
    Everything else stays a link_flags_diff error. Most -f flags matter at link
    time, so the list is explicit rather than a prefix, and -fopenmp, -pthread,
    -static*, -fsanitize* and -flto* are not in it. When an -flto* flag is on
    either side of a link, warning controls and the front-end flags stay errors,
    because LTO runs code generation, and diagnostics such as
    -Werror=lto-type-mismatch, at link time. ignore.link_flags still silences
    any of them entirely. SKILL.md lists the new kind, and the front-end flags,
    with the other no-action WARNs. The upstream test that
    used -fvisibility=hidden as its example of a link error now uses
    -Wl,--no-undefined.

A built-in list is a design choice the maintainers may prefer to own; this
one is reported rather than dropped, so nothing disappears silently. Not
done: raising an unreferenced _EXPORTS define only when a source
reads it, which would need the differ to read source files.

In the lab's runs with this change, the first version of the list (without
the front-end flags) still left agents suppressing -fexceptions on lensfun
and -w and -fno-common on CMake. With the list above, neither project's
next run suppressed a link flag by hand.

Testing

pytest tests/ at this commit: 191 passed (130 on main).

🤖 Generated with Claude Code

CMake passes CMAKE_<LANG>_FLAGS to the link line as well as the compile
line, so warning flags, -pedantic and -D/-U defines (including the -DNDEBUG
of Release builds) appear in the File API's link flags. The driver ignores
them when linking, and Bazel's link lines do not carry them, so each one was
a link_flags_diff error that every migration had to suppress by hand in
ignore.link_flags.

Measured in any2bazel-lab: every converged migration of three small
projects suppressed the same kinds of flag, each agent rediscovering and
justifying them in its own words (-Wall -Wextra -Wformat-security -pedantic
on one, -Wno-format-truncation on another, -DNDEBUG on a third). Agents also
suppressed front-end flags by hand: -fexceptions on lensfun, -w and
-fno-common on CMake's sources, -fvisibility=hidden on GDAL and QGIS. A hand
suppression is also where a reviewer can wave a real difference through.

_diff_link_flags now sends these missing CMake link flags to a new WARN
kind, link_compile_only_flags, which does not block `converged`:
- warnings and -Wp, preprocessor pass-throughs (-W..., but not -Wl, or
  -Wa,, the latter because an LTO link runs the assembler), -w and
  -pedantic*;
- -D and -U;
- front-end -f flags that steer only the compiler, listed one by one:
  -fexceptions, -fno-exceptions, -fcommon, -fno-common,
  -fvisibility-inlines-hidden and -fvisibility=.
Everything else stays a link_flags_diff error. Most -f flags matter at link
time, so the list is explicit rather than a prefix, and -fopenmp, -pthread,
-static*, -fsanitize* and -flto* are not in it. When an -flto* flag is on
either side of a link, warning controls and the front-end flags stay errors,
because LTO runs code generation, and diagnostics such as
-Werror=lto-type-mismatch, at link time. ignore.link_flags still silences
any of them entirely. SKILL.md lists the new kind, and the front-end flags,
with the other no-action WARNs. The upstream test that
used -fvisibility=hidden as its example of a link error now uses
-Wl,--no-undefined.

A built-in list is a design choice the maintainers may prefer to own; this
one is reported rather than dropped, so nothing disappears silently. Not
done: raising an unreferenced <target>_EXPORTS define only when a source
reads it, which would need the differ to read source files.

In the lab's runs with this change, the first version of the list (without
the front-end flags) still left agents suppressing -fexceptions on lensfun
and -w and -fno-common on CMake. With the list above, neither project's
next run suppressed a link flag by hand.

Lab-Proposal: P11
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant