Previous Entry Add to Memories Share Next Entry
the amazing story of fedora bug #638477
nepal
k001
It's pretty amazing. A guy reported to Fedora bugzilla that his Fedora 14 have problems playing music via Adobe Flash -- "strange sound" as he puts it. He added that it works fine on Fedora 13, so it must be a regression. I would say such reports are going nowhere, for a number of reasons -- such bugs are hard to debug, Adobe Flash is closed-source hated piece of software, and there are way too many other bugs in Fedora to care about.

Fortunately, some other people have the same problem, among them is a guy named Linus Torvalds, who adds: "I see this as well. Sounds like clipping or some really bad sample rate frequency conversion". They tracked it down to a combination of Fedora 14 and 64-bit flash plugin. Then they tracked it down to glibc (old verions works fine, new one causes that "strange sounds"), and also found out (using valgrind) that flash plugin is doing memcpy() for the overlapping regions. In such case, memmove() should be used instead, as memcpy() behavior is undefined.

Anyway, to make a long story short, recent glibc version (the one shipped in F14) includes an optimization from Intel guys that speeds up memcpy() for Core 2 Duo, Atom and Core i7 CPUs. Apparently the part of optimization is that memory copying is now done backwards (from upper addresses to lower addresses) which manifestates the bug.

Now what is the solution? Fix Adobe Flash to use memmove(). It should take quite a lot of time, given the fact that the bug report to Adobe was only filed 4 days ago, i.e. this Monday.

What is the workaround? To use own implementation of memcpy() for the browser (and thus the flash plugin) by LD_PRELOADing it. A simple memcpy() implementation and details come from the same Torvalds guy.


Here are cut-n-paste instructions for Fedora 14/x86_64/Firefox users, tested on two F14 boxes by me.


cat << EOF > mymemcpy.c
#include <sys/types.h>

void *memcpy(void *dst, const void *src, size_t size)
{
void *orig = dst;
asm volatile("rep ; movsq"
:"=D" (dst), "=S" (src)
:"0" (dst), "1" (src), "c" (size >> 3)
:"memory");
asm volatile("rep ; movsb"
:"=D" (dst), "=S" (src)
:"0" (dst), "1" (src), "c" (size & 7)
:"memory");
return orig;
}
EOF

# Compile and link
gcc -O2 -c mymemcpy.c
ld -G mymemcpy.o -o mymemcpy.so
# Install
sudo cp mymemcpy.so /usr/local/lib64/
# chcon is for SELinux users
sudo chcon --reference=/lib64/libc.so.6 /usr/local/lib64/mymemcpy.so
# Patch the script that runs Firefox
sudo sed -i 's,\(^[[:space:]]*\)\("$prog" ${1+"$@"}\),\1LD_PRELOAD=/usr/local/lib64/mymemcpy.so \2,' /usr/lib64/firefox-3.6/run-mozilla.sh
# Same for newer Firefox versions
sudo sed -i 's,\(^[[:space:]]*\)\(exec "$prog" ${1+"$@"}\),\1LD_PRELOAD=/usr/local/lib64/mymemcpy.so \2,' /usr/lib64/firefox-3.6/run-mozilla.sh
# Same for Firefox 5:
sudo sed -i 's,\(^[[:space:]]*\)\(exec "$prog" ${1+"$@"}\),\1LD_PRELOAD=/usr/local/lib64/mymemcpy.so \2,' /usr/lib64/firefox-5/run-mozilla.sh


What would be really exciting is to know who and how broke sound on my Ubuntu 10.10 after some update. 32 bit here :)

Хорошо тебе с такой простой story. А у меня тайминг убегает

В ядре? Поменять clocksource, параметром ядра в grub.conf

clocksource=[hpet|pit|tsc|acpi_pm|cyclone|scx200_hrt]

Непонятно. Видео играется вдесятеро (на глаз) быстрее, звука нет вообще. Если б в ядре так время уезжало, то и часы бы развалились, и вообще. А так — всё работает, и только ни видео мне, ни звука :)

Во всех плеерах?

Попробуй нового юзера заведи и в его сессии поиграй. Если всё хорошо — у тебя какие-то старые кривые настройки мешают, например, настройки pulseaudio.

Is there a misprint in the last line of the patch? Should put mymemcpy.so into LD_PRELOAD, not .c.

Good catch, thank you! fixed.

Thank you very much for howto - it's cool and very useful!

OTOH, 64-bit hosts weren't meant to run adobe flash player anyway :-D

well, it's official (although beta) adobe flash player software ;)

It's not what 64 bit was MEANT to run :-D

типичный линукс love & hate
love - все можно сделать/починить, разобраться
hate - очень часто приходится этим заниматся :)

Я бы сказал, типичный Ульрих Дреппер (glibc maintainer) — ему наплевать, что у юзеров всё поломалось.

Другой пример — http://lj.rossia.org/users/k001/711507.html
Сам Ульрих негодует, что gcc подменяет printf("%s\n", str) на puts(str), и требует чинить это в gcc, но сам не хочет поправить в glibc, чтобы обе функции одинаково работали, когда str=NULL.

Thanks, it is very useful - just fixed sound in my Google Chrome with this (weird, I listened to many files since I saw this post, but got hit by the bug only now).

Ah yes, I saw that one on lwn.net. Nice to have a test environment where "don't do that" actually gives an empirically testable result.

Script C++ Terminal, Code?

Nathan Dunbar

2011-02-08 03:33 am (UTC)

What do you do with the copy paste function. Do you copy the code into a C program if so how. New to linux, any help would be appreciated as I am getting this crappy sound from my i5 laptop also.


Re: Script C++ Terminal, Code?

k001

2011-02-08 07:36 am (UTC)

Open the terminal emulator and copy-paste everything (starting from "cut") to it.

Good Job man! You should send a link to this post to Adobe! This fixes the problem! Your truly amazing! Great job!

-Nathan

Briliant! thanks very much for this