NetBSD Problem Report #49741

From jarle@festningen.uninett.no  Tue Mar 10 16:54:24 2015
Return-Path: <jarle@festningen.uninett.no>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id A6549A654F
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 10 Mar 2015 16:54:24 +0000 (UTC)
Message-Id: <20150310165418.E966080ADA@festningen.uninett.no>
Date: Tue, 10 Mar 2015 17:54:18 +0100 (CET)
From: jarle@uninett.no
Reply-To: jarle@uninett.no
To: gnats-bugs@gnats.NetBSD.org
Subject: Unconditional use of cpuid instruction causes illegal instruction trap
X-Send-Pr-Version: 3.95

>Number:         49741
>Category:       port-i386
>Synopsis:       Unconditional use of cpuid instruction causes illegal instruction trap
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-i386-maintainer
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 10 16:55:00 +0000 2015
>Closed-Date:    Tue Nov 15 10:41:39 +0000 2016
>Last-Modified:  Tue Nov 15 10:41:39 +0000 2016
>Originator:     Jarle Greipsland
>Release:        NetBSD 6.1_STABLE
>Organization:

>Environment:


System: NetBSD darling.urc.uninett.no 7.99.4 NetBSD 7.99.4 (DARLING) #3: Wed Feb 25 16:05:46 CET 2015  jarle@darling.urc.uninett.no:/usr/obj/sys/arch/i386/compile/DARLING i386
Architecture: i386
Machine: i386
>Description:

Install -current on an old i486 system.  Note that all dynamically linked
programs faults with an illegal instruction trap in libgcc_s.so, a dynamic
library with support functions for all dynamically linked programs compiled
by the system's gcc compiler.

The code in the __cpu_indicator_init in
src/external/gpl3/gcc/dist/libgcc/config/i386/cpuinfo.c calls the
__get_cpuid_output function with parameters that makes it always issue the
cpuid instruction.  This instruction is not implemented on the old i486
CPUs, and thus the program executing receives a SIGILL signal (and dies).

>How-To-Repeat:
Install NetBSD/i386 -current on an old system with a real 486 CPU.

>Fix:

I have run my system for more than a week with the patch below applied, and
observed no ill effects.  Someone with more knowledge about Intel
processors and gcc's run time requirements should double check that the
patch makes sense, in particular on more modern CPUs.

Index: external/gpl3/gcc/dist/libgcc/config/i386/cpuinfo.c
===================================================================
RCS file: /cvsroot/src/external/gpl3/gcc/dist/libgcc/config/i386/cpuinfo.c,v
retrieving revision 1.1.1.1
diff -u -u -r1.1.1.1 cpuinfo.c
--- external/gpl3/gcc/dist/libgcc/config/i386/cpuinfo.c 1 Mar 2014 08:41:47 -0000       1.1.1.1
+++ external/gpl3/gcc/dist/libgcc/config/i386/cpuinfo.c 10 Mar 2015 16:51:55 -0000
@@ -281,8 +281,7 @@
   if (__cpu_model.__cpu_vendor)
     return 0;

-  /* Assume cpuid insn present. Run in level 0 to get vendor id. */
-  if (!__get_cpuid_output (0, &eax, &ebx, &ecx, &edx))
+  if (!__get_cpuid_output (1, &eax, &ebx, &ecx, &edx))
     {
       __cpu_model.__cpu_vendor = VENDOR_OTHER;
       return -1;

>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->feedback
State-Changed-By: snj@NetBSD.org
State-Changed-When: Sun, 13 Nov 2016 19:36:21 +0000
State-Changed-Why:
I believe this has been fixed.  Can you please confirm?


From: Jarle Greipsland <jarle@uninett.no>
To: gnats-bugs@NetBSD.org, snj@NetBSD.org
Cc: port-i386-maintainer@netbsd.org, netbsd-bugs@netbsd.org,
 gnats-admin@netbsd.org
Subject: Re: port-i386/49741 (Unconditional use of cpuid instruction causes
 illegal instruction trap)
Date: Tue, 15 Nov 2016 11:39:44 +0100 (CET)

 snj@NetBSD.org writes:
 > Synopsis: Unconditional use of cpuid instruction causes illegal instruction trap
 > 
 > State-Changed-From-To: open->feedback
 > State-Changed-By: snj@NetBSD.org
 > State-Changed-When: Sun, 13 Nov 2016 19:36:21 +0000
 > State-Changed-Why:
 > I believe this has been fixed.  Can you please confirm?
 Yes.  This has been fixed.
 					-jarle

State-Changed-From-To: feedback->closed
State-Changed-By: martin@NetBSD.org
State-Changed-When: Tue, 15 Nov 2016 10:41:39 +0000
State-Changed-Why:
Confirmed fixed


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.