Porting GCC to new architectures [closed]

半城伤御伤魂 提交于 2019-12-29 08:22:21

问题


How do I go about porting gcc to a new architecture? I am specifically interested in the following architectures:

  • ARM (TI OMAPs)
  • TI MSP430
  • x86

but guidance on how to port to any architecture would go some way to solving my problem.


回答1:


Learning to port gcc is going to be a significantly non-trivial task. As a rough guide of what to expect, you will need to know:

  • The target architecture inside out. Literally, otherwise how else will you know how to convert C to it?
  • The C standard, so C89, C99 etc.
  • How compilers work. There are whole books on this.

In order to start the process, you would typically start with the C-to-assembly translation on your host architecture, such that you could compile something for the target architecture (but on your host). You would then get to the stage where you can compile a compiler for your target architecture on your host. At this stage, you produce a compiler on the target which can then self-compile, so you now have gcc on the target.

Once this work has been done, actually porting gcc is simply a case of building gcc from the host on the target. If that's all you're interested in, Linux from scratch is a very good guide for doing everything you'll need to do (as gcc would, amongst other things, be a prerequisite for porting the kernel).




回答2:


In all likelihood GCC is already available for the architecture you want, in which case you want GCC as a cross-compiler (f.e. on a x86 machine with Windows, use gcc to cross-compile for ARM chips). You can see the targets for gcc here.

Note that in all likelihood you will need to compile GCC yourself with that target.

BTW, what is your target architecture?



来源:https://stackoverflow.com/questions/6245481/porting-gcc-to-new-architectures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!