Disable AVX-optimized functions in glibc (LD_HWCAP_MASK, /etc/ld.so.nohwcap) for valgrind & gdb record

It looks like there is a nice workaround for this implemented in recent versions of glibc: a “tunables” feature that guides selection of optimized string functions. You can find a general overview of this feature here and the relevant code inside glibc in ifunc-impl-list.c. Here’s how I figured it out. First, I took the address … Read more

multiple threads able to get flock at the same time

flock(2) is documented as “blocking if an incompatible lock is held by another process” and with “locks created by flock() are associated with an open file table entry”, so it should be expected that flock-ed locks by several threads of the same process don’t interact. (the flock documentation doesn’t mention threads). Hence, the solution should … Read more

Where are syscalls located in glibc source

What you’ve found is a stub function for systems it’s not implemented on. You need to look under the sysdeps tree for the actual implementation. The following may be of interest: sysdeps/unix/sysv/linux sysdeps/posix sysdeps/i386 (or x86_64 or whatever your cpu arch is)

Sorting list of string with specific locale in python

You could use a PyICU‘s collator to avoid changing global settings: import icu # PyICU def sorted_strings(strings, locale=None): if locale is None: return sorted(strings) collator = icu.Collator.createInstance(icu.Locale(locale)) return sorted(strings, key=collator.getSortKey) Example: >>> L = [u’sandwiches’, u’angel delight’, u’custard’, u’éclairs’, u’glühwein’] >>> sorted_strings(L) [‘angel delight’, ‘custard’, ‘glühwein’, ‘sandwiches’, ‘éclairs’] >>> sorted_strings(L, ‘en_US’) [‘angel delight’, ‘custard’, ‘éclairs’, … Read more

_GNU_SOURCE and __USE_GNU

_GNU_SOURCE is the only one you should ever define yourself. __USE_GNU is defined internally through a mechanism in features.h (which is included by all other glibc headers) when _GNU_SOURCE is defined, and possibly under other conditions. Defining or undefining __USE_GNU yourself will badly break the glibc headers.

How to upgrade glibc on Debian?

I was able to install libc6 2.17 in Debian Wheezy by editing the recommendations in perror’s answer: IMPORTANT You need to exit out of your display manager by pressing CTRL–ALT–F1. Then you can stop x (slim) with sudo /etc/init.d/slim stop (replace slim with mdm or lightdm or whatever) Add the following line to the file … Read more

Is this possible to customize printf?

Sorry, but some answers are incorrect on Linux with Glibc On Linux with a GNU Glibc, you can customize printf: you would call register_printf_function to e.g. define the meaning of %Y in your printf format strings. However, this behavior is Glibc specific, and might even become obsolete… I’m not sure I would recommend this approach! … Read more

Linking a C program directly with ld fails with undefined reference to `__libc_csu_fini`

/usr/lib/libc.so is a linker script which tells the linker to pull in the shared library /lib/libc.so.6, and a non-shared portion, /usr/lib/libc_nonshared.a. __libc_csu_init and __libc_csu_fini come from /usr/lib/libc_nonshared.a. They’re not being found because references to symbols in non-shared libraries need to appear before the archive that defines them on the linker line. In your case, /usr/lib/crt1.o … Read more

Check glibc version for a particular gcc compiler

even easier use ldd –version This should return the glibc version being used i.e. $ ldd –version ldd (GNU libc) 2.17 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO … which is the same result as running my libc library $ /lib/libc.so.6 GNU … Read more