Lorenzo Laneve via llvm-dev
2016-Jun-06 22:06 UTC
[llvm-dev] Compiling for more than one target at once
Can a front-end use the same IR modules to compile a copy of the object codes for more than one target without having to recreate the module? Can LLVM IR modules be compiled for more than one target simply by switching their datalayout and triples? Does the target-independency really exist or there are little things in the code that may change depending on the target? (I'm not talking about C macros).
Tim Northover via llvm-dev
2016-Jun-06 23:46 UTC
[llvm-dev] Compiling for more than one target at once
On 6 June 2016 at 15:06, Lorenzo Laneve via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Does the target-independency really exist or there are little things in the code that may change depending on the target? (I'm not talking about C macros).Lots of little things can vary and make them incompatible. Off the top of my head: + Clang knows the size and alignment of types and inserts it directly in many places (sizeof, for example). + Clang emits custom (target-dependent) code for function argument and return types so that it can follow the C ABI. + va_arg is similar on many targets. + The underlying type (int, long, ...) gets mangled into C++ names, so variation in just what int32_t and so on is can break linking. + You say you're not talking about C macros, but there are obviously countless ways they can completely mess up target independence without even trying. Obviously these apply mostly to C and C++, if you're designing a language from scratch and have no need to follow any platform's specific ABI it can be made to work (you essentially define the ABI by whatever code gets generated). Cheers. Tim.