From nobody@FreeBSD.org  Thu Jan 16 18:31:41 2014
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 38D2D470
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 16 Jan 2014 18:31:41 +0000 (UTC)
Received: from oldred.freebsd.org (oldred.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 24C9C19E6
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 16 Jan 2014 18:31:41 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id s0GIVeNC068421
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 16 Jan 2014 18:31:40 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id s0GIVeK5068412;
	Thu, 16 Jan 2014 18:31:40 GMT
	(envelope-from nobody)
Message-Id: <201401161831.s0GIVeK5068412@oldred.freebsd.org>
Date: Thu, 16 Jan 2014 18:31:40 GMT
From: Francois Tigeot <ftigeot@wolfpond.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Programs using security/cryptopp crash with illegal instructions
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         185826
>Category:       ports
>Synopsis:       Programs using security/cryptopp crash with illegal instructions
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 16 18:40:00 UTC 2014
>Closed-Date:    Wed Feb 05 19:32:12 UTC 2014
>Last-Modified:  Wed Feb 05 19:32:12 UTC 2014
>Originator:     Francois Tigeot
>Release:        DragonFly 3.7-DEVELOPMENT
>Organization:
>Environment:
DragonFly sekishi.zefyris.com 3.7-DEVELOPMENT DragonFly v3.7.1.509.g52b954-DEVELOPMENT #375: Sun Jan 12 13:04:22 CET 2014     ftigeot@sekishi.zefyris.com:/usr/obj/usr/src/sys/X86_64_GENERIC  x86_64
>Description:
While investigating net-p2p/amule crashes, I found out the security/cryptopp package tried to use illegal instructions.

This occurs in the CryptoPP::RandomNumberGenerator::GenerateWord32(unsigned int, unsigned int) method.

And is caused by the use of the shrx x86 instruction:

(gdb output)
Program received signal SIGILL, Illegal instruction.
0x0000000000626b88 in CryptoPP::RandomNumberGenerator::GenerateWord32(unsigned int, unsigned int) ()
=> 0x0000000000626b88 <_ZN8CryptoPP21RandomNumberGenerator14GenerateWord32Ejj+40>: c4 e2 73 f7 c3 shrx %ecx,%ebx,%eax

shrx is a new Haswell instruction, which means programs using the cryptopp library will crash on all machines not using this latest Intel processor generation.


>How-To-Repeat:
Build a cryptopp package on a Haswell CPU and try to use it on a machine with a previous generation CPU.
>Fix:
The root of the issue comes from the CXXFLAGS line in GNUmakefile.
Changing it to stop generating instructions for a particular CPU model (removing "-native") will fix packages once and for all. 

The attached patch fixes the issue for me.

Patch attached with submission follows:

--- GNUmakefile.orig	2014-01-16 18:14:51.544855000 +0000
+++ GNUmakefile
@@ -38,8 +38,6 @@ GAS219_OR_LATER = $(shell $(CXX) -xc -c
 ifneq ($(GCC42_OR_LATER),0)
 ifeq ($(UNAME),Darwin)
 CXXFLAGS += -arch x86_64 -arch i386
-else
-CXXFLAGS += -march=native
 endif
 endif
 


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->delphij 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Thu Jan 16 18:40:08 UTC 2014 
Responsible-Changed-Why:  
Over to maintainer (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=185826 
Responsible-Changed-From-To: delphij->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Wed Feb 5 19:21:28 UTC 2014 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=185826 
State-Changed-From-To: open->closed 
State-Changed-By: eadler 
State-Changed-When: Wed Feb 5 19:32:10 UTC 2014 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=185826 
>Unformatted:
