Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does GCC support multiple target architectures?

Is it possible to compile a single gcc (frontend) binary which supports multiple target architectures, which I can select in the command-line, like this:

$ gcc --architecture=linux-i386 ...
$ gcc --architecture=freebsd-arm ...
$ gcc --architecture=darwin-amd64 ...

I know that it's possible build gcc as a cross-compiler, but is it possible to select the target architecture using a command-line flag, without writing a wrapper script which starts different gcc binaries for each architecture?

For i386 and amd64 -m32 and -m64 seem to do the trick, but how do I select ARM etc.? Please note that -march= looked useless to me, I couldn't make it change from i386 to amd64.

like image 337
pts Avatar asked Dec 14 '13 19:12

pts


Video Answer


2 Answers

Short answer is "no", you can't. There are some flavors of cross compilers, but for one binary to be able to support a bunch of targets, it would require the tool to be very bulky in size and requirement for system headers.

like image 169
drivingon9 Avatar answered Oct 21 '22 05:10

drivingon9


Function multi-versioning is there https://gcc.gnu.org/wiki/FunctionMultiVersioning, including automatic dispatching;

Still versioning is manual; automatic multi-versioning for different architectures is not implemented; here's feature request for it https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78464

like image 21
user3556054 Avatar answered Oct 21 '22 05:10

user3556054