From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4346 invoked by alias); 18 Nov 2012 19:36:11 -0000 Received: (qmail 1602 invoked by uid 48); 18 Nov 2012 19:35:46 -0000 From: "konstantin.s.serebryany at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug other/55354] [asan] by default, the asan run-time should be linked statically, not dynamically Date: Sun, 18 Nov 2012 19:36:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: other X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: konstantin.s.serebryany at gmail dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg01666.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55354 --- Comment #9 from Konstantin Serebryany 2012-11-18 19:35:43 UTC --- As dvyuokv@ pointed out, -ftls-model=initial-exec improves the situation, but does not fully help. Experiment: % cat x.c __thread int a; int foo() { return a; } HORRIBLE: -fPIC -shared % gcc x.c -O2 -fPIC -shared -o x.so ; objdump -d x.so | grep foo.: -A 5 00000000000006e0 : 6e0: 66 48 8d 3d f0 08 20 lea 0x2008f0(%rip),%rdi # 200fd8 <_DYNAMIC+0x1b8> 6e7: 00 6e8: 66 66 48 e8 10 ff ff callq 600 <__tls_get_addr@plt> 6ef: ff 6f0: 8b 00 mov (%rax),%eax NOT-SO-BAD: -fPIC -shared -ftls-model=initial-exec % gcc x.c -O2 -fPIC -shared -o x.so -ftls-model=initial-exec ; objdump -d x.so | grep foo.: -A 5 0000000000000630 : 630: 48 8b 05 a9 09 20 00 mov 0x2009a9(%rip),%rax # 200fe0 <_DYNAMIC+0x1b8> 637: 64 8b 00 mov %fs:(%rax),%eax 63a: c3 retq GOOD: -fPIE % gcc -c x.c -O2 -fPIE -o x.o ; objdump -d x.o | grep foo.: -A 5 0000000000000000 : 0: 64 8b 04 25 00 00 00 mov %fs:0x0,%eax 7: 00 8: c3 retq So, while -ftls-model=initial-exec improves the TLS performance, it is still 2x slower than -fPIE. For tsan, which does this for *every* memory access in the original program, this will cost 5%-10% slowdown. For our users this is a big deal, so they will link the static library whenever possible. Which default is used in gcc -- I don't care that much.