public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "hjl.tools at gmail dot com" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sourceware.org Subject: [Bug libc/14955] New: __get_cpu_features isn't always usable Date: Thu, 13 Dec 2012 17:18:00 -0000 [thread overview] Message-ID: <bug-14955-131@http.sourceware.org/bugzilla/> (raw) http://sourceware.org/bugzilla/show_bug.cgi?id=14955 Bug #: 14955 Summary: __get_cpu_features isn't always usable Product: glibc Version: unspecified Status: NEW Severity: normal Priority: P2 Component: libc AssignedTo: unassigned@sourceware.org ReportedBy: hjl.tools@gmail.com CC: drepper.fsp@gmail.com Classification: Unclassified When we tried to use __get_cpu_features in libpthread.so, we got a crash like this: [hjl@gnu-hsw-1 ifunc-cpu]$ cat foo.c enum { COMMON_CPUID_INDEX_1 = 0, COMMON_CPUID_INDEX_80000001, /* for AMD */ /* Keep the following line at the end. */ COMMON_CPUID_INDEX_MAX }; enum { FEATURE_INDEX_1 = 0, /* Keep the following line at the end. */ FEATURE_INDEX_MAX }; struct cpu_features { enum cpu_features_kind { arch_kind_unknown = 0, arch_kind_intel, arch_kind_amd, arch_kind_other } kind; int max_cpuid; struct cpuid_registers { unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx; } cpuid[COMMON_CPUID_INDEX_MAX]; unsigned int family; unsigned int model; unsigned int feature[FEATURE_INDEX_MAX]; }; extern const struct cpu_features *__get_cpu_features (void); static int one (void) { return -30; } static int two (void) { return -40; } void * foo_ifunc (void) __asm__ ("foo") __attribute__ ((visibility ("hidden"))); __asm__(".type foo, %gnu_indirect_function"); void * foo_ifunc (void) { const struct cpu_features * cpu = __get_cpu_features (); return cpu->max_cpuid > 1 ? two : one; } extern int foo (void) __attribute__ ((visibility ("hidden"))); int (*foo_ptr) (void) = foo; [hjl@gnu-hsw-1 ifunc-cpu]$ cat main.c #include <stdio.h> extern int (*foo_ptr) (void); int main() { foo_ptr (); printf ("main: %p\n", foo_ptr); return 0; } [hjl@gnu-hsw-1 ifunc-cpu]$ make gcc -g -c -o main.o main.c gcc --shared -o libfoo.so foo.c -fPIC -g gcc -o main main.o libfoo.so -Wl,-rpath,. ./main make: *** [all] Segmentation fault [hjl@gnu-hsw-1 ifunc-cpu]$ gdb main GNU gdb (GDB) 7.5.50.20121203-cvs Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-unknown-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /export/home/hjl/bugs/libc/ifunc-cpu/main...done. (gdb) r Starting program: /export/home/hjl/bugs/libc/ifunc-cpu/main Program received signal SIGSEGV, Segmentation fault. 0x00000000000005a6 in ?? () (gdb) bt #0 0x00000000000005a6 in ?? () #1 0x00007ffff7dfc6f3 in ?? () #2 0x00007ffff7dfc2a0 in ?? () #3 0x0000000000000006 in ?? () #4 0x00007fffffffe070 in ?? () #5 0x000000373b80c6d8 in _dl_relocate_object () from /lib64/ld-linux-x86-64.so.2 Backtrace stopped: frame did not save the PC (gdb) -- Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
next reply other threads:[~2012-12-13 17:18 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-12-13 17:18 hjl.tools at gmail dot com [this message] 2012-12-13 17:58 ` [Bug libc/14955] " hjl.tools at gmail dot com 2014-06-14 5:36 ` fweimer at redhat dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-14955-131@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).