Page MenuHomePhabricator

[lldb/AppleSimulator] Always provide a -simulator environment
AcceptedPublic

Authored by friss on Jul 24 2020, 9:27 AM.

Details

Reviewers
aprantl
Summary

This commit is somewhat NFC-ish today as the environment of triples
is not considered when comparing s if one of them is
not set (I plan to change that).

We have made simulator triples unambiguous these days, but the
simulator platforms still advertise triples without the
environment. This wasn't an issue when the sims ran only on
a very different architecure than the real device, but this
has changed with Apple Silicon.

This patch simplifies the way GetSupportedArchitectureAtIndex
is implemented for the sim platforms and adds the environment.
It also trivially adds support for Apple Silicon to those
platforms.

Diff Detail

Event Timeline

friss created this revision.Jul 24 2020, 9:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2020, 9:27 AM
Herald added a subscriber: mgorny. · View Herald Transcript
aprantl added inline comments.Jul 24 2020, 10:27 AM
lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
269

I guess I should really know this... does this construct create a static initializer? If yes, isn't that something we generally want to avoid in LLVM?

I checked: HostInfo::GetArchitecture() caches the result anyway, so there is no need to cache it again here.

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
59

If the StringRef is supposed to be a triple, we might want to store an array of llvm::Triple instead? They are basically std::strings.

lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
81

at some point we should factor out all the common code in the simulator platforms ...

159

I'm probably missing something: Instead of declaring the static list of supported triples here and then manually adding the host architecture, why not create the list on-the-fly in GetSupportedArchitectureAtIndex()? Is m_supported_triples used directly somewhere?

Something like:

switch (i) {
#ifdef __APPLE__
#if __arm64__
case 0:  return  "arm64-apple-tvos-simulator";
case 1:  return  "x86_64-apple-tvos-simulator";
case 2: return "x86_64h-apple-tvos-simulator",
  };
#else
if (is_haswell)
switch (i) {
case 0: return "x86_64h-apple-tvos-simulator";
case 1: return "x86_64-apple-tvos-simulator";
}
else  return "x86_64-apple-tvos-simulator"
aprantl added inline comments.Jul 24 2020, 10:28 AM
lldb/unittests/Platform/PlatformAppleSimulatorTest.cpp
73

Does this explicitly test that platform[0] == HostInfo::GetArchitecture()?

friss marked 4 inline comments as done.Jul 24 2020, 2:36 PM
friss added inline comments.
lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp
269

static inside of a function will not create a global initializer, it will ensure that the variable is initialized once when the function is first executed. I can remove the caching though, this was cargo-culted.

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h
59

I was going for constant expressions given the StringRef constructor is constexpr. The Triple constructor is not.

lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
159

Again, I was going for constant expressions that can be indexed directly into, while this requires executing code. Spelling that argument out makes it sound really silly :-) Still I prefer a hardcoded list that any logic if we can get by with it. Maybe we just put all the variants there? If the binary cannot be executed, then the kernel will complain. Yeah, I think I'll do that.

lldb/unittests/Platform/PlatformAppleSimulatorTest.cpp
73

No. It tests the second ::Create method. This test would fail on Apple Silicon without the case llvm::Triple::aarch64 I added in there.

friss updated this revision to Diff 280604.Jul 24 2020, 3:23 PM

Simplify the logic.

aprantl accepted this revision.Jul 24 2020, 6:47 PM

This looks much cleaner!

lldb/source/Plugins/Platform/MacOSX/PlatformAppleTVSimulator.cpp
155

nit: it's weird that x86_64h comes after x86_64. All the others are sorted by newest first.

This revision is now accepted and ready to land.Jul 24 2020, 6:47 PM