Porting GCC to new architectures [closed]

2020-02-13 05:55发布

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.

2条回答
SAY GOODBYE
2楼-- · 2020-02-13 06:24

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?

查看更多
霸刀☆藐视天下
3楼-- · 2020-02-13 06:34

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).

查看更多
登录 后发表回答