Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 593336 - games-emulation/pcsx2-1.4.0 - asm clobbers PIC register
Summary: games-emulation/pcsx2-1.4.0 - asm clobbers PIC register
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: nE0sIghT
URL:
Whiteboard:
Keywords: NeedPatch
Depends on:
Blocks:
 
Reported: 2016-09-09 23:25 UTC by Alex
Modified: 2018-03-17 17:14 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex 2016-09-09 23:25:17 UTC
Hello.
Emerging pcsx2 on hardened gives this error:


In file included from /var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/include/Pcsx2Defs.h:31:0,
                 from /var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/src/x86emitter/PrecompiledHeader.h:23,
                 from /var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/src/x86emitter/cpudetect.cpp:16:
/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/include/intrin_x86.h: In member function ‘void x86capabilities::Identify()’:
/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/include/intrin_x86.h:99:127: error: inconsistent operand constraints in an ‘asm’
  __asm__ __volatile__( "cpuid;" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
                                                                                                                               ^
/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/include/intrin_x86.h:99:127: error: inconsistent operand constraints in an ‘asm’
  __asm__ __volatile__( "cpuid;" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
                                                                                                                               ^
/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/include/intrin_x86.h:104:137: error: inconsistent operand constraints in an ‘asm’
  __asm__ __volatile__( "cpuid;" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (level), "c" (count));
                                                                                                                                         ^
/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/include/intrin_x86.h:99:127: error: inconsistent operand constraints in an ‘asm’
  __asm__ __volatile__( "cpuid;" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
                                                                                                                               ^
/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/include/intrin_x86.h:99:127: error: inconsistent operand constraints in an ‘asm’
  __asm__ __volatile__( "cpuid;" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
                                                                                                                               ^
/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/include/intrin_x86.h:99:127: error: inconsistent operand constraints in an ‘asm’
  __asm__ __volatile__( "cpuid;" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
                                                                                                                               ^
/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/include/intrin_x86.h:99:127: error: inconsistent operand constraints in an ‘asm’
  __asm__ __volatile__( "cpuid;" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
                                                                                                                               ^
/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/common/include/intrin_x86.h:99:127: error: inconsistent operand constraints in an ‘asm’
  __asm__ __volatile__( "cpuid;" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));


After some searching I figured out this is because of cpuid instruction using ebx register for returning and PIC wants it for storing global offset table. 
This can be fixed with following patch:

--- common/include/intrin_x86.h.old	2016-09-10 02:05:53.493312954 +0300
+++ common/include/intrin_x86.h	2016-09-10 02:18:10.615282126 +0300
@@ -96,12 +96,20 @@
 /*** System information ***/
 static __inline__ __attribute__((always_inline)) void __cpuid(int CPUInfo[], const int InfoType)
 {
-	__asm__ __volatile__( "cpuid;" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
+#if defined(__PIC__)
+	__asm__ __volatile__("mov %%ebx, %%edi; cpuid; xchgl %%ebx, %%edi;" : "=a" (CPUInfo[0]), "=D" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
+#else
+	__asm__ __volatile__("cpuid" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType));
+#endif
 }
 
 static __inline__ __attribute__((always_inline)) void __cpuidex(int CPUInfo[], const int level, const int count)
 {
-	__asm__ __volatile__( "cpuid;" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (level), "c" (count));
+#if defined(__PIC__)
+	__asm__ __volatile__("mov %%ebx, %%edi; cpuid; xchgl %%ebx, %%edi;" : "=a" (CPUInfo[0]), "=D" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (level), "c" (count));
+#else
+	__asm__ __volatile__("cpuid" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (level), "c" (count));
+#endif
 }
 
 static __inline__ __attribute__((always_inline)) unsigned long long _xgetbv(unsigned int index)



However it still fails to build later with this error:

/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/pcsx2/IPU/yuv2rgb.cpp: In function ‘void yuv2rgb_sse2()’:
/var/tmp/portage/games-emulation/pcsx2-1.4.0/work/pcsx2-1.4.0/pcsx2/IPU/yuv2rgb.cpp:402:3: error: ‘asm’ operand has impossible constraints
  );
   ^
pcsx2/CMakeFiles/PCSX2.dir/build.make:4206: recipe for target 'pcsx2/CMakeFiles/PCSX2.dir/IPU/yuv2rgb.cpp.o' failed


And I am not smart enough to fix that.
Thank you for your attention.

Reproducible: Always

Steps to Reproduce:
1. emerge pcsx2
2.
3.
Actual Results:  
compilation fails with error

Expected Results:  
pcsx2 is emerged

emerge --info output:
Portage 2.2.28 (python 2.7.10-final-0, hardened/linux/amd64/selinux, gcc-4.9.3, glibc-2.22-r4, 4.4.8-hardened-r1 x86_64)
=================================================================
System uname: Linux-4.4.8-hardened-r1-x86_64-Intel-R-_Core-TM-_i7-3632QM_CPU_@_2.20GHz-with-gentoo-2.2
KiB Mem:     8039784 total,   1757028 free
KiB Swap:    1048572 total,    858484 free
Timestamp of repository gentoo: Wed, 07 Sep 2016 21:30:01 +0000
sh bash 4.3_p42-r1
ld GNU ld (Gentoo 2.25.1 p1.1) 2.25.1
distcc 3.2rc1 x86_64-pc-linux-gnu [disabled]
app-shells/bash:          4.3_p42-r1::gentoo
dev-java/java-config:     2.2.0-r3::gentoo
dev-lang/perl:            5.20.2::gentoo
dev-lang/python:          2.7.10-r1::gentoo, 3.4.3-r1::gentoo
dev-util/cmake:           3.5.2-r1::gentoo
dev-util/pkgconfig:       0.28-r2::gentoo
sys-apps/baselayout:      2.2::gentoo
sys-apps/openrc:          0.21.3::gentoo
sys-apps/sandbox:         2.10-r1::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69::gentoo
sys-devel/automake:       1.11.6-r1::gentoo, 1.12.6::gentoo, 1.14.1::gentoo, 1.15::gentoo
sys-devel/binutils:       2.25.1-r1::gentoo
sys-devel/gcc:            4.9.3::gentoo
sys-devel/gcc-config:     1.7.3::gentoo
sys-devel/libtool:        2.4.6::gentoo
sys-devel/make:           4.1-r1::gentoo
sys-kernel/linux-headers: 4.3::gentoo (virtual/os-headers)
sys-libs/glibc:           2.22-r4::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

rion
    location: /var/lib/layman/rion
    masters: gentoo
    priority: 1

pzskc383
    location: /home/maniac/dev/overlay
    masters: gentoo
    priority: 2

crossdev
    location: /var/lib/layman/cross-arm
    masters: gentoo rion
    priority: 3

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.6/ext-active/ /etc/php/cgi-php5.6/ext-active/ /etc/php/cli-php5.6/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -pipe"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS=" --quiet-build=y"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox selinux sesandbox sfperms splitdebug strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j3 -l4"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X acl amd64 audit avx bash-completion berkdb bzip2 caps cli consolekit cracklib crypt cxx dbus dri flac gdbm hardened iconv idn ipv6 jpeg justify libnotify mmx mmxext modules mp3 multilib ncurses nls nptl offensive ogg open_perms opengl openmp pam pax_kernel pcre pic pie png policykit qt3support readline sasl seccomp selinux session sse sse2 ssl ssp startup-notification tcpd theora threads unconfined unicode urandom vim-syntax webm webp x264 xattr xtpax zlib zsh-completion" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2 canon" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="evdev keyboard mouse synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="en" NGINX_MODULES_HTTP="dav dav_ext access auth_basic fancyindex fastcgi geo gzip limit_conn limit_req lua map memcached mp4 flv proxy referer rewrite scgi split_clients stub_status userid uwsgi upstream_ip_hash spdy upload_progress secure_link charset browser upstream_check push headers_more" OFFICE_IMPLEMENTATION="libreoffice" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python3_4 python2_7" QEMU_SOFTMMU_TARGETS="i386 x86_64 arm alpha ppc" QEMU_USER_TARGETS="i386 x86_64 arm" RUBY_TARGETS="ruby21" USERLAND="GNU" UWSGI_PLUGINS="cache corerouter fastrouter http logfile logsocket rawrouter router_basicauth router_cache router_expires router_hash router_http router_redirect router_rewrite router_uwsgi signal sslrouter symcall syslog transformation_chunked transformation_gzip transformation_offload transformation_tofile" VIDEO_CARDS="radeon r600 intel i965" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON

gcc -v output:
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.3/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.9.3/work/gcc-4.9.3/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo Hardened 4.9.3 p1.5, pie-0.6.4' --enable-esp --enable-libstdcxx-time --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-altivec --disable-fixed-point --enable-targets=all --disable-libgcj --enable-libgomp --disable-libmudflap --disable-libssp --disable-libcilkrts --disable-vtable-verify --disable-libvtv --enable-lto --without-cloog --disable-libsanitizer
Thread model: posix
gcc version 4.9.3 (Gentoo Hardened 4.9.3 p1.5, pie-0.6.4)
Comment 1 nE0sIghT 2016-09-24 10:34:29 UTC
Hi,

I need to setup hardened test stand - it will take a time.
Comment 2 Alex 2016-09-26 09:22:17 UTC
Hi, 

just FIY: current git master (-9999 ebuild) builds fine, maybe we could backport offending optimizations to 1.4.0.
Comment 3 nE0sIghT 2016-12-11 05:53:52 UTC
"common/include/intrin_x86.h" was completelly dropped from master in favor of new "common/include/x86emitter/x86_intrin.h" which includes compiler's "x86intrin.h" as I see.
Maybe we can use new file instead of old one...
Comment 4 Alex 2018-03-17 17:14:54 UTC
Well, I just tried building 1.4.0 on current hardened amd64 profile and it worked just fine.

Given that no one else have got this error in more than year, I'm closing this report as resolved.