Skip to content

Do not pass CFLAGS to linker#13200

Merged
shindere merged 3 commits intoocaml:trunkfrom
shindere:fix-cflags
May 27, 2024
Merged

Do not pass CFLAGS to linker#13200
shindere merged 3 commits intoocaml:trunkfrom
shindere:fix-cflags

Conversation

@shindere
Copy link
Copy Markdown
Contributor

The present PR is a follow-up to both #9824 (Build system: honour the
CFLAGS and CPPFLAGS build variables) and #9837 (Build system: use
OC_CFLAGS and CFLAGS even during the link stage).

After #9824 was merged, Inria's extra-checks CI job got broken
because the link stage needed the sanitizer-related flags, too.
The fix that was then provided in #9837 was actually not correct: rather
than using CFLAGS also during the link stage, which is not what GNU make does
by default, we should rather
duplicate the relevant flags into LDFLAGS.

This makes sense because even a flag with the same name does not
have the same semantics depending on whether it is in CFLAGS or LDFLAGS.
For the instrumentation flags, for instance, when in CFLAGS they request the
code to be compiled with instrumentation, whereas when in LDFLAGS they
request that the runtime support for instrumentation to be linked in, which
is of course related but still slightly different.

The reason why the flags intended to be in CFLAGS and those intended to be
in LDFLAGS often have the same name is to make it possible to do both
compile and link in one go, which we still were doing sometimes at the time
of #9824 and #9837 (e.g. for checkstack) but do not do any longer
nowadays: our build system pays a lot of attention not to confuse
compile and link commands, be it for programs / libraries in C or in OCaml.

This PR opens the road to an improvement in the way TSan build flags are
handled, which will considerably speed-up the build of TSan-enabled
compilers. Once this PR is merged, we will also be able to bring #12589 to
its clean and ocrrect completion.

shindere added 3 commits May 27, 2024 11:03
The TSan CI workflow should pass -DTSAN_INSTRUMENT_ALL through
CPPFLAGS rather than CFLAGS
Copy link
Copy Markdown
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me. I was a bit surprised by the fact that we now rely more on CPPFLAGS, but it makes sense.

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shindere
Copy link
Copy Markdown
Contributor Author

shindere commented May 27, 2024 via email

Copy link
Copy Markdown
Contributor

@MisterDA MisterDA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve this PR too, based on GNU Make Catalogue of Rules:

  • Compiling C programs: $(CC) $(CPPFLAGS) $(CFLAGS) -c;
  • Linking a single object file: $(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS) (LOADLIBES being deprecated).

@shindere
Copy link
Copy Markdown
Contributor Author

shindere commented May 27, 2024 via email

@shindere
Copy link
Copy Markdown
Contributor Author

shindere commented May 27, 2024 via email

@shindere shindere merged commit 5cd8631 into ocaml:trunk May 27, 2024
@shindere shindere deleted the fix-cflags branch May 27, 2024 10:20
shindere added a commit that referenced this pull request May 27, 2024
@shindere
Copy link
Copy Markdown
Contributor Author

Just pushed bb119d1 to add names of reviewers to the Changes entry for this PR, apologies for having forgotten.

@gasche
Copy link
Copy Markdown
Member

gasche commented May 27, 2024

Your Changes entry credits @shym with a review, did it occur outside github/ocaml?

@shindere
Copy link
Copy Markdown
Contributor Author

shindere commented May 27, 2024 via email

@MisterDA
Copy link
Copy Markdown
Contributor

A small unforeseen consequence is that we used to pass -nologo to MSVC to disable its (verbose!) output. The flag was added to the CFLAGS. As we're no longer passing CFLAGS to the linker invocation, the MKEXE step has become noisy. I've tested that adding -nologo to LDFLAGS (more exactly, to flags coming after /link in the compiler driver invocation) silences cl. @shindere, would you know what would be the most appropriate location to add this flag?

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.

3 participants