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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B3A263858D28 for ; Sat, 18 Dec 2021 18:46:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B3A263858D28 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-489-LC362ChEMSa9jYzgBL9gqQ-1; Sat, 18 Dec 2021 13:46:05 -0500 X-MC-Unique: LC362ChEMSa9jYzgBL9gqQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8FDF801962; Sat, 18 Dec 2021 18:46:03 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4A4A4BC54; Sat, 18 Dec 2021 18:45:59 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, John Mellor-Crummey , Ben Woodard , Alexander Monakov Subject: Re: [PATCH v6 10/20] elf: Avoid unnecessary slowdown from profiling with audit (BZ#15533) References: <20211115183734.531155-1-adhemerval.zanella@linaro.org> <20211115183734.531155-11-adhemerval.zanella@linaro.org> Date: Sat, 18 Dec 2021 19:45:58 +0100 In-Reply-To: <20211115183734.531155-11-adhemerval.zanella@linaro.org> (Adhemerval Zanella's message of "Mon, 15 Nov 2021 15:37:24 -0300") Message-ID: <87lf0hhhuh.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.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.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_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Dec 2021 18:46:10 -0000 * Adhemerval Zanella: > The rtld-audit interfaces introduces a slowdown due to enabling profiling > instrumentation (as if LD_AUDIT implied LD_PROFILE). However, instrumenting > is only necessary if one of audit libraries provides PLT callbacks ( > la_pltenter or la_pltexit symbols). Otherwise, the slowdown can be avoided. Awkward linebreak after (. > To keep la_symbind() to work even without PLT callbacks, _dl_fixup now > +* The audit libraries will avoid unnecessary slowdown if it is not required > + PLT tracking (by not implementing the la_pltenter() or la_pltexit() > + callbacks). I think we don't use the () markers? (Although I said before I wouldn't point this out anymore.) > diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c > index 0d5b727c64..64a96c36e8 100644 > --- a/elf/dl-reloc.c > +++ b/elf/dl-reloc.c > @@ -205,12 +205,28 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[], > int skip_ifunc = reloc_mode & __RTLD_NOIFUNC; > #ifndef PROF > - if (__glibc_unlikely (consider_profiling) > + if (consider_profiling | consider_symbind > && l->l_info[DT_PLTRELSZ] != NULL) > { > /* Allocate the array which will contain the already found Please add parentheses around the | expression (which should perhaps use || too). > diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c > index 03da689503..9a38eea7cc 100644 > --- a/elf/dl-runtime.c > +++ b/elf/dl-runtime.c > @@ -131,6 +131,37 @@ _dl_fixup ( > - /* Determine whether any of the two participating DSOs is > - interested in auditing. */ > - if ((l->l_audit_any_plt | result->l_audit_any_plt) != 0) > - { > - unsigned int flags = 0; > - struct audit_ifaces *afct = GLRO(dl_audit); > - /* Synthesize a symbol record where the st_value field is > - the result. */ > - ElfW(Sym) sym = *defsym; > - sym.st_value = DL_FIXUP_VALUE_ADDR (value); All this was copied over in patch 06/20 of the series to dl-audit.c. > diff --git a/elf/tst-audit19a.c b/elf/tst-audit19a.c > new file mode 100644 > index 0000000000..36b781f9be > --- /dev/null > +++ b/elf/tst-audit19a.c > +#include > +#include > + > +/* We interpose the profile resolver and if it is called it means profiling is > + enabled. */ > +void > +_dl_runtime_profile (ElfW(Word) addr) I don't think this works. _dl_runtime_profile is not an exported symbol, so it can't be interposed. Maybe you can check for an allocated l_reloc_result instead. If it's not there, profiling isn't possible. It's not entirely equivalent, but it provides at least some testing. > diff --git a/elf/tst-auditmod19a.c b/elf/tst-auditmod19a.c > new file mode 100644 > index 0000000000..2296382a1c > --- /dev/null > +++ b/elf/tst-auditmod19a.c > @@ -0,0 +1,23 @@ > +unsigned int > +la_version (unsigned int version) > +{ > + return version; > +} This should use LAV_CURRENT. > diff --git a/elf/tst-auditmod19b.c b/elf/tst-auditmod19b.c > new file mode 100644 > index 0000000000..52bb88c7d7 > --- /dev/null > +++ b/elf/tst-auditmod19b.c > +unsigned int > +la_version (unsigned int version) > +{ > + return version; > +} Likweise. Thanks, Florian