This is the mail archive of the
mailing list for the GCC project.
Re: detecting if cross-compiler (in plugin)?
- From: Ian Lance Taylor <iant at google dot com>
- To: Basile Starynkevitch <basile at starynkevitch dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 29 Aug 2012 17:50:18 -0700
- Subject: Re: detecting if cross-compiler (in plugin)?
- References: <20120829085929.GA31368@hector.lesours>
On Wed, Aug 29, 2012 at 1:59 AM, Basile Starynkevitch
> What is the simplest way, for a plugin (and also for a GCC branch),
> to detect if the compiler is straight or not (i.e. cross, that is
> target & host are different, or even canadian-cross).
> I was thinking of some macro in auto-host.h or other header.
> (MELT is, during its building procedure, testing itself by running
> a simple MELT pass on the MELT runtime. Obviously this step makes
> no sense for cross compilers, hence the question)
It sounds like what you want to know is not whether host != target,
but whether build != target. Actually you may want to know whether
the compiler produces executables that run on the build system, but
that is more complicated still--e.g., a cross-compiler from x86_64 to
i386 GNU/Linux can produce executables that run on the build system
even though it is configured as a cross-compiler.
Unfortunately I don't know of any way to check within GCC whether
build == target. It's not something that GCC generally cares about.
One imperfect thing you can test is whether CROSS_DIRECTORY_STRUCTURE
is defined. That is true when host != target.
In general I would support having ways for plugins to detect this sort
of thing, perhaps simply by making the build, host, and target triplet
strings available to the plugin in some way.