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 082B63858C2C for ; Mon, 20 Dec 2021 19:19:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 082B63858C2C 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-395-FtrwOnVaOWeQNvlheC3iww-1; Mon, 20 Dec 2021 14:18:44 -0500 X-MC-Unique: FtrwOnVaOWeQNvlheC3iww-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 2C3C5100C609; Mon, 20 Dec 2021 19:18:43 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C84695F4E9; Mon, 20 Dec 2021 19:18:41 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, John Mellor-Crummey , Ben Woodard Subject: Re: [PATCH v6 18/20] elf: Issue la_symbind() for bind-now (BZ #23734) References: <20211115183734.531155-1-adhemerval.zanella@linaro.org> <20211115183734.531155-19-adhemerval.zanella@linaro.org> Date: Mon, 20 Dec 2021 20:18:39 +0100 In-Reply-To: <20211115183734.531155-19-adhemerval.zanella@linaro.org> (Adhemerval Zanella's message of "Mon, 15 Nov 2021 15:37:32 -0300") Message-ID: <87a6gvf5kg.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.15 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=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, URIBL_BLACK 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: Mon, 20 Dec 2021 19:19:05 -0000 I believe this change needs to update elf/sotruss-lib.c: uintptr_t la_symbind (Elf_Sym *sym, unsigned int ndx, uintptr_t *refcook, =09 uintptr_t *defcook, unsigned int *flags, const char *symname) { if (!do_exit) *flags =3D LA_SYMB_NOPLTEXIT; return sym->st_value; } * Adhemerval Zanella: > diff --git a/elf/Makefile b/elf/Makefile > index ee4daae0fc..acce163078 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > +# The test check if a library without .gnu.version correctly calls the > +# audit callbacks. So it uses an explicit link rule to avoid linking > +# against libc.so. > +$(objpfx)tst-audit24bmod1.so: $(objpfx)tst-audit24bmod1.os > +=09$(CC) -nostdlib -nostartfiles -shared -o $@.new $(objpfx)tst-audit24b= mod1.os \ > +=09 -Wl,-z,now > +=09$(call after-link,$@.new) > +=09mv -f $@.new $@ I think you may have to update modules-names-nobuild as well. > # tst-sonamemove links against an older implementation of the library. > LDFLAGS-tst-sonamemove-linkmod1.so =3D \ > -Wl,--version-script=3Dtst-sonamemove-linkmod1.map \ > diff --git a/elf/dl-audit.c b/elf/dl-audit.c > index c3569cb357..f080591596 100644 > --- a/elf/dl-audit.c > +++ b/elf/dl-audit.c > @@ -190,7 +190,7 @@ rtld_hidden_def (_dl_audit_symbind_alt) > void > _dl_audit_symbind (struct link_map *l, struct reloc_result *reloc_result= , > =09=09 const ElfW(Sym) *defsym, DL_FIXUP_VALUE_TYPE *value, > -=09=09 lookup_t result) > +=09=09 lookup_t result, bool bindnow) > { Should =E2=80=9Cbindow=E2=80=9C be called =E2=80=9Cfor_jmp_slot=E2=80=9D? > @@ -229,16 +230,16 @@ _dl_audit_symbind (struct link_map *l, struct reloc= _result *reloc_result, > =09{ > =09 if (afct->symbind !=3D NULL) > =09 { > -=09 uintptr_t new_value =3D afct->symbind (&sym, > -=09=09=09=09=09=09 reloc_result->boundndx, > -=09=09=09=09=09=09 &l_state->cookie, > -=09=09=09=09=09=09 &result_state->cookie, > -=09=09=09=09=09=09 &flags, > -=09=09=09=09=09=09 strtab2 + defsym->st_name); > +=09 flags |=3D bindnow ? LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT : 0= ; > +=09 new_value =3D afct->symbind (&sym, reloc_result->boundndx, > +=09=09=09=09=09 &l_state->cookie, > +=09=09=09=09=09 &result_state->cookie, &flags, > +=09=09=09=09=09 strtab2 + defsym->st_name); > =09 if (new_value !=3D (uintptr_t) sym.st_value) > =09=09{ > =09=09 flags |=3D LA_SYMB_ALTVALUE; > -=09=09 sym.st_value =3D new_value; > +=09=09 sym.st_value =3D bindnow > +=09=09 ? DL_FIXUP_BINDNOW_ADDR_VALUE (new_value) : new_value; > =09=09} > =09 } We could error out if the audit callback clears the LA_SYMB_NOPLT* flags we've set (after fixing sotruss). And then we'll have to make this change conditional on the la_version return value, I think. > --- a/elf/dl-reloc.c > +++ b/elf/dl-reloc.c > @@ -234,9 +234,7 @@ _dl_relocate_object (struct link_map *l, struct r_sco= pe_elem *scope[], > =20 > /* If DT_BIND_NOW is set relocate all references in this object. We > do not do this if we are profiling, of course. */ > - // XXX Correct for auditing? > - if (!consider_profiling > - && __builtin_expect (l->l_info[DT_BIND_NOW] !=3D NULL, 0)) > + if (!consider_profiling && l->l_info[DT_BIND_NOW] !=3D NULL) > lazy =3D 0; > =20 > if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_RELOC)) > @@ -285,8 +283,6 @@ _dl_relocate_object (struct link_map *l, struct r_sco= pe_elem *scope[], > { > /* Do the actual relocation of the object's GOT and other data. */ > =20 > - ELF_DYNAMIC_RELOCATE (l, scope, lazy, consider_profiling, skip_ifunc= ); > - > #ifndef PROF > if (consider_profiling | consider_symbind > =09&& l->l_info[DT_PLTRELSZ] !=3D NULL) > @@ -309,6 +305,8 @@ _dl_relocate_object (struct link_map *l, struct r_sco= pe_elem *scope[], > =09 } > } > #endif > + > + ELF_DYNAMIC_RELOCATE (l, scope, lazy, consider_profiling, skip_ifunc= ); > } I don't understand why this is needed. Can we indeed use the profiling trampoline with a BIND_NOW binding? If not, then we shouldn't need the allocation of l_reloc_result, either. We should patch in the changed symbol variable directly, not going through l_reloc_result. Thanks, Florian