This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Don't LTO optimize targets on Darwin either
ClosedPublic

Authored by phosek on Jun 23 2021, 12:52 AM.

Details

Summary

This is a follow up to D102732 which also expands the logic to Darwin.

Diff Detail

Event Timeline

phosek created this revision.Jun 23 2021, 12:52 AM
phosek requested review of this revision.Jun 23 2021, 12:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2021, 12:52 AM
smeenai accepted this revision.Jun 23 2021, 11:12 AM
smeenai added a subscriber: int3.

Hmm, LLD for Mach-O already has some support for LTO. @int3, do we expect --lto-O0 to work for it?

This revision is now accepted and ready to land.Jun 23 2021, 11:12 AM
int3 added a comment.Jun 23 2021, 11:18 AM

Nope, we didn't add support for --lto-O0. I *think* the ld64 equivalent is -flto-codegen-only, but we don't support that yet either (and it's undocumented). However, we do support -mllvm, so -mllvm,-O0 should work.

Shall I drop the NOT LINKER_IS_LLD check so it applies to both ld64 and ld64.lld?

Shall I drop the NOT LINKER_IS_LLD check so it applies to both ld64 and ld64.lld?

Sounds good.

phosek updated this revision to Diff 354155.Jun 23 2021, 10:27 PM

LGTM, thanks!

This revision was automatically updated to reflect the committed changes.

Should this apply to Darwin even when not using LLD?

I'm seeing an error which tracks down to this change. It works fine without the -mllvm,-O0 link flags.

FAILED: bin/llvm-tblgen 
[...snip...]
Remaining virtual register operands
UNREACHABLE executed at .../llvm-project/llvm/lib/CodeGen/MachineRegisterInfo.cpp:209!
clang-13: error: unable to execute command: Abort trap: 6
clang-13: error: linker command failed due to signal (use -v to see invocation)

https://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/4221/consoleFull

Should this apply to Darwin even when not using LLD?

I'm seeing an error which tracks down to this change. It works fine without the -mllvm,-O0 link flags.

FAILED: bin/llvm-tblgen 
[...snip...]
Remaining virtual register operands
UNREACHABLE executed at .../llvm-project/llvm/lib/CodeGen/MachineRegisterInfo.cpp:209!
clang-13: error: unable to execute command: Abort trap: 6
clang-13: error: linker command failed due to signal (use -v to see invocation)

https://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/4221/consoleFull

It should, ld64 supports passing flags to libLTO via the -mllvm flag. We have been using this on our macOS bots for a few weeks and haven't run into any issues (they are using using ld64, not lld).

Should this apply to Darwin even when not using LLD?

I'm seeing an error which tracks down to this change. It works fine without the -mllvm,-O0 link flags.

FAILED: bin/llvm-tblgen 
[...snip...]
Remaining virtual register operands
UNREACHABLE executed at .../llvm-project/llvm/lib/CodeGen/MachineRegisterInfo.cpp:209!
clang-13: error: unable to execute command: Abort trap: 6
clang-13: error: linker command failed due to signal (use -v to see invocation)

https://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/4221/consoleFull

It should, ld64 supports passing flags to libLTO via the -mllvm flag. We have been using this on our macOS bots for a few weeks and haven't run into any issues (they are using using ld64, not lld).

@phosek, the config where I'm seeing this is a two stage bootstrap build. Could you try building again with the just built clang and see if it still works for you? I seem to be able to reliably reproduce the error locally.

@phosek, the config where I'm seeing this is a two stage bootstrap build. Could you try building again with the just built clang and see if it still works for you? I seem to be able to reliably reproduce the error locally.

Yes, that's what we use on our bots as well. However, I just noticed that your bots are using ThinLTO, is that correct? We always use full LTO and it's possible that this issue only manifests in ThinLTO.

@phosek, the config where I'm seeing this is a two stage bootstrap build. Could you try building again with the just built clang and see if it still works for you? I seem to be able to reliably reproduce the error locally.

Yes, that's what we use on our bots as well. However, I just noticed that your bots are using ThinLTO, is that correct? We always use full LTO and it's possible that this issue only manifests in ThinLTO.

Yes, correct, this is with ThinLTO. I tried full LTO and I don't see the error, so, yes this appears to be an issue only with ThinLTO.

For now, let me guard this behavior to if its not ThinLTO, until we get the root cause fixed.