Look at line 277 in portage.py (line ref from the the new ultrafast version): it's ordering $LDPATH alphabetically. I don't know why this is so but it's not the expected behaviour because it ignores the order of the env.d files that set $LDPATH. The problem that raised this was that libartsc (from arts, kde) is compatible both ways between kde2 and kde3. A program (e.g. libsdl) compiles against the correct arts (the newer kde3 one), but at runtime /usr/kde/2 comes before /usr/kde/3 in the alphabetically-sorted ld.so.conf and the wrong libartsc.so is loaded.