Which compiler compiled system?

Matthew Story matthewstory at gmail.com
Mon Mar 12 23:16:06 UTC 2012


On Mon, Mar 12, 2012 at 6:55 PM, Da Rock <
freebsd-questions at herveybayaustralia.com.au> wrote:

> On 03/13/12 06:49, Pierre-Luc Drouin wrote:
>
>> If Java is broken, then you know FreeBSD was compiled with clang...
>>
> I wouldn't say that is categorical.
>
>
>> On Mon, Mar 12, 2012 at 3:45 PM,<kaltheat at googlemail.com>  wrote:
>>
>>  Hi,
>>>
>>> Is there a way to determine whether a FreeBSD-system was compiled with
>>> gcc
>>> or clang?
>>> I thought of some libs or so that might significantly differ.
>>>
>>
strings on a clang v. gcc compile shows no differences (at least in my
tests), but binaries compiled with clang and gcc seem to reliable show
differences at the 25th character of the compiled program, although the
differences at the 25th character are not consistent across programs ...

$ # one example
$ gcc -Wall -o hello_world.gcc hello_world.c
$ clang -Wall -o hello_world.clang hello_world.c
$ cmp hello_world.gcc hello_world.clang
hello_world.gcc hello_world.clang differ: char 25, line 1

this does suggest that if you know gcc and clang are the only 2 options for
compilation on a system, and you have a version compiled with the same
flags on the same system from a known compiler, you should be able to
reliably detect compilation by the other compiler using cmp ... although
this may be more or less meaningless to you depending on how much control
you have over the variables (e.g. binaries built on the same system,
ability to know which compilation flags were sent at compile time, etc ...):

$ # hello_world here is ``in the wild''
$ clang -Wall -o hello_world.clang hello_world.c
$ if cmp hello_world.clang hello_world > /dev/null 2> /dev/null; then echo
"built with clang"; else echo "built with gcc"; fi
built with clang


>
>>> Regards,
>>> kaltheat
>>>
>>> ______________________________**_________________
>>> freebsd-questions at freebsd.org mailing list
>>> http://lists.freebsd.org/**mailman/listinfo/freebsd-**questions<http://lists.freebsd.org/mailman/listinfo/freebsd-questions>
>>> To unsubscribe, send any mail to "
>>> freebsd-questions-unsubscribe@**freebsd.org<freebsd-questions-unsubscribe at freebsd.org>
>>> "
>>>
>>>  ______________________________**_________________
>> freebsd-questions at freebsd.org mailing list
>> http://lists.freebsd.org/**mailman/listinfo/freebsd-**questions<http://lists.freebsd.org/mailman/listinfo/freebsd-questions>
>> To unsubscribe, send any mail to "freebsd-questions-**
>> unsubscribe at freebsd.org <freebsd-questions-unsubscribe at freebsd.org>"
>>
>
> ______________________________**_________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/**mailman/listinfo/freebsd-**questions<http://lists.freebsd.org/mailman/listinfo/freebsd-questions>
> To unsubscribe, send any mail to "freebsd-questions-**
> unsubscribe at freebsd.org <freebsd-questions-unsubscribe at freebsd.org>"
>



-- 
regards,
matt


More information about the freebsd-questions mailing list