From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x92e.google.com (mail-ua1-x92e.google.com [IPv6:2607:f8b0:4864:20::92e]) by sourceware.org (Postfix) with ESMTPS id 9A99B385841B for ; Mon, 20 Dec 2021 20:43:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9A99B385841B Received: by mail-ua1-x92e.google.com with SMTP id o63so7624795uao.5 for ; Mon, 20 Dec 2021 12:43:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=srfZrHSUdh1BbC0Srrm0ub56F0p2kFHch93MoF26M2Q=; b=XxEjC1Q/PZ3cYk1UNcT0yo9/07zuP+H0t4hxultlw4zA/u4MB7b/tIq1U9jet7V1rZ LE0VsuCxTTU0TQdxIQepkWmyWzShuyjeHTTFqR9gd8k8jq1udVVHvJOpq4U/5KE13J/c XzzLpXuY32KpMZDoxtAXA5kHgT5Z5FtKRErCxpPO5hN7O8XfcVhabi/3xIPMlfbt4Ckr o7TbSgCm011XwD/kUooy/NhTKXD2nrTjWsXcDK0twaFt+uF9V7HOEffekgpBYL0Alru1 lqtrExgwAXq8NBGT+w3qCKYaqonBBQUd8mPLkPkMny05iJC6mKrniVeWBf8UXrQfqZYO Nsgg== X-Gm-Message-State: AOAM533RG+Jy9zzS+sVI2hHE8YGIvogX7Q8IHQUgOKCOZY6LHmhocbR6 G9V1QLDgQ/hGC6e6u93iAIbVK7F0bBBm7Q== X-Google-Smtp-Source: ABdhPJx8kLwXus7cOB99GOx96Us0c9JHjDMZ3Z2IvnZZKF4fvuLcwWTPQfxn5/+exUdsBACH5+CT+w== X-Received: by 2002:ab0:14c3:: with SMTP id f3mr5980061uae.136.1640033010948; Mon, 20 Dec 2021 12:43:30 -0800 (PST) Received: from ?IPV6:2804:431:c7cb:3b1e:762b:24f5:94b:4e15? ([2804:431:c7cb:3b1e:762b:24f5:94b:4e15]) by smtp.gmail.com with ESMTPSA id u145sm2971443vkb.1.2021.12.20.12.43.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Dec 2021 12:43:30 -0800 (PST) Message-ID: <16d66938-9a41-1982-58f8-72c0259cc891@linaro.org> Date: Mon, 20 Dec 2021 17:43:28 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v6 18/20] elf: Issue la_symbind() for bind-now (BZ #23734) Content-Language: en-US To: Florian Weimer Cc: libc-alpha@sourceware.org, John Mellor-Crummey , Ben Woodard References: <20211115183734.531155-1-adhemerval.zanella@linaro.org> <20211115183734.531155-19-adhemerval.zanella@linaro.org> <87a6gvf5kg.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella In-Reply-To: <87a6gvf5kg.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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 20:43:33 -0000 On 20/12/2021 16:18, Florian Weimer wrote: > I believe this change needs to update elf/sotruss-lib.c: > > uintptr_t > la_symbind (Elf_Sym *sym, unsigned int ndx, uintptr_t *refcook, > uintptr_t *defcook, unsigned int *flags, const char *symname) > { > if (!do_exit) > *flags = 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 >> + $(CC) -nostdlib -nostartfiles -shared -o $@.new $(objpfx)tst-audit24bmod1.os \ >> + -Wl,-z,now >> + $(call after-link,$@.new) >> + mv -f $@.new $@ > > I think you may have to update modules-names-nobuild as well. Ack. > >> # tst-sonamemove links against an older implementation of the library. >> LDFLAGS-tst-sonamemove-linkmod1.so = \ >> -Wl,--version-script=tst-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, >> const ElfW(Sym) *defsym, DL_FIXUP_VALUE_TYPE *value, >> - lookup_t result) >> + lookup_t result, bool bindnow) >> { > > Should “bindow“ be called “for_jmp_slot”? Ok, it does make sense if the idea would be extend not only for functions calls. > >> @@ -229,16 +230,16 @@ _dl_audit_symbind (struct link_map *l, struct reloc_result *reloc_result, >> { >> if (afct->symbind != NULL) >> { >> - uintptr_t new_value = afct->symbind (&sym, >> - reloc_result->boundndx, >> - &l_state->cookie, >> - &result_state->cookie, >> - &flags, >> - strtab2 + defsym->st_name); >> + flags |= bindnow ? LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT : 0; >> + new_value = afct->symbind (&sym, reloc_result->boundndx, >> + &l_state->cookie, >> + &result_state->cookie, &flags, >> + strtab2 + defsym->st_name); >> if (new_value != (uintptr_t) sym.st_value) >> { >> flags |= LA_SYMB_ALTVALUE; >> - sym.st_value = new_value; >> + sym.st_value = bindnow >> + ? DL_FIXUP_BINDNOW_ADDR_VALUE (new_value) : new_value; >> } >> } > > We could error out if the audit callback clears the LA_SYMB_NOPLT* flags > we've set (after fixing sotruss). I don't oppose bumping LAV_CURRENT, it is large change than I envisioned in this change but it makes sense. > > And then we'll have to make this change conditional on the la_version > return value, I think. My understanding from previous discussion is we don't want to support mixed lav versions, so bumping the minimal version should be suffice. It would required older modules to be rebuild against a newer glibc, but I think it should be ok. > >> --- a/elf/dl-reloc.c >> +++ b/elf/dl-reloc.c >> @@ -234,9 +234,7 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[], >> >> /* 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] != NULL, 0)) >> + if (!consider_profiling && l->l_info[DT_BIND_NOW] != NULL) >> lazy = 0; >> >> if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_RELOC)) >> @@ -285,8 +283,6 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[], >> { >> /* Do the actual relocation of the object's GOT and other data. */ >> >> - ELF_DYNAMIC_RELOCATE (l, scope, lazy, consider_profiling, skip_ifunc); >> - >> #ifndef PROF >> if (consider_profiling | consider_symbind >> && l->l_info[DT_PLTRELSZ] != NULL) >> @@ -309,6 +305,8 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[], >> } >> } >> #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. I does not indeed, I just did it to avoid adjusting _dl_audit_symbind. But I agree that not requiring allocate l_reloc_results for bind-now is a better strategy. I will fix it.