Hey all,
Would someone help me understand the difference between “porting” and “cross-compiling”? I did some googling and YouTubing but it seems some people don’t make a distinction, some do, and some talk about crossing to a different OS and some to a different chip architecture.
PS: I have also read that porting/cross-compiling takes a very long time and can be a hard task – apparently Google Chrome and Firefox both have assembly in them but why was it so important to put assembly in them? It has to be super important given that they knew it would take a long time to port/cross compile to a different chip than the original one right?!
Thanks so much!
Thanks!!
In: Technology
Using video games as an example, current and last gen Playstations and Xboxs both ran basically the same architectures, so porting games between them basically just consisted of changes to make the games work with their different operating systems and hardware specs.
A PS3 and a Xbox 360 ran on completely different architectures. Making a game for one of them and then altering it to work on the other is still “porting”, but since the architectures are different, there may be some cross compiling needed as well.
Edit: Regarding Assembly, Assembly is simply an extremely low level programming language. It is specific to each CPU architecture, though syntax may be similar or the same across platforms. It’s as close to machine code as you can get without being machine code. Assembly is generally only used when the operating system doesn’t have a particular function that you need, and/or you’re very interested in maximum performance for a particular function. Chrome and Firefox both using Assembly is not particularly noteworthy.
porting is making changes to the code to make something run on a different platform, it could be making a windows program run on linux or making a x86 program run on arm. Or something like making code that run on one Arduino board run on a different arduino board with a different pinout
cross compiling is compiling code on one platform to run on a different platform, like for example compiling ARM code for a RPI on a pc instead of compiling the code on the RPI itself,or compiling AVR code for an arduino on a PC
As an analogy: cross-compiling is taking a product, translating the text on the box into German, and trying to sell the product in Germany. That might work for some products, like a bicycle for example.
Porting is taking a product and rethinking it for a different market. That might be needed for something like a washing machine, where everything from the power outlet shape to typical expectations of appliances might be completely different in Germany.
To answer your second question: the vast majority of the code in Chrome and FIrefox is written in a high-level language that can be cross-compiled to any processor architecture like x86 or ARM. Only a tiny fraction is written in assembly language and that’s usually done for performance reasons, in rare cases where that’s the only way to make code optimally efficient. I doubt that would be a large roadblock.
However, Chrome and Firefox have lots of code that’s specific to each operating system. That’s because operating systems provide all of the functionality needed to do just about anything fundamental on a computer, including interacting with hardware (your disk, display, keyboard, mouse, network, etc.). Each operating system has completely different functions you need to call to accomplish those tasks.
Chrome and Firefox were both designed from the start to be ported to multiple operating systems. However, the work needed to port to a new operating system is massive because browsers are large and complex and there are probably hundreds of thousands of lines of operating-system-specific code that needs to be ported.
Generally porting creates a separate codebase that modifies the original code to suit the new architecture.
Cross-compiling means a single codebase can be compiled into the new architecture. Differences between the original architecture and the new architecture maybe handled by the cross compiler or conditional compilation code in the codebase.
Cross-compiling is when you write code for one platform on a different platform than the intended target.
For example: if i write a program on my linux machine for windows, ill have to use cross compilation to actually get the win32 api calls to work.
-or-
If i write a program for my ARM rasberry pi on my x86_64 laptop, ill have to use cross compilation because ARM bytecode is different from x86_64 bytecode.
Porting is when the underlying code has to be changed in order to get it to work on another platform.
For example: if i write a native windows app, it will use the win32 api’s system calls to do different things. If i want to use that app on linux natively, ill have to go in and rewrite the underlying code so that it uses linux kernel syscalls instead of windows’.
Overall:
With a simple enough program that only uses standard libraries, cross compilation can be pretty simple and is mostly a matter of using a different compiler or issuing unusual directives to the compiler.
Porting on the other hand is a manual process where you may have to significantly rewrite the underlying code.
>the difference between “porting” and “cross-compiling”?
Cross compiling is specifically when you use one computer to compile code for a different computer. One where the code can’t run on the one compiling it.
Porting would be getting code written for one computer/platform/whatever and getting it to run on something else.
You can take some Linux source code, work on it on a Windows box and change enough to get it to run. That’s porting without cross compiling.
You can also take some Linux code, work on it within Linux and compile with gcc targeting windows, or embedded devices, or toothbrushes, and get it to run on those. That’s porting with cross compiling.
And embedded devs regularly cross-compile code that was never meant to run anywhere else. Cross-compiling without porting.
Latest Answers