This is an archive of the discontinued LLVM Phabricator instance.

Check build-type dependent variables for -flto as well.
Needs ReviewPublic

Authored by fhahn on Apr 28 2019, 11:56 AM.

Details

Summary

Currently we do not collect stats during the link step, if -flto is
added to the build-type dependent CMAKE_C/CXX_FLAGS variables. We should
check those variables as well.

Event Timeline

fhahn created this revision.Apr 28 2019, 11:56 AM

Two thoughts:

  1. Why is LDFLAGS being set conditionally, is there a warning otherwise?
  2. I wonder, why it's {C,CXX,LD}FLAGS, and not CMAKE_*_FLAGS directly.
fhahn added a comment.Apr 30 2019, 8:12 AM

Two thoughts:

  1. Why is LDFLAGS being set conditionally, is there a warning otherwise?

I think it is set conditionally, because the selected linker exe may not support it. When doing LTO and saving stats, the assumption is that people are using clang for linking.

  1. I wonder, why it's {C,CXX,LD}FLAGS, and not CMAKE_*_FLAGS directly.

Not sure, TBH.

Two thoughts:

  1. Why is LDFLAGS being set conditionally, is there a warning otherwise?

I think it is set conditionally, because the selected linker exe may not support it. When doing LTO and saving stats, the assumption is that people are using clang for linking.

Unless it is intentionally overridden along the way by the user, CMake is always using the compiler as the linker.

  1. I wonder, why it's {C,CXX,LD}FLAGS, and not CMAKE_*_FLAGS directly.

Not sure, TBH.

I just realised that this patch was still around!

Two thoughts:

  1. Why is LDFLAGS being set conditionally, is there a warning otherwise?

I think it is set conditionally, because the selected linker exe may not support it. When doing LTO and saving stats, the assumption is that people are using clang for linking.

Unless it is intentionally overridden along the way by the user, CMake is always using the compiler as the linker.

That makes sense, thanks! But I think moving away from CFLAGS, CXXFLAGS and LDFLAGS is an orthogonal change to this one and there potentially are additional things that can go wrong there. Do you think that and the change as is makes sense?

I just realised that this patch was still around!

Two thoughts:

  1. Why is LDFLAGS being set conditionally, is there a warning otherwise?

I think it is set conditionally, because the selected linker exe may not support it. When doing LTO and saving stats, the assumption is that people are using clang for linking.

Unless it is intentionally overridden along the way by the user, CMake is always using the compiler as the linker.

That makes sense, thanks! But I think moving away from CFLAGS, CXXFLAGS and LDFLAGS is an orthogonal change to this one and there potentially are additional things that can go wrong there. Do you think that and the change as is makes sense?

I don't think the change as-is is bad. Though i'm not sure it will catch everything - it can be set in subdirectory too.
Have you checked what happens if you do list(APPEND LDFLAGS -save-stats=obj) unconditionally?

I wonder, why it's {C,CXX,LD}FLAGS, and not CMAKE_*_FLAGS directly.

Not sure, TBH.

As far as I know the idea is that CFLAGS/CXXFLAGS/LDFLAGS are maintained as cmake lists so you can do stuff like list(FILTER on them. CMAKE_xxx_FLAGS are strings so it's harder to do it there.

The desire to have them as lists stems from the fact that the first version of the test-suite cmake files were mostly created by an automatic script reading the Makefiles needing to translate stuff like $(filter -lstdc++,$(LDFLAGS))...

So no strong reason, but will be annoying to change now.

lebedev.ri resigned from this revision.Jan 12 2023, 5:24 PM

This review seems to be stuck/dead, consider abandoning if no longer relevant.

Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 5:24 PM
Herald added a subscriber: StephenFan. · View Herald Transcript