This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Handle target and sysroot flags in tests
Needs RevisionPublic

Authored by phosek on Jun 2 2022, 6:37 PM.

Details

Summary

Pass the target and sysroot flags from the build to lit and make sure
they are included in the test cflags.

Diff Detail

Event Timeline

phosek created this revision.Jun 2 2022, 6:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2022, 6:37 PM
Herald added subscribers: Enna1, dberris. · View Herald Transcript
phosek requested review of this revision.Jun 2 2022, 6:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 2 2022, 6:37 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
yln accepted this revision.Jun 3 2022, 1:30 PM

Looks sensible to me, but I don't understand the implications here.

Can you explain why this is needed/what doesn't work right now?
@phosek

This revision is now accepted and ready to land.Jun 3 2022, 1:30 PM
phosek added a comment.Jun 6 2022, 2:13 PM

Looks sensible to me, but I don't understand the implications here.

Can you explain why this is needed/what doesn't work right now?
@phosek

In our case we build against an explicit sysroot or SDK, even when the host matches the target. This is to ensure that we don't accidentally introduce dependency on libraries (or their versions) that are only present on certain hosts. We noticed recently that test binaries don't follow the CMake configuration when we saw test failures that only affected some hosts. The goal of this change is to make the behavior CMake and lit more consistent.

delcypher added inline comments.Jun 6 2022, 2:38 PM
compiler-rt/test/lit.common.cfg.py
699

I haven't verified this but I think this very likely to break testing for Apple platforms. I don't think config.target_triple is set correctly. IIRC we rely on the target triple being inferred from the SDK and arch being used. This isn't a good situation to be in, explicit would definitely be better.

701

We should check but I doubt this is configured correctly. It's probably correct for macOS but broken for other Apple platforms because I suspect config.sysroot might always be set to a macOS SDK path.

delcypher requested changes to this revision.Jun 6 2022, 3:02 PM

The change is right in "spirit" but I think the current implementation will likely break things (or will work by accident). There is a fundamental difference between how compiler-rt is built for Apple platforms and other platforms. For Apple platforms we build all platforms and targets in a single CMake configure (IIUC other platforms have a CMake configure correspond to a single platform and arch). So there is no single sysroot or target triple.

The way this is currently handled for the the lit testing is we generate a lit test suite for each OS and architecture we want, e.g. from a template like

https://github.com/llvm/llvm-project/blob/main/compiler-rt/test/asan/lit.site.cfg.py.in

I think what the patch does here is fine to be the "default" (although I might prefer it to be set to something that causes on error by default on Apple platforms) but we need to make sure for all the generated testsuites that we override config.target_triple and config.sysroot to be the right thing.

We might also want to remote the sysroot from being set in the target_cflags because we already do that e.g.

# Autogenerated from /Volumes/user_data/dev/llvm/llvm.org/main/src/llvm-project/compiler-rt/test/asan/lit.site.cfg.py.in
# Do not edit!

# Allow generated file to be relocatable.
from pathlib import Path
def path(p):
    if not p: return ''
    return str((Path(__file__).parent / p).resolve())


# Tool-specific config options.
config.name_suffix = "-arm64-ios"
config.target_cflags = "-arch arm64 -stdlib=libc++ -miphoneos-version-min=9.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta "
config.clang = "/Volumes/user_data/dev/llvm/llvm.org/main/builds/Debug/./bin/clang"
config.bits = "64"
config.arm_thumb = ""
config.apple_platform = "ios"
config.apple_platform_min_deployment_target_flag = "-miphoneos-version-min"
config.asan_dynamic = True
config.target_arch = "arm64"

...

We might want to create an Apple "platform/arch" specific "lit.common.configured.in" files that the existing testsuites (e.g. ASan) can include so we don't have to duplicate the logic across all the different test suites.

compiler-rt/test/lit.common.configured.in
11

This will be the sysroot for macOS which is the wrong sysroot for all other Apple platforms.

This revision now requires changes to proceed.Jun 6 2022, 3:02 PM