diff mbox

xf86-video-intel (git-13461a1): BROKEN with clang-3.2 due to __cpuid() not available?

Message ID CA+icZUWHUJg247UTNkton7YxhFiJtj7z0oxbqCSJ1k+KSazOew@mail.gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sedat Dilek Feb. 26, 2013, 1:20 p.m. UTC
On Tue, Feb 26, 2013 at 1:58 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> On Tue, Feb 26, 2013 at 01:35:51PM +0100, Sedat Dilek wrote:
>> With xf86-video-intel-git13461a1 [1] I see this:
>>
>> [ build-log ]
>> ...
>>   CC     sna_cpu.lo
>> 8 warnings generated.
>>   CC     sna_damage.lo
>>   CC     sna_display.lo
>> sna_cpu.c:47:2: error: implicit declaration of function '__cpuid' is
>> invalid in C99 [-Werror,-Wimplicit-function-declaration]
>>         __cpuid(1, eax, ebx, ecx, edx);
>>         ^
> [snip]
>
>> So, clang should be treated differently?
>
> It doesn't use cpuid.h unless the compiler claims to be gcc >= 4. It
> would appear once again that clang is broken.

Can you explain why clang is BROKEN in your eyes?

So, this cpuid.h is from the compiler's include-dir?
If YES, there is no __cpuid() used/defined in clang's "cpuid.h".
clang has __get_cpuid()...

Substituting like this...


...leads to...

  CC     sna_cpu.lo
sna_cpu.c:47:17: warning: incompatible integer to pointer conversion
passing 'unsigned int' to parameter of type 'unsigned int *'; take the
address with & [-Wint-conversion]
        __get_cpuid(1, eax, ebx, ecx, edx);
                       ^~~
                       &
/opt/llvm/bin/../lib/clang/3.2/include/cpuid.h:28:66: note: passing
argument to parameter 'eax' here
static inline int __get_cpuid (unsigned int level, unsigned int *eax,
                                                                 ^
sna_cpu.c:47:22: warning: incompatible integer to pointer conversion
passing 'unsigned int' to parameter of type 'unsigned int *'; take the
address with & [-Wint-conversion]
        __get_cpuid(1, eax, ebx, ecx, edx);
                            ^~~
                            &
/opt/llvm/bin/../lib/clang/3.2/include/cpuid.h:29:46: note: passing
argument to parameter 'ebx' here
                               unsigned int *ebx, unsigned int *ecx,
                                             ^
sna_cpu.c:47:27: warning: incompatible integer to pointer conversion
passing 'unsigned int' to parameter of type 'unsigned int *'; take the
address with & [-Wint-conversion]
        __get_cpuid(1, eax, ebx, ecx, edx);
                                 ^~~
                                 &
/opt/llvm/bin/../lib/clang/3.2/include/cpuid.h:29:65: note: passing
argument to parameter 'ecx' here
                               unsigned int *ebx, unsigned int *ecx,
                                                                ^
sna_cpu.c:47:32: warning: incompatible integer to pointer conversion
passing 'unsigned int' to parameter of type 'unsigned int *'; take the
address with & [-Wint-conversion]
        __get_cpuid(1, eax, ebx, ecx, edx);
                                      ^~~
                                      &
/opt/llvm/bin/../lib/clang/3.2/include/cpuid.h:30:46: note: passing
argument to parameter 'edx' here
                               unsigned int *edx) {
                                             ^
sna_cpu.c:49:12: error: use of undeclared identifier 'bit_SSE3'
        if (eax & bit_SSE3)
                  ^
sna_cpu.c:52:12: error: use of undeclared identifier 'bit_SSSE3'
        if (eax & bit_SSSE3)
                  ^
sna_cpu.c:55:12: error: use of undeclared identifier 'bit_SSE4_1'
        if (eax & bit_SSE4_1)
                  ^
sna_cpu.c:58:12: error: use of undeclared identifier 'bit_SSE4_2'
        if (eax & bit_SSE4_2)
                  ^
sna_cpu.c:61:12: error: use of undeclared identifier 'bit_AVX'
        if (eax & bit_AVX)
                  ^
sna_cpu.c:64:12: error: use of undeclared identifier 'bit_MMX'
        if (edx & bit_MMX)
                  ^
sna_cpu.c:67:12: error: use of undeclared identifier 'bit_SSE'
        if (edx & bit_SSE)
                  ^
sna_cpu.c:70:12: error: use of undeclared identifier 'bit_SSE2'
        if (edx & bit_SSE2)
                  ^
sna_cpu.c:73:12: error: use of undeclared identifier 'bit_SSE4a'
        if (edx & bit_SSE4a)
                  ^
sna_cpu.c:76:2: error: implicit declaration of function '__cpuid' is
invalid in C99 [-Werror,-Wimplicit-function-declaration]
        __cpuid(7, eax, ebx, ecx, edx);
        ^
4 warnings and 10 errors generated.
make[3]: *** [sna_cpu.lo] Error 1

From my understanding this happens as all those bit_XXX are not
defined in clang's cpuid.h!

Whereas gcc's cpuid.h has them:

$ grep bit_SSE /usr/lib/gcc/x86_64-linux-gnu/4.6/include/cpuid.h
#define bit_SSE3        (1 << 0)
#define bit_SSE4_1      (1 << 19)
#define bit_SSE4_2      (1 << 20)
#define bit_SSE         (1 << 25)
#define bit_SSE2        (1 << 26)
#define bit_SSE4a       (1 << 6)

Did you had a look at the attached cpuid.h files from gcc-4.6 and
llvm-3.2/clang-3.2?

Regards,
- Sedat -

> -Chris
>
> --
> Chris Wilson, Intel Open Source Technology Centre

Comments

Chris Wilson Feb. 26, 2013, 1:33 p.m. UTC | #1
On Tue, Feb 26, 2013 at 02:20:26PM +0100, Sedat Dilek wrote:
> On Tue, Feb 26, 2013 at 1:58 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> > On Tue, Feb 26, 2013 at 01:35:51PM +0100, Sedat Dilek wrote:
> >> With xf86-video-intel-git13461a1 [1] I see this:
> >>
> >> [ build-log ]
> >> ...
> >>   CC     sna_cpu.lo
> >> 8 warnings generated.
> >>   CC     sna_damage.lo
> >>   CC     sna_display.lo
> >> sna_cpu.c:47:2: error: implicit declaration of function '__cpuid' is
> >> invalid in C99 [-Werror,-Wimplicit-function-declaration]
> >>         __cpuid(1, eax, ebx, ecx, edx);
> >>         ^
> > [snip]
> >
> >> So, clang should be treated differently?
> >
> > It doesn't use cpuid.h unless the compiler claims to be gcc >= 4. It
> > would appear once again that clang is broken.
> 
> Can you explain why clang is BROKEN in your eyes?

Because it claims to be gcc 4, yet fails to provide a function/macro
provided by gcc 4.
-Chris
Sedat Dilek Feb. 26, 2013, 1:38 p.m. UTC | #2
On Tue, Feb 26, 2013 at 2:33 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> On Tue, Feb 26, 2013 at 02:20:26PM +0100, Sedat Dilek wrote:
>> On Tue, Feb 26, 2013 at 1:58 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>> > On Tue, Feb 26, 2013 at 01:35:51PM +0100, Sedat Dilek wrote:
>> >> With xf86-video-intel-git13461a1 [1] I see this:
>> >>
>> >> [ build-log ]
>> >> ...
>> >>   CC     sna_cpu.lo
>> >> 8 warnings generated.
>> >>   CC     sna_damage.lo
>> >>   CC     sna_display.lo
>> >> sna_cpu.c:47:2: error: implicit declaration of function '__cpuid' is
>> >> invalid in C99 [-Werror,-Wimplicit-function-declaration]
>> >>         __cpuid(1, eax, ebx, ecx, edx);
>> >>         ^
>> > [snip]
>> >
>> >> So, clang should be treated differently?
>> >
>> > It doesn't use cpuid.h unless the compiler claims to be gcc >= 4. It
>> > would appear once again that clang is broken.
>>
>> Can you explain why clang is BROKEN in your eyes?
>
> Because it claims to be gcc 4, yet fails to provide a function/macro
> provided by gcc 4.

Even clang latest-git has same file [1].
Any workaround you can imagine?

- Sedat -

[1] https://github.com/llvm-mirror/clang/blob/master/lib/Headers/cpuid.h

> -Chris
>
> --
> Chris Wilson, Intel Open Source Technology Centre
Chris Wilson Feb. 26, 2013, 1:50 p.m. UTC | #3
On Tue, Feb 26, 2013 at 02:38:14PM +0100, Sedat Dilek wrote:
> On Tue, Feb 26, 2013 at 2:33 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> > On Tue, Feb 26, 2013 at 02:20:26PM +0100, Sedat Dilek wrote:
> >> On Tue, Feb 26, 2013 at 1:58 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> >> > On Tue, Feb 26, 2013 at 01:35:51PM +0100, Sedat Dilek wrote:
> >> >> With xf86-video-intel-git13461a1 [1] I see this:
> >> >>
> >> >> [ build-log ]
> >> >> ...
> >> >>   CC     sna_cpu.lo
> >> >> 8 warnings generated.
> >> >>   CC     sna_damage.lo
> >> >>   CC     sna_display.lo
> >> >> sna_cpu.c:47:2: error: implicit declaration of function '__cpuid' is
> >> >> invalid in C99 [-Werror,-Wimplicit-function-declaration]
> >> >>         __cpuid(1, eax, ebx, ecx, edx);
> >> >>         ^
> >> > [snip]
> >> >
> >> >> So, clang should be treated differently?
> >> >
> >> > It doesn't use cpuid.h unless the compiler claims to be gcc >= 4. It
> >> > would appear once again that clang is broken.
> >>
> >> Can you explain why clang is BROKEN in your eyes?
> >
> > Because it claims to be gcc 4, yet fails to provide a function/macro
> > provided by gcc 4.
> 
> Even clang latest-git has same file [1].
> Any workaround you can imagine?

&& !defined(__clang__)

Based on the bug reports I have, I would strongly recommend not to use
clang as it is known to miscompile the ddx. My outlook is jaundiced
though as people report the failures but not if it ever then succeeds in
not exploding during use.
-Chris
Sedat Dilek Feb. 26, 2013, 2:11 p.m. UTC | #4
On Tue, Feb 26, 2013 at 2:50 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> On Tue, Feb 26, 2013 at 02:38:14PM +0100, Sedat Dilek wrote:
>> On Tue, Feb 26, 2013 at 2:33 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>> > On Tue, Feb 26, 2013 at 02:20:26PM +0100, Sedat Dilek wrote:
>> >> On Tue, Feb 26, 2013 at 1:58 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>> >> > On Tue, Feb 26, 2013 at 01:35:51PM +0100, Sedat Dilek wrote:
>> >> >> With xf86-video-intel-git13461a1 [1] I see this:
>> >> >>
>> >> >> [ build-log ]
>> >> >> ...
>> >> >>   CC     sna_cpu.lo
>> >> >> 8 warnings generated.
>> >> >>   CC     sna_damage.lo
>> >> >>   CC     sna_display.lo
>> >> >> sna_cpu.c:47:2: error: implicit declaration of function '__cpuid' is
>> >> >> invalid in C99 [-Werror,-Wimplicit-function-declaration]
>> >> >>         __cpuid(1, eax, ebx, ecx, edx);
>> >> >>         ^
>> >> > [snip]
>> >> >
>> >> >> So, clang should be treated differently?
>> >> >
>> >> > It doesn't use cpuid.h unless the compiler claims to be gcc >= 4. It
>> >> > would appear once again that clang is broken.
>> >>
>> >> Can you explain why clang is BROKEN in your eyes?
>> >
>> > Because it claims to be gcc 4, yet fails to provide a function/macro
>> > provided by gcc 4.
>>
>> Even clang latest-git has same file [1].
>> Any workaround you can imagine?
>
> && !defined(__clang__)
>
> Based on the bug reports I have, I would strongly recommend not to use
> clang as it is known to miscompile the ddx. My outlook is jaundiced
> though as people report the failures but not if it ever then succeeds in
> not exploding during use.

Can you explain what you mean with "miscompilation"?

Attached patch lets me compile intel-ddx with clang-3.2.

- Sedat -

> -Chris
>
> --
> Chris Wilson, Intel Open Source Technology Centre
Chris Wilson Feb. 26, 2013, 2:31 p.m. UTC | #5
On Tue, Feb 26, 2013 at 03:11:50PM +0100, Sedat Dilek wrote:
> On Tue, Feb 26, 2013 at 2:50 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> > On Tue, Feb 26, 2013 at 02:38:14PM +0100, Sedat Dilek wrote:
> >> On Tue, Feb 26, 2013 at 2:33 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> >> > On Tue, Feb 26, 2013 at 02:20:26PM +0100, Sedat Dilek wrote:
> >> >> On Tue, Feb 26, 2013 at 1:58 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> >> >> > On Tue, Feb 26, 2013 at 01:35:51PM +0100, Sedat Dilek wrote:
> >> >> >> With xf86-video-intel-git13461a1 [1] I see this:
> >> >> >>
> >> >> >> [ build-log ]
> >> >> >> ...
> >> >> >>   CC     sna_cpu.lo
> >> >> >> 8 warnings generated.
> >> >> >>   CC     sna_damage.lo
> >> >> >>   CC     sna_display.lo
> >> >> >> sna_cpu.c:47:2: error: implicit declaration of function '__cpuid' is
> >> >> >> invalid in C99 [-Werror,-Wimplicit-function-declaration]
> >> >> >>         __cpuid(1, eax, ebx, ecx, edx);
> >> >> >>         ^
> >> >> > [snip]
> >> >> >
> >> >> >> So, clang should be treated differently?
> >> >> >
> >> >> > It doesn't use cpuid.h unless the compiler claims to be gcc >= 4. It
> >> >> > would appear once again that clang is broken.
> >> >>
> >> >> Can you explain why clang is BROKEN in your eyes?
> >> >
> >> > Because it claims to be gcc 4, yet fails to provide a function/macro
> >> > provided by gcc 4.
> >>
> >> Even clang latest-git has same file [1].
> >> Any workaround you can imagine?
> >
> > && !defined(__clang__)
> >
> > Based on the bug reports I have, I would strongly recommend not to use
> > clang as it is known to miscompile the ddx. My outlook is jaundiced
> > though as people report the failures but not if it ever then succeeds in
> > not exploding during use.
> 
> Can you explain what you mean with "miscompilation"?

It generates invalid object code that cause segfaults during use.

Besides which as you have also demonstrated, it barely understands C.
-Chris
diff mbox

Patch

--- a/src/sna/sna_cpu.c
+++ b/src/sna/sna_cpu.c
@@ -44,7 +44,7 @@  unsigned sna_cpu_detect(void)
        unsigned int eax, ebx, ecx, edx;
        unsigned features = 0;

-       __cpuid(1, eax, ebx, ecx, edx);
+       __get_cpuid(1, eax, ebx, ecx, edx);

        if (eax & bit_SSE3)
                features |= SSE3;