linux-tools: PIE fixes and cleanup.

This commit is contained in:
Christian Neukirchen 2016-05-20 13:41:40 +02:00
parent 438c83faaf
commit 975da7cf81
2 changed files with 96 additions and 23 deletions

View File

@ -0,0 +1,76 @@
https://patchwork.kernel.org/patch/2165061/
--- tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
+++ tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c
@@ -130,20 +130,48 @@ void cmdline(int argc, char **argv)
}
}
+static inline void cpuid(unsigned int info, unsigned int *eax,
+ unsigned int *ebx, unsigned int *ecx,
+ unsigned int *edx)
+{
+#if defined(__i386__) || defined(__x86_64__)
+ unsigned int _eax = info, _ebx, _ecx, _edx;
+ asm volatile (
+# ifdef __i386__
+ "xchg %%ebx, %%esi;" /* save ebx (for PIC) */
+ "cpuid;"
+ "xchg %%esi, %%ebx;" /* restore ebx & pass to caller */
+ : "=S" (_ebx),
+#else
+ "cpuid;"
+ : "=b" (_ebx),
+#endif
+ "+a" (_eax), "=c" (_ecx), "=d" (_edx)
+ : /* inputs: eax is handled above */
+ );
+ if (eax)
+ *eax = _eax;
+ if (ebx)
+ *ebx = _ebx;
+ if (ecx)
+ *ecx = _ecx;
+ if (edx)
+ *edx = _edx;
+#endif
+}
+
/*
* validate_cpuid()
* returns on success, quietly exits on failure (make verbose with -v)
*/
void validate_cpuid(void)
{
- unsigned int eax, ebx, ecx, edx, max_level;
+ unsigned int ebx, ecx, edx, max_level;
unsigned int fms, family, model, stepping;
- eax = ebx = ecx = edx = 0;
-
- asm("cpuid" : "=a" (max_level), "=b" (ebx), "=c" (ecx),
- "=d" (edx) : "a" (0));
+ ebx = ecx = edx = 0;
+ cpuid(0, &max_level, &ebx, &ecx, &edx);
if (ebx != 0x756e6547 || edx != 0x49656e69 || ecx != 0x6c65746e) {
if (verbose)
fprintf(stderr, "%.4s%.4s%.4s != GenuineIntel",
@@ -151,7 +179,7 @@ void validate_cpuid(void)
exit(1);
}
- asm("cpuid" : "=a" (fms), "=c" (ecx), "=d" (edx) : "a" (1) : "ebx");
+ cpuid(1, &fms, NULL, NULL, &edx);
family = (fms >> 8) & 0xf;
model = (fms >> 4) & 0xf;
stepping = fms & 0xf;
@@ -173,7 +201,7 @@ void validate_cpuid(void)
* Support for MSR_IA32_ENERGY_PERF_BIAS
* is indicated by CPUID.06H.ECX.bit3
*/
- asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (6));
+ cpuid(6, NULL, NULL, &ecx, NULL);
if (verbose)
printf("CPUID.06H.ECX: 0x%x\n", ecx);
if (!(ecx & (1 << 3))) {

View File

@ -1,14 +1,14 @@
# Template file for 'linux-tools' # Template file for 'linux-tools'
pkgname=linux-tools pkgname=linux-tools
version=4.1 version=4.1
revision=2 revision=3
build_style=meta build_style=meta
wrksrc="linux-${version}" wrksrc="linux-${version}"
short_desc="Linux kernel tools meta-pkg" short_desc="Linux kernel tools meta-pkg"
hostmakedepends="flex perl asciidoc xmlto python automake libtool" hostmakedepends="flex perl asciidoc xmlto python automake libtool"
makedepends="pciutils-devel python-devel libglib-devel libsysfs-devel makedepends="pciutils-devel python-devel libglib-devel libsysfs-devel
elfutils-devel libunwind-devel binutils-devel zlib-devel slang-devel elfutils-devel libunwind-devel binutils-devel zlib-devel slang-devel
eudev-libudev-devel" eudev-libudev-devel liblzma-devel"
depends="cpupower-${version}_${revision} perf-${version}_${revision} usbip-${version}_${revision}" depends="cpupower-${version}_${revision} perf-${version}_${revision} usbip-${version}_${revision}"
maintainer="Juan RP <xtraeme@voidlinux.eu>" maintainer="Juan RP <xtraeme@voidlinux.eu>"
license="GPL-2" license="GPL-2"
@ -18,34 +18,36 @@ checksum=caf51f085aac1e1cea4d00dbbf3093ead07b551fc07b31b2a989c05f8ea72d9f
subpackages="cpupower libcpupower libcpupower-devel libusbip libusbip-devel usbip perf freefall" subpackages="cpupower libcpupower libcpupower-devel libusbip libusbip-devel usbip perf freefall"
if [ "$XBPS_TARGET_MACHINE" = "i686" -o "$XBPS_TARGET_MACHINE" = "x86_64" ]; then case "$XBPS_TARGET_MACHINE" in
i686*|x86_64*)
makedepends+=" libnuma-devel" makedepends+=" libnuma-devel"
depends+=" x86_energy_perf_policy>=${version}" depends+=" x86_energy_perf_policy>=${version}"
subpackages+=" x86_energy_perf_policy" subpackages+=" x86_energy_perf_policy"
nopie="x86_energy_perf_policy.c:154:2: error: PIC register clobbered by 'ebx' in 'asm'" ;;
fi esac
nocross=yes nocross=yes
post_extract() {
sed -i 's/\$(LIBS)/& $(LDFLAGS)/' tools/power/cpupower/bench/Makefile
}
do_build() { do_build() {
cd ${wrksrc}/tools/perf cd ${wrksrc}/tools/perf
make ${makejobs} CC=$CC \ make ${makejobs} CC=$CC LD=$LD CFLAGS="$CFLAGS" EXTRA_CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \
WERROR=0 \ WERROR=0 DESTDIR=${DESTDIR}/usr \
DESTDIR=$DESTDIR \
perfexecdir='lib/perf' \ perfexecdir='lib/perf' \
NO_GTK2=1 \ NO_GTK2=1 \
PERF_VERSION=${version}_${revision} \ PERF_VERSION=${version}_${revision} \
all man all man
cd ${wrksrc}/tools/power/cpupower cd ${wrksrc}/tools/power/cpupower
# Disable --as-needed. make CC=$CC LDFLAGS="$LDFLAGS" VERSION=${version}_${revision} V=1
unset LDFLAGS
make CC=$CC VERSION=${version}_${revision}
if [ "$XBPS_TARGET_MACHINE" = "i686" -o "$XBPS_TARGET_MACHINE" = "x86_64" ]; then case "$XBPS_TARGET_MACHINE" in
i686*|x86_64*)
cd ${wrksrc}/tools/power/x86/x86_energy_perf_policy cd ${wrksrc}/tools/power/x86/x86_energy_perf_policy
make ${makejobs} make ${makejobs}
fi esac
cd ${wrksrc}/Documentation/laptops cd ${wrksrc}/Documentation/laptops
$CC ${CFLAGS} ${LDFLAGS} -o freefall freefall.c $CC ${CFLAGS} ${LDFLAGS} -o freefall freefall.c
@ -72,7 +74,8 @@ do_install() {
# perf # perf
cd ${wrksrc}/tools/perf cd ${wrksrc}/tools/perf
make WERROR=0 DESTDIR=${DESTDIR}/usr \ make CC=$CC LD=$LD CFLAGS="$CFLAGS" EXTRA_CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \
WERROR=0 DESTDIR=${DESTDIR}/usr \
perfexecdir='lib/perf' \ perfexecdir='lib/perf' \
NO_GTK2=1 \ NO_GTK2=1 \
PERF_VERSION=${version}_${revision} \ PERF_VERSION=${version}_${revision} \
@ -89,13 +92,6 @@ do_install() {
printf 'usbip-core\nusbip-host\n' > \ printf 'usbip-core\nusbip-host\n' > \
${DESTDIR}/usr/lib/modules-load.d/usbip.conf ${DESTDIR}/usr/lib/modules-load.d/usbip.conf
if [ "$XBPS_TARGET_MACHINE" = "i686" -o "$XBPS_TARGET_MACHINE" = "x86_64" ]; then
# x86_energy_perf_policy
cd ${wrksrc}/tools/power/x86/x86_energy_perf_policy
vinstall x86_energy_perf_policy 755 usr/bin
vinstall x86_energy_perf_policy.8 644 usr/share/man/man8
fi
if [ -d ${DESTDIR}/usr/lib64 ]; then if [ -d ${DESTDIR}/usr/lib64 ]; then
mv ${DESTDIR}/usr/lib64/* ${DESTDIR}/usr/lib/ mv ${DESTDIR}/usr/lib64/* ${DESTDIR}/usr/lib/
fi fi
@ -155,8 +151,9 @@ perf_package() {
x86_energy_perf_policy_package() { x86_energy_perf_policy_package() {
short_desc="Read or write MSR_IA32_ENERGY_PERF_BIAS" short_desc="Read or write MSR_IA32_ENERGY_PERF_BIAS"
pkg_install() { pkg_install() {
vmove usr/bin/x86_energy_perf_policy cd ${wrksrc}/tools/power/x86/x86_energy_perf_policy
vmove usr/share/man/man8/x86_energy_perf_policy.8 vbin x86_energy_perf_policy
vman x86_energy_perf_policy.8
} }
} }
usbip_package() { usbip_package() {