Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2013-04-15
17:07 • Closed ticket [3601804fff]: platformCPUID segmentation fault on Darwin plus ... artifact: ff843f0779 user: nijtmans
2013-01-27
04:03 • Ticket [3601804fff]: 4 changes artifact: cb95468c38 user: nijtmans
01:41 • Ticket [3601804fff]: 4 changes artifact: 03ae0f474b user: msofer
01:37 • Open ticket [3601804fff]. artifact: fd02cd5780 user: pooryorick
00:00 • Pending ticket [3601804fff]. artifact: 7f0b3cc069 user: nijtmans
2013-01-26
23:43 • Ticket [3601804fff]: 4 changes artifact: b01699beec user: pooryorick
23:14 • Ticket [3601804fff]: 4 changes artifact: 2a9a835981 user: pooryorick
22:08 • Ticket [3601804fff]: 4 changes artifact: 2f84cfc317 user: nijtmans
20:36 • Ticket [3601804fff]: 1 change artifact: 5850f73c1a user: pooryorick
02:53 • Ticket [3601804fff]: 4 changes artifact: ac83b0eb54 user: andreas_kupries
02:39 • Open ticket [3601804fff]. artifact: b094044cbb user: pooryorick
02:39 • Ticket [3601804fff]: 4 changes artifact: 52c9df3d35 user: pooryorick
2013-01-25
05:04 • Pending ticket [3601804fff]. artifact: 2cfffad539 user: nijtmans
04:49 • Ticket [3601804fff]: 4 changes artifact: 21013f837f user: nijtmans
04:35 • Open ticket [3601804fff]. artifact: 36b533e8dd user: nijtmans
2013-01-23
05:00 • Closed ticket [3601804fff]. artifact: ee944cc2f5 user: nijtmans
02:54 • Ticket [3601804fff]: 6 changes artifact: 8ddcd07a7a user: dgp
2013-01-22
21:58
Bug [3601804]: platformCPUID segmentation fault on Darwin check-in: 8e83219e38 user: jan.nijtmans tags: trunk
21:57
Bug [3601804]: platformCPUID segmentation fault on Darwin check-in: f3509c3d35 user: jan.nijtmans tags: core-8-5-branch
21:56
Bug [3601804]: platformCPUID segmentation fault on Darwin check-in: 273bbe926d user: jan.nijtmans tags: core-8-4-branch
19:49 • New ticket [3601804fff] platformCPUID segmentation fault on Darwin. artifact: ec47f02424 user: pooryorick

platformCPUID segmentation fault on Darwin

Closed / Fixed3601804fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 14 years ago
Descriptionplain2013-01-22 19:49:45
platform-3.1 results in segmentation fault.  the CPUID instruction is documented to clobber eax, ebx, ecx, and edx.  The code clobbers edi, so chaning the list of clobbers in the assembly code in TclWinCPUID may be a good fix for the problem.  It cured the segmentation fault in my case:

"edi","ebx","ecx","edx"

"eax" does not need to be listed, since the code expects it to be clobbered.
dgpplain2013-01-23 02:54:24
Passing to test originator.
nijtmansplain2013-01-23 05:00:30
Good analysis, Thanks! However, ecx and edx are
already output registers, so they cannot be mentioned
twice. gcc will complain with "can’t find a register in class ‘DREG’ while reloading ‘asm’"

However, "ebx" was indeed missing as clobber register.

Fixed now in core-8-4-branch, core-8-5-branch and trunk.
nijtmansplain2013-01-25 04:35:34
Had to revert the change on all branches: on i386,
ebx is the PIC register, which cannot be used
in assembler. The asm code already saves
ebx before the cpuid, and restores it afterwards,
so in reality ebx is not clobbered at all: The
original code was correct......

Poor, what platform are you using?
nijtmansplain2013-01-25 04:49:30
>Poor, what platform are you using?

Just read from the title that it was Darwin..... What version?
nijtmansplain2013-01-25 05:04:14
Found some other cpuid example code for Darwin. Committed a version now that doesn't use the edi register any more.

Does that help?
pooryorickplain2013-01-26 02:39:14
This host is Mac OS X 10.6.8 (Darwin 10.8.0).  Still getting a segmentation fault with your latest changes.
pooryorick Open ticket [3601804fff]. [History diff]2013-01-26 02:39:15
andreas_kupriesplain2013-01-26 02:53:54
Where and why do we need this CPUID stuff in the Tcl core ?
pooryorick Ticket [3601804fff]: 1 change [History diff]2013-01-26 20:36:05
nijtmansplain2013-01-26 22:08:45
The CPUID stuff came in the core for Cygwin, but
actually it's processor-specific, not OS-specific. So it
should simply work fine on any Intel or compatible
processor, even on Darwin and Solaris.

My big question is: Why is pooryorick the only
one getting a segfault? This code is already in
for more than half a year, and nobody else
noticed a segmentation fault on Darwin
in any of the past releases.

This sounds to me like a "Works for Me", but
I'm willing to give it some more time until
someone comes up with a bright idea
what's going on here. My best guess would
be a buggy compiler.

Regards,
       Jan Nijtmans
pooryorickplain2013-01-26 23:14:15
I've found that using the 64-bit register names rbx and rsi with Jan's latest changes resolves  the segmentation fault problem.  I think the same would probably be true with the original code.
pooryorickplain2013-01-26 23:43:52
Here is an option that specifies fewer registers:

        __asm__ __volatile__(
                "pushq %%rbx     \n\t" /* save %rbx */
                "cpuid            \n\t"
                "movl %%ebx ,%[rbx]  \n\t" /* write the result into output var */
                "popq %%rbx \n\t"
                : "=a"(regs[0]), [rbx] "=r"(regs[1]), "=c"(regs[2]), "=d"(regs[3])
                : "a"(index));
nijtmansplain2013-01-27 00:00:21
So, that's the point:  the problem only occurs on 64-bit Darwin. This
means that we cannot have the same assembler-code in 32-bit
and 64-bit machines.

Should be fixed now on all branches.

Thanks!
pooryorickplain2013-01-27 01:37:26
I think configure.in needs to be updated as well.
msoferplain2013-01-27 01:41:03
Shouldn't this code be ifdef'ed out of the core for all non-cygwin builds? Why is it needed at all?
nijtmansplain2013-01-27 04:03:43
> Why is it needed at all?
It could be needed by any code which wants to detect what
kind of processor the system has. Currently, only "clock" is
using it on Windows, but any platform could use it, provided
the processor is Intel-compatible. See also TIP #377, which
was rejected at that time, but it could easily be implemented
for Intel based on cpuid.
> I think configure.in needs to be updated as well.
No, the problem here can only be detected at run-time,
and "configure" doesn't run the code. So there is
no way configure could detect this.
>Shouldn't this code be ifdef'ed out ...
Yes, it should be ifdefed out if the processor is not
Intel, that's exactly what "configure" does.

The problem that pouryorick found has no
relation with cpuid, it's the code that gcc
generates around it which is problematic.
The compiler option -fPIC needs a special
register, and when cpuid uses the same
register, that's the problem that needs to
be worked around. Without -fPIC it would
work fine without any of those tricks.

So, I' glad that this is fixed now. Case closed.
nijtmansplain2013-04-15 17:07:16
allow_comments - 1
Log in (anonymous is fine) to add a comment.