Ian Wienand: Toolchains, libc and interesting interactions
When building a user space binary, the -lc that gcc
inserts into the final link seems pretty straight forward link
the C library. As with all things system-library related there is
more to investigate.
If you look at /usr/lib/libc.so; the "library" that gets
linked when you specify -lc, it is not a library as such, but
a link script which specifies the libraries to link, which also
includes the dynamic linker itself:
On very
old glibc's the AS_NEEDED didn't appear; so every binary
really did have a DT_NEEDED entry for the dynamic linker
itself. This can be somewhat confusing if you're ever doing forensics
on an old binary which seems to have these entries for not apparent
reason. However, we can see that that /lib/libc.so itself
does actually require symbols from the dynamic linker:
Although you're unlikely to encounter it, a broken toolchain can
cause havoc if it gets the link order wrong here, because the glibc
dynamic linker defines minimal
versions of malloc and friends -- you've got a
chicken-and-egg problem using libc's malloc before you've
loaded it! You can simulate this havoc with something like:
Depending on various versions of things, you might see that assert
or possibly just strange, corrupt output in your logs as
syslog calls the wrong malloc. You could debug
something like this by asking the dynamic linker to show you its
bindings as it resolves them:
Above, because the dynamic loader comes first in the link order,
libc.so.6's malloc has bound to the minimal
implementation it provides, rather the full-featured one it provides
internally.
As an aside, AFAICT, there is really only one reason why a normal
library will link against the dynamic loader -- for the thread-local
storage support function __tls_get_addr. You can try this
yourself:
Thread-local storage is worthy of a book of its own,
but the gist is that this support function says "hey, give me an
address of foo in libtls.so", the magic being that
if the current thread has never accessed foo then it may not
actually have any storage for foo yet, so the dynamic linker
can allocate some memory for it lazily and then return the right
thing. Otherwise, every thread that started would need to reserve
room for foo "just in case", even if it never cares about
moo.
But looking a little closer at the symbols of libc.so is
also interesting. libc.so doesn't actually have many
functions you can override. You can see what it is possible to
override by checking the relocations against the procdure-lookup table
(PLT).
i.e. instead of jumping directly to the malloc defined in
the libc code section, any internal calls will jump to this
stub which, the first time, asks the dynamic linker to go out and find
the address of malloc (it then saves it, so the second time
the stub just jumps to the saved location).
This is an interesting list, seemingly without much order.
feof, for example, stands out as worth checking out a bit
closer why would that be there when fopen isn't, say?
We can track down where it comes from with a bit of detective work;
knowing that the value of the symbol feof will be placed into
0x35b018 we can disassemble libc.so to see that this
address is used by the feof PLT stub at 0x1e870
(luckily, objdump has done the math to offest from the
rip for us; i.e. 0x1e876 + 0x33c7a2 = 0x35b018)
From there we can search for anyone jumping to that address, and
find out the caller:
Which turns out to be part of a local
patch which probably gets things a little wrong, as described
below. The sysconf relocation is from a similar add-on patch
(being used to find the page size, it seems).
libc, like all sensible libraries, uses the hidden
attribute on symbols to restrict what is exported by the library.
The benefit of this is that when the linker knows you are referencing
a hidden symbol it knows that the value can never be overridden, and
thus does not need to emit extra code to do indirection just in case
you ever wish to redirect the symbols. In the above, it appears that
feof has never been marked as hidden, probably because no
internal glibc functions used it until that add-on patch, and since it
is not considered an internal function the linker must allow for the
possibility that it will be overridden at run time and provide a PLT
slot for it. There are consequences; if this was on a fast-path then
the extra jumps required to go via the PLT may matter for performance
and it may also cause strange behaviour if somebody had preloaded
something that took over feof.
Note, this is different from saying that your library can
override symbols provided by libc.so; such as when you
LD_PRELOAD a library to wrap an open call. What you
can not override is the open call that say, the internal
libc.so function getusershell does to read
/etc/shells.
Having the malloc related calls as preemptable seems
intentional and sane; although I can not find a comment to the effect
of "we deliberately leave these like this so that users may use
alternative malloc implementations", it makes sense so that
libc.so is internally using the same malloc as everything
else if you choose to use something such as tc-malloc.
tl;dr? Digging into your system libraries is always interesting.
Be careful with your link order when creating toolchains, and be
careful about symbol visibility when you're working with
libraries.
$ cat /usr/lib/libc.so /* GNU ld script Use the shared library, but some functions are only in the static library, so try that secondarily. */ OUTPUT_FORMAT(elf64-x86-64) GROUP ( /lib/libc.so.6 /usr/lib/libc_nonshared.a AS_NEEDED ( /lib/ld-linux-x86-64.so.2 ) )
$ readelf --dynamic /lib/libc.so.6 grep NEEDED 0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
$ cat foo.c #include <stdio.h> #include <syslog.h> int main(void) syslog(LOG_DEBUG, "hello, world!"); return 0; $ cat libbroken.so GROUP ( /lib/ld-linux-x86-64.so.2 ) $ gcc -o -Wall -Wl,-rpath=. -L. -lbroken -g -o foo foo.c $ ./foo Inconsistency detected by ld.so: dl-minimal.c: 138: realloc: Assertion ptr == alloc_last_block' failed!
$ LD_DEBUG_OUTPUT=foo.txt LD_DEBUG=bindings ./foo
Inconsistency detected by ld.so: dl-minimal.c: 138: realloc: Assertion ptr == alloc_last_block' failed!
$ cat foo.txt.11360 grep "\ malloc'"
11360: binding file /lib/libc.so.6 [0] to /lib64/ld-linux-x86-64.so.2 [0]: normal symbol malloc' [GLIBC_2.2.5]
11360: binding file /lib64/ld-linux-x86-64.so.2 [0] to /lib64/ld-linux-x86-64.so.2 [0]: normal symbol malloc' [GLIBC_2.2.5]
11360: binding file /lib/libc.so.6 [0] to /lib64/ld-linux-x86-64.so.2 [0]: normal symbol malloc' [GLIBC_2.2.5]
$ cat tls.c char __thread *foo; char* moo(void) return foo; $ gcc -fPIC -o libtls.so -shared tls.c $ readelf -d ./libtls.so grep NEED 0x00000001 (NEEDED) Shared library: [libc.so.6] 0x00000001 (NEEDED) Shared library: [ld-linux.so.2] 0x6ffffffe (VERNEED) 0x314 0x6fffffff (VERNEEDNUM) 2
Relocation section '.rela.plt' at offset 0x1e770 contains 8 entries: Offset Info Type Sym. Value Sym. Name + Addend 00000035b000 084600000007 R_X86_64_JUMP_SLO 00000000000a2100 sysconf + 0 00000035b008 02e000000007 R_X86_64_JUMP_SLO 0000000000075e50 calloc + 0 00000035b010 01dd00000007 R_X86_64_JUMP_SLO 0000000000077910 realloc + 0 00000035b018 029300000007 R_X86_64_JUMP_SLO 00000000000661c0 feof + 0 00000035b020 046f00000007 R_X86_64_JUMP_SLO 00000000000768c0 malloc + 0 00000035b028 000400000007 R_X86_64_JUMP_SLO 0000000000000000 __tls_get_addr + 0 00000035b030 01b400000007 R_X86_64_JUMP_SLO 0000000000076dd0 memalign + 0 00000035b038 086000000007 R_X86_64_JUMP_SLO 00000000000767e0 free + 0
000000000001e870 <feof@plt>: 1e870: ff 25 a2 c7 33 00 jmpq *0x33c7a2(%rip) # 35b018 <_IO_file_jumps+0xb18> 1e876: 68 03 00 00 00 pushq $0x3 1e87b: e9 b0 ff ff ff jmpq 1e830 <h_errno+0x1e7dc>
$ objdump --disassemble-all /lib/libc.so.6 grep 1e870 000000000001e870 <feof@plt>: 1e870: ff 25 a2 c7 33 00 jmpq *0x33c7a2(%rip) # 35b018 <_IO_file_jumps+0xb18> f19f7: e8 74 ce f2 ff callq 1e870 <feof@plt> $ addr2line -e /lib/libc.so.6 f19f7 /home/aurel32/eglibc/eglibc-2.11.2/sunrpc/bindrsvprt.c:70
At some stage the seminal KDE vs Gnome paper vanished from its
The major upcoming configuration change in Linux 2.6.39 is to get
rid of the '686' flavour. This may be surprising, because it's the
most widely used flavour of the 4 we have a present:
I was given this Sheevaplug. The idea with plug computers is they look like
just a wall wart, but are a whole computer.
Ideally, a 


So I've succumbed and joined twitter. I'm pretending I'm a photographer, rather than a techie/geeky/random person, whether that persists is anybodys guess.
At the very least I don't feel any real need to write/post/ask about Linux, development, or similar. I can do that here or elsewhere. (Not least because length-restrictions are annoying; yes it is true. Size is important.)
So far I've been posting semi-random pictures, I guess that is one way to pass the time, while I play with my camera.
For marathon freaks, Boston marathon is a mythical one. Probably more
than New York marathon, because this is the world's oldest annual
marathon. Also because is is quite difficult to register for it (this
year, the 20,000 seats reserved for qualifiers were distributed
in....8 hours).
In order to qualify, runners must have a previous mark that depends on
their age and gender. For instance, in my age category (50-54), the
required mark for men is 3h30, something I never achieved yet. This is
what's required for the 2013 race. For 2012, it will be still 3h35,
but a rolling process will be held to give best runners priority.
So, in short, it will probably stay among my dream marathons
forever..:-)
The 2011 race happened yesterday and was a great event. Kenyan runners
Geoffrey Mutai and Moses Mosop even broke Haile Gebresselassie's world
record, set in Berlin, back in 2008. The ran in 2h03'02" while
Gebresselassie's mark is 2h03'59". However, this record will not
become official because Boston's race is one-way (thus with a
possibility of consistent tailwind) and has a too big altitude
difference between start and finish. However, many consider that hills
on the race compensate this quite strongly, so this year's time is a
really great time.
And, really, from all reports I read and all images I saw, the level
of support you get from the crowd is incredible there, with world
famous moments like Wellesley College "scream tunnel", or Kenmore
Square where, traditionnaly, the Red Sox have a game prior to marathon
and the crowd then goes from Fenway Park to Kenmore Square to cheer
the runners for their final mile (I have no idea how they can manage
the unpredictable length of a base-ball game).
And I can't even mention the final mile on Commonwealth Av., then
Bolston St. Everybody who ran this once says this is something you
have to do once in your life.
So, well, I'm still crossing fingers..:-)...Maybe, one day a miracle
happens, I can qualify *and* I get a seat and I fly to Boston...
Frequently Asked Questions and Common Problems
Why do links always open in epiphany instead of iceweasel? You need to upgrade to the latest version on libglib2.0-0, gvfs and gnome-control-center in experimental. Then you can customize the default application used in the control center (under System Information > Default applications ).
You might need to switch to iceweasel 4.0 in experimental to have iceweasel appear in the list of browsers. Or you can edit
Went to

That bread is zwieback, then there is cherry moos, bohne berrogi, verenike, and of course, sausage.
Here are Jacob and Oliver enjoying their food:


I took part in a occupational-health-related thread recently, and wrote a bit of my experience which might be helpful for my readers, many of them avid keyboard users, with usually 8hr of typing per day.
( ) I suffered not from RSI but from painful back aches. I started using standard keyboards in a different fashion, not putting so much stress on my wrists (and on the muscles connecting them to the rest of the body, of course): I exclusively use US keymaps (with some modifications to allow for proper Spanish input and characters), but instead of making the middle row my fingers' home row, I type with the base position of my fingers in a V shape Fingers resting on (approx.) w-e-f-v-spacebar and spacebar-m-l-;-]; the fingers doing most of the travelling are the index and middle, and with no straining for the little fingers to reach or backspace. On the other side, the most straining keys become Control and Shift, which requires closing the hands a bit too much, but are not that bad. My way does induce some new kind of stress, as my arms also have to move to reach 6 and 7, but it... Works for me .
It looks weird and is somewhat strange to get used to, but I must say it has worked great for me. I work this way on regular and laptop keyboards, even on my netbook's noticeably smaller one.
As mentioned on