Bug 199186 - Fix sysutils/i7z segfaults and warnings
Summary: Fix sysutils/i7z segfaults and warnings
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Dmitry Marakasov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-05 20:20 UTC by Dimitry Andric
Modified: 2016-09-15 14:08 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (zont)


Attachments
Fix sysutils/i7z segfaults and warnings (8.44 KB, patch)
2015-04-05 20:20 UTC, Dimitry Andric
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric freebsd_committer freebsd_triage 2015-04-05 20:20:24 UTC
Created attachment 155215 [details]
Fix sysutils/i7z segfaults and warnings

I found out that sysutils/i7z segfaults under various conditions, e.g. different compilers and compilation flags.  For example, compiling with clang -O0 almost always works, but as soon as you start optimizing, segfaults occur.
  
There is also a comment in the Makefile about having to disable several gcc optimizations to avoid segfaults.

I did some debugging, and it turns out that the inline cpuid() implementation can inadvertently clobber registers, causing the cpu_heirarchy_info struct in 'chi' to be destroyed.  Later on, this can lead to segfaults.

I replaced the cpuid() implementation by a more standard one, and that solves all crashes for me.  I tried compiling with:

* clang 3.4.1 (on stable/10), with default flags
* clang 3.4.1 (on stable/10), with CPUTYPE=core-avx2
* clang 3.4.1 (on stable/10), with CPUTYPE=core-avx2 and -O3
* gcc 4.2.1 (on stable/10), with default flags
* gcc 4.2.1 (on stable/10), with -O3

There was also no more need to use -fno-schedule-insns2 -fno-schedule-insns -fno-caller-saves for gcc.

In addition, I fixed a number of warnings about printf formats used for time_t, but that is mostly cosmetic.
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2015-04-05 20:21:20 UTC
I forgot to mention that I also compiled with clang trunk r234092, same result.
Comment 2 Dmitry Marakasov freebsd_committer freebsd_triage 2016-09-11 19:18:22 UTC
Maintainer timeout
Comment 3 commit-hook freebsd_committer freebsd_triage 2016-09-11 19:19:19 UTC
A commit references this bug:

Author: amdmi3
Date: Sun Sep 11 19:18:59 UTC 2016
New revision: 421871
URL: https://svnweb.freebsd.org/changeset/ports/421871

Log:
  - Fix broken cpuid implementation to fix segfaults and remove need of optimization removal hacks

  PR:		199186
  Submitted by:	dim
  Approved by:	maintainer timeout (zont, 1 year)

Changes:
  head/sysutils/i7z/Makefile
  head/sysutils/i7z/files/patch-helper_functions.c
  head/sysutils/i7z/files/patch-i7z.c
Comment 4 Dimitry Andric freebsd_committer freebsd_triage 2016-09-11 20:35:53 UTC
Dmitry, can you please also remove the USE_GCC= yes line?  It is no longer needed, the program works fine when compiled with clang.
Comment 5 Anton Saietskii 2016-09-15 14:08:38 UTC
(In reply to Dimitry Andric from comment #4)

I second this. It would be really good because I just don't want to install 200 MiB of crap like GCC just to run i7z.