From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 4286B398980C for ; Thu, 17 Jun 2021 19:24:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4286B398980C 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-381-VKgbubOiMOqdrBsCPORkxQ-1; Thu, 17 Jun 2021 15:23:58 -0400 X-MC-Unique: VKgbubOiMOqdrBsCPORkxQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03AAEEC1D9; Thu, 17 Jun 2021 19:23:57 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-115-60.ams2.redhat.com [10.36.115.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8CC960C5C; Thu, 17 Jun 2021 19:23:55 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Cc: Kevin Buettner , gdb@sourceware.org Subject: [PATCH] nptl: Export libthread_db-used symbols under GLIBC_PRIVATE Date: Thu, 17 Jun 2021 21:23:53 +0200 Message-ID: <877disuwfq.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.9 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, URIBL_BLACK 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: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jun 2021 19:24:05 -0000 Kevin, this *almost* gives us the perfect debugging experience with your patched GDB in Fedora 35, according to my preliminary tests. A build with the patch is running here: However, it seems that GDB still needs pthread_create in the .symtab to trigger loading of libpthread_db. A fully stripped libc.so.6 without .symtab does not trigger loading in my experiments. (The other symbols we preserve for valgrind's sake and are immaterial to GDB.) In other words, cp /lib64/libc.so.6 . ; strip libc.so.6 ; LD_LIBRARY_PATH=3D. gdb =E2=80= =A6 does not result in working thread debugging. If the pthread_create .symtab requirement is too difficult to work around, we might as well put the _thread_db_* symbols into .symtab and tell distributions to use: strip -w -K pthread_create -K _thread_db_\* libc.so.6 But then we'd need two categories of symbols in the internal consistency check for nptl_db (the db-symbol.awk file), so maybe that's overdoing things for a slightly smaller .dynsym size. Thanks, Florian 8<------------------------------------------------------------------8< This allows distributions to strip debugging information from libc.so.6 without impacting the debugging experience. nptl_version had to be renamed to __nptl_version to avoid namespace issues. --- nptl/Versions | 56 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ nptl/pthread_create.c | 13 +++++++----- nptl_db/Makefile | 2 +- nptl_db/db-symbols.awk | 4 +++- nptl_db/structs.def | 2 +- nptl_db/td_ta_new.c | 2 +- 6 files changed, 70 insertions(+), 9 deletions(-) diff --git a/nptl/Versions b/nptl/Versions index 62bb939d54..c03ed92848 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -403,10 +403,14 @@ libc { __nptl_deallocate_tsd; __nptl_death_event; __nptl_free_tcb; + __nptl_last_event; __nptl_nthreads; + __nptl_rtld_global; __nptl_setxid_sighandler; __nptl_stack_list_add; __nptl_stack_list_del; + __nptl_threads_events; + __nptl_version; __pthread_attr_copy; __pthread_attr_destroy; __pthread_attr_init; @@ -430,6 +434,58 @@ libc { __pthread_unwind; __sched_fifo_max_prio; __sched_fifo_min_prio; + _thread_db___nptl_last_event; + _thread_db___nptl_rtld_global; + _thread_db_const_thread_area; + _thread_db_dtv_dtv; + _thread_db_dtv_slotinfo_gen; + _thread_db_dtv_slotinfo_list_len; + _thread_db_dtv_slotinfo_list_next; + _thread_db_dtv_slotinfo_list_slotinfo; + _thread_db_dtv_slotinfo_map; + _thread_db_dtv_t_counter; + _thread_db_dtv_t_pointer_val; + _thread_db_link_map_l_tls_modid; + _thread_db_link_map_l_tls_offset; + _thread_db_list_t_next; + _thread_db_list_t_prev; + _thread_db_pthread_cancelhandling; + _thread_db_pthread_dtvp; + _thread_db_pthread_eventbuf; + _thread_db_pthread_eventbuf_eventmask; + _thread_db_pthread_eventbuf_eventmask_event_bits; + _thread_db_pthread_key_data_data; + _thread_db_pthread_key_data_level2_data; + _thread_db_pthread_key_data_seq; + _thread_db_pthread_key_struct_destr; + _thread_db_pthread_key_struct_seq; + _thread_db_pthread_list; + _thread_db_pthread_nextevent; + _thread_db_pthread_report_events; + _thread_db_pthread_schedparam_sched_priority; + _thread_db_pthread_schedpolicy; + _thread_db_pthread_specific; + _thread_db_pthread_start_routine; + _thread_db_pthread_tid; + _thread_db_register32; + _thread_db_register32_thread_area; + _thread_db_register64; + _thread_db_register64_thread_area; + _thread_db_rtld_global__dl_stack_used; + _thread_db_rtld_global__dl_stack_user; + _thread_db_rtld_global__dl_tls_dtv_slotinfo_list; + _thread_db_sizeof_dtv_slotinfo; + _thread_db_sizeof_dtv_slotinfo_list; + _thread_db_sizeof_list_t; + _thread_db_sizeof_pthread; + _thread_db_sizeof_pthread_key_data; + _thread_db_sizeof_pthread_key_data_level2; + _thread_db_sizeof_pthread_key_struct; + _thread_db_sizeof_td_eventbuf_t; + _thread_db_sizeof_td_thr_events_t; + _thread_db_td_eventbuf_t_eventdata; + _thread_db_td_eventbuf_t_eventnum; + _thread_db_td_thr_events_t_event_bits; } } =20 diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 3f017f1e26..d1b6817a81 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -43,21 +43,24 @@ =20 =20 /* Globally enabled events. */ -static td_thr_events_t __nptl_threads_events __attribute_used__; +td_thr_events_t __nptl_threads_events __attribute__ ((nocommon)); +libc_hidden_proto (__nptl_threads_events) +libc_hidden_data_def (__nptl_threads_events) =20 /* Pointer to descriptor with the last event. */ -static struct pthread *__nptl_last_event __attribute_used__; +struct pthread *__nptl_last_event __attribute__ ((nocommon)); +libc_hidden_proto (__nptl_last_event) +libc_hidden_data_def (__nptl_last_event) =20 #ifdef SHARED /* This variable is used to access _rtld_global from libthread_db. If GDB loads libpthread before ld.so, it is not possible to resolve _rtld_global directly during libpthread initialization. */ -static struct rtld_global *__nptl_rtld_global __attribute_used__ - =3D &_rtld_global; +struct rtld_global *__nptl_rtld_global =3D &_rtld_global; #endif =20 /* Version of the library, used in libthread_db to detect mismatches. */ -static const char nptl_version[] __attribute_used__ =3D VERSION; +const char __nptl_version[] =3D VERSION; =20 /* This performs the initialization necessary when going from single-threaded to multi-threaded mode for the first time. */ diff --git a/nptl_db/Makefile b/nptl_db/Makefile index ea721c1dcf..4cc51c0e7b 100644 --- a/nptl_db/Makefile +++ b/nptl_db/Makefile @@ -57,7 +57,7 @@ include ../Rules =20 $(objpfx)db-symbols.out: $(objpfx)db-symbols.v.i \ =09=09=09 $(common-objpfx)libc.so -=09LC_ALL=3DC $(READELF) -W -s $(filter %.so,$^) | $(AWK) -f $< > $@; \ +=09LC_ALL=3DC $(READELF) -W -D -s $(filter %.so,$^) | $(AWK) -f $< > $@; \ =09$(evaluate-test) =20 $(objpfx)db-symbols.v.i: db-symbols.awk diff --git a/nptl_db/db-symbols.awk b/nptl_db/db-symbols.awk index 6f326cf379..2033f95e38 100644 --- a/nptl_db/db-symbols.awk +++ b/nptl_db/db-symbols.awk @@ -13,7 +13,7 @@ BEGIN { in_symtab =3D 0; } =20 -/Symbol table '.symtab'/ { in_symtab=3D1; next } +/Symbol table for image/ { in_symtab=3D1; next } NF =3D=3D 0 { in_symtab=3D0; next } =20 !in_symtab { next } @@ -24,6 +24,7 @@ END { status =3D 0; =20 for (s in required) { + s =3D s "@@GLIBC_PRIVATE" if (s in seen) print s, "ok"; else { status =3D 1; @@ -33,6 +34,7 @@ END { =20 any =3D ""; for (s in th_unique) { + s =3D s "@@GLIBC_PRIVATE" if (s in seen) { any =3D s; break; diff --git a/nptl_db/structs.def b/nptl_db/structs.def index 6a726f207e..e2e51acc39 100644 --- a/nptl_db/structs.def +++ b/nptl_db/structs.def @@ -77,7 +77,7 @@ DB_STRUCT (td_eventbuf_t) DB_STRUCT_FIELD (td_eventbuf_t, eventnum) DB_STRUCT_FIELD (td_eventbuf_t, eventdata) =20 -DB_SYMBOL (nptl_version) +DB_SYMBOL (__nptl_version) DB_MAIN_SYMBOL (__nptl_create_event) DB_MAIN_SYMBOL (__nptl_death_event) DB_SYMBOL (__nptl_threads_events) diff --git a/nptl_db/td_ta_new.c b/nptl_db/td_ta_new.c index 501d922ea2..eeca29d5a0 100644 --- a/nptl_db/td_ta_new.c +++ b/nptl_db/td_ta_new.c @@ -39,7 +39,7 @@ td_ta_new (struct ps_prochandle *ps, td_thragent_t **ta) LOG ("td_ta_new"); =20 /* Check whether the versions match. */ - if (td_lookup (ps, SYM_nptl_version, &versaddr) !=3D PS_OK) + if (td_lookup (ps, SYM___nptl_version, &versaddr) !=3D PS_OK) return TD_NOLIBTHREAD; if (ps_pdread (ps, versaddr, versbuf, sizeof (versbuf)) !=3D PS_OK) return TD_ERR;