From patchwork Thu Feb 22 13:42:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 774872 Delivered-To: patch@linaro.org Received: by 2002:a5d:6ac2:0:b0:33b:4db1:f5b3 with SMTP id u2csp771354wrw; Thu, 22 Feb 2024 05:43:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWv+GBT0OT27Yu/n8qP/NAkAWcDfJctjA/GzClQeqwo903grrFKSbJFWKcwfda6B7qS60pEF0h+ANq5fWrubh5v X-Google-Smtp-Source: AGHT+IEGZ0M9K53R2IsLrHBn1sTXhhuPU7d5AIKxRsbdFOiRuvs7lyq0w2Yqy4iGWNcqkdjY+psT X-Received: by 2002:a05:620a:851d:b0:787:3ac1:75b with SMTP id pe29-20020a05620a851d00b007873ac1075bmr23873601qkn.14.1708609394068; Thu, 22 Feb 2024 05:43:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708609394; cv=pass; d=google.com; s=arc-20160816; b=Prf6qyzU4waeCo6c0zJTt2QqyGF9ps+EOpc1P7bOXTYq0cxktZX5Go3vO809m/x0ap KO/UY2zlN+5k8Dd4bMUKYF1blzIA3roRI0Z2wJj5GuvAhE7IWIdI9jKlrXKNgQTVLtiJ VBLovnVr2JlpBxLluOcd9wSVotofL3+tieyJ47JcT3mgkD4Io3h6VgBJKHcRM2o1pazZ o+LFH6rnBtwRpw1ERC4POWupovXw/vNqT9cEJKiWDqAlTCMoSuX34biwSebe7+ORUVQJ 0mmNiERlijL+PBFslVftN7zViPXJYWb8xNQROXHR+Uejfe1WoJya4zM57g5LyTekauIB i+Gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=YYI4VbaTAUhq54mceJ12vEgHTQ1k+ZnU7mnQ9AAUf0U=; fh=kxowym6POAF/T9quUApBdGf/nA7molZxbV2OMoNUxK8=; b=U3Ye4CyGcB0t5Ue8VyS/tsi62dbBhjSZPu3PKHLANulz5KwveRHPRzHpYzaIdf4TQt M9nnRm8jwpUjhw4BajJFmxK1E0YEzOTGKDJY33tJ60GhY/Zi+DiEm7XRsPDfYkb4HXW1 74pT0ZANEx3jeIG38lpfPg0BaBXKMhhIV/R8EyIaGziKwtNHPw9ePhh8o5ko3Fg3n9KK XrU/7iEfBcdy/Lm73fkW5bxJ30OiPZ7zulky+FKJ4PiPNfp4CuKjwN4Awiv4FfPk9RER iDxwZXv7WKCc6O7JkHI5v3xVdduR/CV6ZrP/EPqvK4b00ZOcEFEK+5a1D287wXdv1t9X seXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SoOeOmGQ; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ow37-20020a05620a822500b0078341830e2esi13098081qkn.337.2024.02.22.05.43.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:43:14 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SoOeOmGQ; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2567385840C for ; Thu, 22 Feb 2024 13:43:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 3D3113858D33 for ; Thu, 22 Feb 2024 13:43:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D3113858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3D3113858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::22e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708609383; cv=none; b=G69hUEdvE+K2COq9OYogz4gCyvikbbl3Mvp3V2qem8+bpCpt7HlPniuuKjUVuB8z7LdJObZ3CJChKT2FLtiSJBrz0WRvXI+pBF0LNuTxz+lhqTGAIKsWUk5i1EcTfnJsNoBnvbndhNDdDbsYtdiCFR0q9OTX2tfQVqXNVdr7SAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708609383; c=relaxed/simple; bh=3vd/V4+IaZBvELHuG+T5nCh2p+IFRpDSiFbY/9E/f4Q=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gaUtLdve5BuvEI9XACu6pUY7jHdf8eomo6+BJVVlItgJp05WxFzPFqet1F5DtIsAgMlrvK8wP+GBFadMPQCJXNJvGc48KAS2GuWmvKIPOcJNXFrT0APjP1J97N/PfSxx+4SmrOh1eO3Or/uRR/4IR6KWzn0d8DQmClGWSTgQ6D0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3bba50cd318so5770404b6e.0 for ; Thu, 22 Feb 2024 05:43:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708609380; x=1709214180; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YYI4VbaTAUhq54mceJ12vEgHTQ1k+ZnU7mnQ9AAUf0U=; b=SoOeOmGQwc9F1/5nAMet/jbaJhmub7aF9A4VJduoPLmkgUNvqeT6f/zw4rEgnpH355 guJxx0sufF08T13FFW2GAFjtFgvuMWE6ElqpiUC+U6oPY9z/ygtQ0rP5OzqnOVL+qmmN d1WUWkZuzV4az5owH/F1VUay/e1JKXTSKRSMsAorzuRpSNpOUHHR7/dQNEoI1LnO3Bbw 9oL7n3gwiq1IPfVyg65sV0cUkGvbL/L+ho+0BQBGZZ6ky1U5CuaXjjYN+3Qc6CzgcxtR /vW6ixtNABhqw6BITTlzOwG5wuoPsPzeLFACg5EjpBHeyQ3jTpVLKzEH1Jsd4V8P5fHV L+Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708609380; x=1709214180; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YYI4VbaTAUhq54mceJ12vEgHTQ1k+ZnU7mnQ9AAUf0U=; b=P4SlLB214hD8UdSelGhZECNlVJsrQjnnzNwJQPxXA7jwtAVqmpJPqrtaRBr20bmipz F13PkiY8Ch2zYmbmf5DEuQ0J4C/sTrMSycztYX1FFu3oTTNfu52P5kD4UYEmqnyro8ec 5E+CFAdLNak3ZnVl2Ac7p0oH/FzBejBT+PapRQvkf7b5U2DcQejNsyOhsR2dBx0GUT3S I6tTpTd5W/zItnelbWbofzw6P95HeXz+XoQlWjrVfgPzB3s86PoK6b8r+4sG3Emx0aYC HP8lAuFZb3kWW40CveU3fWL5oirkug3sqX+bcu+OdNRwccVLZVuixNAj8urJpWdq+iN/ Jnmg== X-Gm-Message-State: AOJu0Yx898lDPDCcsQgkvrdBcmYD1fjbRhSuqfmtpveZhrmvpPYIpNh6 5GMyR1coIfsaDFHf7FEFUcE4+BT1LwkAKhMpoKG6cWY6Cjk4KASQEB2dP7tNGsYjKcl01yTuOuO 7 X-Received: by 2002:a05:6808:d51:b0:3c1:533b:55f7 with SMTP id w17-20020a0568080d5100b003c1533b55f7mr16788261oik.12.1708609379866; Thu, 22 Feb 2024 05:42:59 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:18f8:e14e:794b:211f:8b37]) by smtp.gmail.com with ESMTPSA id y17-20020aa78551000000b006e0e66369e5sm10953585pfn.66.2024.02.22.05.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 05:42:59 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Fred Hsueh , Florian Weimer Subject: [PATCH] arm: Use _dl_find_object on __gnu_Unwind_Find_exidx (BZ 31405) Date: Thu, 22 Feb 2024 10:42:55 -0300 Message-Id: <20240222134255.2921498-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org Instead of __dl_iterate_phdr. On ARM dlfo_eh_frame/dlfo_eh_count maps to PT_ARM_EXIDX vaddr start / length. On a Neoverse N1 machine with 160 cores, the following program: $ cat test.c #include #include #include enum { niter = 1024, ntimes = 128, }; static void * tf (void *arg) { int a = (int) arg; for (int i = 0; i < niter; i++) { void *p[ntimes]; for (int j = 0; j < ntimes; j++) p[j] = malloc (a * 128); for (int j = 0; j < ntimes; j++) free (p[j]); } return NULL; } int main (int argc, char *argv[]) { enum { nthreads = 16 }; pthread_t t[nthreads]; for (int i = 0; i < nthreads; i ++) assert (pthread_create (&t[i], NULL, tf, (void *) i) == 0); for (int i = 0; i < nthreads; i++) { void *r; assert (pthread_join (t[i], &r) == 0); assert (r == NULL); } return 0; } $ arm-linux-gnueabihf-gcc -fsanitize=address test.c -o test Improves from ~15s to 0.5s. Checked on arm-linux-gnueabihf. --- elf/Makefile | 2 +- elf/dl-find_object.c | 5 ++-- include/dlfcn.h | 3 ++- sysdeps/arm/find_exidx.c | 57 +++------------------------------------- 4 files changed, 10 insertions(+), 57 deletions(-) diff --git a/elf/Makefile b/elf/Makefile index 5d78b659ce..36c04baf02 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -34,6 +34,7 @@ routines = \ dl-addr \ dl-addr-obj \ dl-early_allocate \ + dl-find_object \ dl-iteratephdr \ dl-libc \ dl-origin \ @@ -60,7 +61,6 @@ dl-routines = \ dl-deps \ dl-exception \ dl-execstack \ - dl-find_object \ dl-fini \ dl-init \ dl-load \ diff --git a/elf/dl-find_object.c b/elf/dl-find_object.c index 940fa5c223..449302eda3 100644 --- a/elf/dl-find_object.c +++ b/elf/dl-find_object.c @@ -356,7 +356,7 @@ _dlfo_lookup (uintptr_t pc, struct dl_find_object_internal *first1, size_t size) } int -_dl_find_object (void *pc1, struct dl_find_object *result) +__dl_find_object (void *pc1, struct dl_find_object *result) { uintptr_t pc = (uintptr_t) pc1; @@ -463,7 +463,8 @@ _dl_find_object (void *pc1, struct dl_find_object *result) return -1; } /* Transaction retry loop. */ } -rtld_hidden_def (_dl_find_object) +hidden_def (__dl_find_object) +weak_alias (__dl_find_object, _dl_find_object) /* _dlfo_process_initial is called twice. First to compute the array sizes from the initial loaded mappings. Second to fill in the diff --git a/include/dlfcn.h b/include/dlfcn.h index a44420fa37..f49ee1b0c9 100644 --- a/include/dlfcn.h +++ b/include/dlfcn.h @@ -4,7 +4,8 @@ #include /* For ElfW. */ #include -rtld_hidden_proto (_dl_find_object) +extern __typeof (_dl_find_object) __dl_find_object; +hidden_proto (__dl_find_object) /* Internally used flag. */ #define __RTLD_DLOPEN 0x80000000 diff --git a/sysdeps/arm/find_exidx.c b/sysdeps/arm/find_exidx.c index d647865e5a..a924d59b9f 100644 --- a/sysdeps/arm/find_exidx.c +++ b/sysdeps/arm/find_exidx.c @@ -16,64 +16,15 @@ . */ #include -#include - -struct unw_eh_callback_data -{ - _Unwind_Ptr pc; - _Unwind_Ptr exidx_start; - int exidx_len; -}; - - -/* Callback to determines if the PC lies within an object, and remember the - location of the exception index table if it does. */ - -static int -find_exidx_callback (struct dl_phdr_info * info, size_t size, void * ptr) -{ - struct unw_eh_callback_data * data; - const ElfW(Phdr) *phdr; - int i; - int match; - _Unwind_Ptr load_base; - - data = (struct unw_eh_callback_data *) ptr; - load_base = info->dlpi_addr; - phdr = info->dlpi_phdr; - - match = 0; - for (i = info->dlpi_phnum; i > 0; i--, phdr++) - { - if (phdr->p_type == PT_LOAD) - { - _Unwind_Ptr vaddr = phdr->p_vaddr + load_base; - if (data->pc >= vaddr && data->pc < vaddr + phdr->p_memsz) - match = 1; - } - else if (phdr->p_type == PT_ARM_EXIDX) - { - data->exidx_start = (_Unwind_Ptr) (phdr->p_vaddr + load_base); - data->exidx_len = phdr->p_memsz; - } - } - - return match; -} - /* Find the exception index table containing PC. */ _Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr pc, int * pcount) { - struct unw_eh_callback_data data; - - data.pc = pc; - data.exidx_start = 0; - if (__dl_iterate_phdr (find_exidx_callback, &data) <= 0) + struct dl_find_object data; + if (__dl_find_object ((void *) pc, &data) < 0) return 0; - - *pcount = data.exidx_len / 8; - return data.exidx_start; + *pcount = data.dlfo_eh_count; + return (_Unwind_Ptr) data.dlfo_eh_frame; }