Message ID | 20210101100818.GA368024@host1.jankratochvil.net |
---|---|
State | Rejected |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8A4E386186E; Fri, 1 Jan 2021 10:08:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8A4E386186E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609495709; bh=ejeKUrK/5+u3YrrHpCvKBQ7H/oGX8k31iscnY8489KY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mTQW/8doQotuw9qEyFapbxfPb9pIBGTcGGacIu3jibFCsMaCKTH/ppmJiNoCDlvNU D5OE9HqchDq0SH+VZ82wId8vI6xRyDa5j9XaKg72E2Zj+o7cHF/ermTIvtRy/cPY13 WBJGCrACYAj1a0sJIk5WlafpssSweqUfKO10qeF4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id DF8023858D29 for <libc-alpha@sourceware.org>; Fri, 1 Jan 2021 10:08:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DF8023858D29 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-512-pESL-MiBNbiPotWcctDA3A-1; Fri, 01 Jan 2021 05:08:23 -0500 X-MC-Unique: pESL-MiBNbiPotWcctDA3A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 323971005513 for <libc-alpha@sourceware.org>; Fri, 1 Jan 2021 10:08:22 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-112-104.ams2.redhat.com [10.36.112.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 975D16362A for <libc-alpha@sourceware.org>; Fri, 1 Jan 2021 10:08:21 +0000 (UTC) Date: Fri, 1 Jan 2021 11:08:18 +0100 To: libc-alpha@sourceware.org Subject: [patch] Make _thread_db_sizeof_pthread public for Sanitizers Message-ID: <20210101100818.GA368024@host1.jankratochvil.net> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Jan Kratochvil via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Jan Kratochvil <jan.kratochvil@redhat.com> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
Make _thread_db_sizeof_pthread public for Sanitizers
|
|
Commit Message
Jan Kratochvil
Jan. 1, 2021, 10:08 a.m. UTC
Sanitizers currently contain ugly list of glibc versions and their sizeof(struct pthread). https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp#L276 This list is not much maintained causing SEGVs of Sanitizers: $ echo 'int main(){}'|clang -g -fsanitize=leak -x c++ -;./a.out Tracer caught signal 11: addr=0x7f1087f51f40 pc=0x4222c8 sp=0x7f1086effd40 ==234624==LeakSanitizer has encountered a fatal error. ==234624==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1 ==234624==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc) I would find better if just glibc made the value public, Sanitizers can then read it by dlsym(): http://people.redhat.com/jkratoch/lsan-pthread.patch
Comments
* Jan Kratochvil via Libc-alpha: > Sanitizers currently contain ugly list of glibc versions and their > sizeof(struct pthread). > https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp#L276 > > This list is not much maintained causing SEGVs of Sanitizers: > $ echo 'int main(){}'|clang -g -fsanitize=leak -x c++ -;./a.out > Tracer caught signal 11: addr=0x7f1087f51f40 pc=0x4222c8 sp=0x7f1086effd40 > ==234624==LeakSanitizer has encountered a fatal error. > ==234624==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1 > ==234624==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc) > > I would find better if just glibc made the value public, Sanitizers can then > read it by dlsym(): Do you know why the GetTLS function needs to know the size of the thread descriptor? And why it adds it to the start address of the TLS area, without subtracting it from the area size? I think this identifies the wrong memory region as TLS.
On 1/1/21 7:42 AM, Florian Weimer wrote: > * Jan Kratochvil via Libc-alpha: > >> Sanitizers currently contain ugly list of glibc versions and their >> sizeof(struct pthread). >> https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp#L276 >> >> This list is not much maintained causing SEGVs of Sanitizers: >> $ echo 'int main(){}'|clang -g -fsanitize=leak -x c++ -;./a.out >> Tracer caught signal 11: addr=0x7f1087f51f40 pc=0x4222c8 sp=0x7f1086effd40 >> ==234624==LeakSanitizer has encountered a fatal error. >> ==234624==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1 >> ==234624==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc) >> >> I would find better if just glibc made the value public, Sanitizers can then >> read it by dlsym(): > > Do you know why the GetTLS function needs to know the size of the > thread descriptor? And why it adds it to the start address of the TLS > area, without subtracting it from the area size? I think this > identifies the wrong memory region as TLS. This also seems like a use case for GLIBC_DEBUG (available via dlsym, with no copy relocs). However, like you, I'd like to know why the size of the descriptor is needed (XY problem).
On Fri, 01 Jan 2021 13:42:43 +0100, Florian Weimer wrote: > Do you know why the GetTLS function needs to know the size of the > thread descriptor? And why it adds it to the start address of the TLS > area, without subtracting it from the area size? I think this > identifies the wrong memory region as TLS. I do not know the memory layout of glibc TLSes (all of their kinds there are). I just find my proposed fix a better one than to play the catch-up with each glibc version. If you can find some better fix I sure welcome it. https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp#L468 https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp#L237 = static void GetTls(uptr *addr, uptr *size) { #if defined(__x86_64__) || defined(__i386__) || defined(__s390__) *addr = ThreadSelf(); *size = GetTlsSize(); // get_tls_static_info_ptr()->dl_tls_static_size *addr -= *size; *addr += ThreadDescriptorSize(); Jan
I've opned a sanitizer issue about this: Sanitizer requirements related to glibc thread descriptor/control block size <https://github.com/google/sanitizers/issues/1382> Thanks, Florian
diff --git a/nptl/Versions b/nptl/Versions index aed118e717..4144acbac7 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -297,6 +297,10 @@ libpthread { pthread_clockjoin_np; } + GLIBC_2.33 { + _thread_db_sizeof_pthread; + } + GLIBC_PRIVATE { __pthread_initialize_minimal; __pthread_clock_gettime; __pthread_clock_settime;