clang PCH and strace

Why would strace (on Linux) cause clang to fail to read a PCH? :

1. $ clang -cc1 -emit-pch -I/tmp/ /tmp/m.h -o m.pch
   $ clang -cc1 -include-pch m.pch -I/tmp/ /tmp/m.c

2. $ clang -cc1 -emit-pch -I/tmp/ /tmp/m.h -o m.pch
   $ strace -o bla -e open clang -cc1 -include-pch m.pch -I/tmp/ /tmp/m.c
   error: PCH file uses a newer PCH format that cannot be read
   1 error generated.

1st command works, 2nd command (with strace) fails.

strace also causes clang to generate a bad PCH:

1. $ clang -cc1 -emit-pch -I/tmp/ /tmp/m.h -o m.pch
   $ clang -cc1 -include-pch m.pch -I/tmp/ /tmp/m.c

2. $ strace -o bla clang -cc1 -emit-pch -I/tmp/ /tmp/m.h -o m.pch
   $ clang -cc1 -include-pch m.pch -I/tmp/ /tmp/m.c
   error: PCH file uses an older PCH format that is no longer supported
   1 error generated.

Source:
    #include "m.h"
    int main() {
        return foo();
    }

Header:
    #ifndef M_H
    #define M_H
    int foo();
    #endif

Thanks,
-Dawn

I give you a 99% probability of the strace command picking up a different clang executable.

Sebastian

You can confirm that by doing

strace clang --version

and

clang --version

-- Jean-Daniel

Yup, that was it. (Doh!) Thanks.
-Dawn

on 09/28/2010 02:06 PM Sebastian Redl said the following:

Why would strace (on Linux) cause clang to fail to read a PCH? :

[...]

I give you a 99% probability of the strace command picking up a different clang executable.

Why would that be the case? Or, restated, under what circumstances
would this be true?

--- Vladimir

If strace and direct invocation are looking at different PATH variables, for example.

Sebastian

Try invoking 'which clang' with and without strace.

Sebastian

on 09/28/2010 04:13 PM Sebastian Redl said the following:

I give you a 99% probability of the strace command picking up a different clang executable.

Why would that be the case? Or, restated, under what circumstances
would this be true?

If strace and direct invocation are looking at different PATH variables, for example.

Obviously.

I was assuming --- apparently incorrectly --- a single shell with no
intervening command that changes PATH. With a different shell, all
bets are off. The other shell could be on a completely different
machine, for instance.

--- Vladimir

It doesn't have to be. If in your current shell you have set PATH, but haven't exported it, then the command 'clang' would look in the PATH you have set, but 'strace clang' would look for strace in the PATH you have set, but strace wouldn't inherit that PATH, so it would fall back to the system default.

Sebastian

on 10/01/2010 11:11 AM Sebastian Redl said the following:

I was assuming --- apparently incorrectly --- a single shell with no
intervening command that changes PATH. With a different shell, all
bets are off. The other shell could be on a completely different
machine, for instance.

It doesn't have to be. If in your current shell you have set PATH, but haven't exported it, then the command 'clang' would look in the PATH you have set, but 'strace clang' would look for strace in the PATH you have set, but strace wouldn't inherit that PATH, so it would fall back to the system default.

(Score:4, Informative)

--- Vladimir