This is an archive of the discontinued LLVM Phabricator instance.

WoA: Change target triple & try_compile config
ClosedPublic

Authored by rovka on Feb 28 2022, 3:21 AM.

Details

Summary

This affects the Windows on Arm builders:
clang-arm64-windows-msvc and clang-arm64-windows-msvc-2stage.

We make 2 changes:

  • Triple: s/aarch64-windows-msvc/aarch64-pc-windows-msvc; skipping

the vendor seems to confuse flang-new, so we plug an 'unknown' there.

  • Add CMAKE_TRY_COMPILE_CONFIGURATION=Release, otherwise cmake tries to

use the debug configuration for try_compile commands, and fails to find
certain libraries, e.g. MSVCP140D.dll

Diff Detail

Event Timeline

rovka created this revision.Feb 28 2022, 3:21 AM
rovka requested review of this revision.Feb 28 2022, 3:21 AM

Triple: s/aarch64-windows-msvc/aarch64-unknown-windows-msvc; skipping
the vendor seems to confuse flang-new, so we plug an 'unknown' there.

Not opposed to the change in itself (although many such MSVC configs use pc as triple, see e.g. https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/GetHostTriple.cmake#L5-L18), but it would be great if someone could have a look and see why things fail without that vendor field, as that sounds like an issue that should be resolved too.

rovka added a comment.Feb 28 2022, 3:33 AM

Agreed, I was going to pester Andrzej about that :)

rovka updated this revision to Diff 411778.Feb 28 2022, 3:35 AM
rovka edited the summary of this revision. (Show Details)

s/unknown/pc

DavidSpickett accepted this revision.Feb 28 2022, 3:35 AM

I wanna say flang-new is a proper program now not the wrapper script? If so could be something in flang's driver that is missing compared to clang's.

Looks good as far as the builds go.

This revision is now accepted and ready to land.Feb 28 2022, 3:35 AM
awarzynski accepted this revision.Feb 28 2022, 6:19 AM
awarzynski added a subscriber: awarzynski.

Thanks for this patch, @rovka !

This change makes a lot of sense to me. Essentially, it makes the CMake configuration:

  • more explicit (by including the vendor), and
  • more consistent with LLVM triple definition, which _always_ includes the vendor:

ARCHITECTURE-VENDOR-OPERATING_SYSTEM
or
ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT

Now, there are these confusing failures in Flang, which are most likely related to "effective" triples. Clang allows you to skip the vendor and it probably does that for consistency with GCC (from https://wiki.osdev.org/Target_Triplet):

(...) since the vendor field is mostly unused, the GNU build system allows you to leave out the vendor field;

However, internally Clang uses so-called "effective" triples, which do contain the vendor (here's a Clang test to demonstrate this). As Flang's compiler driver is based on clangDriver (Clang's driver library), it inherits this logic. In many cases, it doesn't matter whether you use:

-DLLVM_HOST_TRIPLE=aarch64-windows-msvc

or

-DLLVM_HOST_TRIPLE=aarch64-pc-windows-msvc

because (note how the vendor is included in the output):

clang -target aarch64-windows-msvc --print-effective-triple
aarch64-unknown-windows-msvc19.11.0

The effective triple is what clangDriver will use internally. However, the tests that @rovka is referring to are Flang's frontend driver unit tests. Neither the frontend driver nor the corresponding unit tests in Flang use clangDriver, so aarch64-windows-msvc is used verbatim and windows is parsed as vendor and msvc as OS. And things go "wrong". This is not an issue in Clang, as AFAIK there are no unit tests like this (i.e. most/all code-gen tests are LIT tests that are run via clang).

OK, that's a long comment, I hope that it makes sense :) Many thanks to Diana for digging into this with me!

However, the tests that @rovka is referring to are Flang's frontend driver unit tests. Neither the frontend driver nor the corresponding unit tests in Flang use clangDriver, so aarch64-windows-msvc is used verbatim and windows is parsed as vendor and msvc as OS.

I think the issue here, is that LLVM_HOST_TRIPLE is handled inconsistently in the codebase. When a user passes an explicit triple (e.g. via Clang's --target), it usually gets normalized before it's used. The use of LLVM_HOST_TRIPLE and similar is much more inconsistent though; in some cases in the codebase (in some tools), it works fine with a non-normalized triple, but others fail. I think we should move towards always normalizing the triples before they're used like that, even for the compiled-in hardcoded defaults, to make it behave the same as ones passed on the command line.

This revision was landed with ongoing or failed builds.Mar 1 2022, 1:42 AM
This revision was automatically updated to reflect the committed changes.
rovka added a comment.Mar 1 2022, 1:45 AM

@mstorsjo I think that would be a noble effort :) But even if we did that, it would still make sense for the buildbots to show the "best practice".