
Translating an ARM iOS App to Intel macOS Using Bitcode - sjuut
https://www.highcaffeinecontent.com/blog/20190518-Translating-an-ARM-iOS-App-to-Intel-macOS-Using-Bitcode
======
ken
The intro makes it sound like this could be feasible for translating x86 Mac
apps into ARM Mac apps.

> So, what if the Mac switched to using ARM chips instead of Intel? Well, as
> you can see, Apple could use Bitcode to translate every Bitcode-enabled app
> on the Mac App Store, without consulting developers, so it would be ready to
> go on day one.

But:

> Apple doesn't enable Bitcode for submissions to the Mac App Store today

Right. The flag to enable bitcode isn't even visible in Xcode for Mac apps.
There's no such thing as Mac/x86 bitcode yet, in or out of the MAS. And:

> ARC appears to use some inline assembly, which means you'll need to disable
> ARC for a project for arm64-to-x86 translation to succeed right now.

So this approach will only work on Objective-C programs, written in a pre-2011
style -- which I'd bet is a vanishingly small fraction of the apps on the MAS
today.

It's a neat exercise in what is possible for a simplest-possible-app, but it's
hard to imagine Apple would actually use this approach. It'd require them to
ship a couple big new features in Xcode, and then for everyone on the MAS to
recompile their apps using those features. Easier all around to just add a new
architecture in Xcode the normal way, and have developers compile fat
binaries.

~~~
Someone
_”ARC appears to use some inline assembly, which means you 'll need to disable
ARC for a project for arm64-to-x86 translation to succeed right now.”_

That’s fairly easily fixed, certainly if you’re Apple. They already have the
equivalent x86 code (Swift and modern Objective-C couldn't exist without it),
so they could detect the specific inline ARM code fragment and replace it by
the equivalent inline x86 code.

~~~
saagarjha
This seems like it would be very fragile.

------
sjtgraham
This is rather "embed intermediate representation, extract, run another
target's back end, and link". I was hoping this would be explaining how to go
from ARM by uplifting executable to LLVM IR and retargeting for Intel. This is
notionally already possible with ELF and PE executables using McSema
([https://github.com/trailofbits/mcsema](https://github.com/trailofbits/mcsema)).

If anyone is working on this please email me (address in profile), it's
something we slated for a future research project and I'd love to talk.

~~~
voltagex_
>McSema and remill were developed and are maintained by Trail of Bits, funded
by and used in research for DARPA and the US Department of Defense.

~~~
Twirrim
So?

~~~
richrichardsson
Don’t tell them where the internet came from, there ain’t enough tinfoil in
the world.

------
fiddlerwoaroof
Sounds like we're reinventing the AS/400 piecemeal:

[https://en.wikipedia.org/wiki/IBM_System_i#Instruction_set](https://en.wikipedia.org/wiki/IBM_System_i#Instruction_set)

[http://ibmsystemsmag.com/blogs/you-and-i/archive/timi-
protec...](http://ibmsystemsmag.com/blogs/you-and-i/archive/timi-protecting-
investments-and-integrity-in-ibm-i/)

------
saagarjha
I would be _very_ surprised (and impressed!) if Apple managed to pull this
off. With the bitcode transition on watchOS Apple had full control over the
ABI and architecture that they were going to target: this isn't the case for
x86. Sure, this works for the very simple case presented here, but I forsee it
quickly breaking down for any non-trivial application. At the very least, it
will not work correctly on _every_ application.

------
writepub
Alternatives:

1\. WebAssembly

2\. A subset of LLVM-IR that's architecture independent. PNacl from Google
used this across chip architectures

~~~
saagarjha
Neither of these would help migrate current Mac apps.

~~~
writepub
I meant, they are alternatives for Apple to consider, instead of reinventing
the wheel on a cross architecture IR. Of course they won't help _current_ Mac
apps that don't have IR in those formats

~~~
saagarjha
I don’t think we really have a “cross architecture IR” yet.

~~~
writepub
Who's "we"? If you mean Apple, their IR (bitcode) is alomst a 100% the same as
LLVM-IR, so it is not really Apple's. Aside from WebAssembly and PNacl cited
in my parent comment, there's .net IR, JVM byte code, yada yada yada ..

The universe is teeming with cross architecture IRs. Eventually, LLVM will
have a cross platform LLVM-IR, which will possibly be even more impactful than
WebAssembly has been in it's short lifespan

