From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by sourceware.org (Postfix) with ESMTPS id 2A744386F835 for ; Fri, 5 Jun 2020 20:16:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2A744386F835 Received: by mail-qt1-x843.google.com with SMTP id k22so9603226qtm.6 for ; Fri, 05 Jun 2020 13:16:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:autocrypt:subject :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=yC9/IlyOcVnoybvqoeo2L0PgnISEjr7Dr/iVb7oKsFg=; b=kgVaNs7QsCN3Tag+3KUk07qLM1e32j6gj7B7xyOc2e4/o06h1lCgkK4R9zl/Kiq//f VSbhro1xtSEIo5HkArrDa5cd5JrMJzlpRLY5STZOD+r/p3nws8v0URH0EkiCNc2CFc3J /1wBbRv4zO1dccGRjRbGodq0SGHWtumLiSWmwW76c4IDs9Ym6nm26E+Okv4qIEheder1 d0d2I3E0wk5XhEY3goX5qooTc/1Vn5g5rNF8gR+nFu6Pa5mAb7ODMmSKy0Fqk27etcs8 VOV1XOgrHQ3uacxjOlt3kM5M4XxRHDWwg9Xbesje72vs1B/AcagtfkmfWHh0+plJjfjn z5EQ== X-Gm-Message-State: AOAM531hWLF7H/4HoZaz3MiYV+cZusJhD53tmLmvWZm8S0Scp4H1sUks JEfmjqBWqNQp5NE6PePri2fLnQ== X-Google-Smtp-Source: ABdhPJxy/UargPdElKZNfkx6hlUjQGK4QU2HB5//0QCbVvfyyeoS8/CCvQY97YgpcsUfEuVEeNvpHw== X-Received: by 2002:aed:3f17:: with SMTP id p23mr12051692qtf.346.1591388166512; Fri, 05 Jun 2020 13:16:06 -0700 (PDT) Received: from [192.168.1.4] ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id d16sm796244qte.49.2020.06.05.13.16.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Jun 2020 13:16:06 -0700 (PDT) To: Vineet Gupta , libc-alpha@sourceware.org Cc: linux-snps-arc@lists.infradead.org References: <20200601221823.17861-1-vgupta@synopsys.com> <20200601221823.17861-2-vgupta@synopsys.com> From: Adhemerval Zanella Autocrypt: addr=adhemerval.zanella@linaro.org; prefer-encrypt=mutual; keydata= mQINBFcVGkoBEADiQU2x/cBBmAVf5C2d1xgz6zCnlCefbqaflUBw4hB/bEME40QsrVzWZ5Nq 8kxkEczZzAOKkkvv4pRVLlLn/zDtFXhlcvQRJ3yFMGqzBjofucOrmdYkOGo0uCaoJKPT186L NWp53SACXguFJpnw4ODI64ziInzXQs/rUJqrFoVIlrPDmNv/LUv1OVPKz20ETjgfpg8MNwG6 iMizMefCl+RbtXbIEZ3TE/IaDT/jcOirjv96lBKrc/pAL0h/O71Kwbbp43fimW80GhjiaN2y WGByepnkAVP7FyNarhdDpJhoDmUk9yfwNuIuESaCQtfd3vgKKuo6grcKZ8bHy7IXX1XJj2X/ BgRVhVgMHAnDPFIkXtP+SiarkUaLjGzCz7XkUn4XAGDskBNfbizFqYUQCaL2FdbW3DeZqNIa nSzKAZK7Dm9+0VVSRZXP89w71Y7JUV56xL/PlOE+YKKFdEw+gQjQi0e+DZILAtFjJLoCrkEX w4LluMhYX/X8XP6/C3xW0yOZhvHYyn72sV4yJ1uyc/qz3OY32CRy+bwPzAMAkhdwcORA3JPb kPTlimhQqVgvca8m+MQ/JFZ6D+K7QPyvEv7bQ7M+IzFmTkOCwCJ3xqOD6GjX3aphk8Sr0dq3 4Awlf5xFDAG8dn8Uuutb7naGBd/fEv6t8dfkNyzj6yvc4jpVxwARAQABtElBZGhlbWVydmFs IFphbmVsbGEgTmV0dG8gKExpbmFybyBWUE4gS2V5KSA8YWRoZW1lcnZhbC56YW5lbGxhQGxp bmFyby5vcmc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B9vQMTBJ2d4+m/qO6+ cFTAceXmIoFsN8+gFN3i8Is3u12u8xGudcBPvpoy4OoG Subject: Re: [PATCH v2 1/2] dl-runtime: reloc_{offset,index} now functions arch overide'able Message-ID: <34af7ce6-e0a2-1391-3be3-a4df7fc10ecd@linaro.org> Date: Fri, 5 Jun 2020 17:16:03 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200601221823.17861-2-vgupta@synopsys.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-15.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: 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: Fri, 05 Jun 2020 20:16:09 -0000 On 01/06/2020 19:18, Vineet Gupta wrote: > The existing macros are fragile and expect local variables with a > certain name. Fix this by defining them as functions with default > implementation in a new header dl-runtime.h which arches can override > if need be. > > This came up during ARC port review, hence the need for argument pltgot > in reloc_index() which is not needed by existing ports. > > This patch potentially only affects hppa/x86 ports, > build tested for both those configs and a few more. > > Suggested-by: Adhemerval Zanella LGTM, thanks. There are just style nits in the one-line comment for new files. Reviewed-by: Adhemerval Zanella > --- > elf/dl-runtime.c | 28 +++++++++++++++++----------- > elf/dl-runtime.h | 30 ++++++++++++++++++++++++++++++ > sysdeps/hppa/dl-runtime.c | 4 ---- > sysdeps/hppa/dl-runtime.h | 31 +++++++++++++++++++++++++++++++ > sysdeps/x86_64/dl-runtime.c | 9 --------- > sysdeps/x86_64/dl-runtime.h | 35 +++++++++++++++++++++++++++++++++++ > 6 files changed, 113 insertions(+), 24 deletions(-) > create mode 100644 elf/dl-runtime.h > create mode 100644 sysdeps/hppa/dl-runtime.h > delete mode 100644 sysdeps/x86_64/dl-runtime.c > create mode 100644 sysdeps/x86_64/dl-runtime.h > > diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c > index cf5f1d3e82e1..85a229f6f019 100644 > --- a/elf/dl-runtime.c > +++ b/elf/dl-runtime.c > @@ -27,6 +27,7 @@ > #include "dynamic-link.h" > #include > #include > +#include > > > #if (!ELF_MACHINE_NO_RELA && !defined ELF_MACHINE_PLT_REL) \ > @@ -42,13 +43,6 @@ > # define ARCH_FIXUP_ATTRIBUTE > #endif > > -#ifndef reloc_offset > -# define reloc_offset reloc_arg > -# define reloc_index reloc_arg / sizeof (PLTREL) > -#endif > - > - > - > /* This function is called through a special trampoline from the PLT the > first time each PLT entry is called. We must perform the relocation > specified in the PLT of the given shared object, and return the resolved > @@ -68,8 +62,11 @@ _dl_fixup ( > = (const void *) D_PTR (l, l_info[DT_SYMTAB]); > const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]); > > + const uintptr_t pltgot = (uintptr_t) D_PTR (l, l_info[DT_PLTGOT]); > + > const PLTREL *const reloc > - = (const void *) (D_PTR (l, l_info[DT_JMPREL]) + reloc_offset); > + = (const void *) (D_PTR (l, l_info[DT_JMPREL]) > + + reloc_offset (pltgot, reloc_arg)); > const ElfW(Sym) *sym = &symtab[ELFW(R_SYM) (reloc->r_info)]; > const ElfW(Sym) *refsym = sym; > void *const rel_addr = (void *)(l->l_addr + reloc->r_offset); Ok. > @@ -180,9 +177,12 @@ _dl_profile_fixup ( > l, reloc_arg); > } > > + const uintptr_t pltgot = (uintptr_t) D_PTR (l, l_info[DT_PLTGOT]); > + > /* This is the address in the array where we store the result of previous > relocations. */ > - struct reloc_result *reloc_result = &l->l_reloc_result[reloc_index]; > + struct reloc_result *reloc_result > + = &l->l_reloc_result[reloc_index (pltgot, reloc_arg, sizeof (PLTREL))]; > > /* CONCURRENCY NOTES: > Ok. > @@ -219,8 +219,11 @@ _dl_profile_fixup ( > = (const void *) D_PTR (l, l_info[DT_SYMTAB]); > const char *strtab = (const char *) D_PTR (l, l_info[DT_STRTAB]); > > + const uintptr_t pltgot = (uintptr_t) D_PTR (l, l_info[DT_PLTGOT]); > + > const PLTREL *const reloc > - = (const void *) (D_PTR (l, l_info[DT_JMPREL]) + reloc_offset); > + = (const void *) (D_PTR (l, l_info[DT_JMPREL]) > + + reloc_offset (pltgot, reloc_arg)); > const ElfW(Sym) *refsym = &symtab[ELFW(R_SYM) (reloc->r_info)]; > const ElfW(Sym) *defsym = refsym; > lookup_t result; Ok. > @@ -485,11 +488,14 @@ _dl_call_pltexit (struct link_map *l, ElfW(Word) reloc_arg, > const void *inregs, void *outregs) > { > #ifdef SHARED > + const uintptr_t pltgot = (uintptr_t) D_PTR (l, l_info[DT_PLTGOT]); > + > /* This is the address in the array where we store the result of previous > relocations. */ > // XXX Maybe the bound information must be stored on the stack since > // XXX with bind_not a new value could have been stored in the meantime. > - struct reloc_result *reloc_result = &l->l_reloc_result[reloc_index]; > + struct reloc_result *reloc_result = > + &l->l_reloc_result[reloc_index (pltgot, reloc_arg, sizeof (PLTREL))]; > ElfW(Sym) *defsym = ((ElfW(Sym) *) D_PTR (reloc_result->bound, > l_info[DT_SYMTAB]) > + reloc_result->boundndx); Ok. > diff --git a/elf/dl-runtime.h b/elf/dl-runtime.h > new file mode 100644 > index 000000000000..dd87d799465e > --- /dev/null > +++ b/elf/dl-runtime.h > @@ -0,0 +1,30 @@ > +/* Helpers for On-demand PLT fixup for shared objects. Generic version. Double space after period. > + Copyright (C) 2020 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, write to the Free > + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA > + 02111-1307 USA. */ > + > +static inline uintptr_t > +reloc_offset (uintptr_t plt0, uintptr_t pltn) > +{ > + return pltn; > +} > + > +static inline uintptr_t > +reloc_index (uintptr_t plt0, uintptr_t pltn, size_t size) > +{ > + return pltn / size; > +} Ok. > diff --git a/sysdeps/hppa/dl-runtime.c b/sysdeps/hppa/dl-runtime.c > index 885a3f1837cb..2d061b150f06 100644 > --- a/sysdeps/hppa/dl-runtime.c > +++ b/sysdeps/hppa/dl-runtime.c > @@ -17,10 +17,6 @@ > Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA > 02111-1307 USA. */ > > -/* Clear PA_GP_RELOC bit in relocation offset. */ > -#define reloc_offset (reloc_arg & ~PA_GP_RELOC) > -#define reloc_index (reloc_arg & ~PA_GP_RELOC) / sizeof (PLTREL) > - > #include > > /* The caller has encountered a partially relocated function descriptor. Ok. > diff --git a/sysdeps/hppa/dl-runtime.h b/sysdeps/hppa/dl-runtime.h > new file mode 100644 > index 000000000000..be3bc929c74c > --- /dev/null > +++ b/sysdeps/hppa/dl-runtime.h > @@ -0,0 +1,31 @@ > +/* Helpers for On-demand PLT fixup for shared objects. HPAA version. Double space after period. > + Copyright (C) 2020 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, write to the Free > + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA > + 02111-1307 USA. */ > + > +/* Clear PA_GP_RELOC bit in relocation offset. */ > +static inline uintptr_t > +reloc_offset (uintptr_t plt0, uintptr_t pltn) > +{ > + return pltn & ~PA_GP_RELOC; > +} > + > +static inline uintptr_t > +reloc_index (uintptr_t plt0, uintptr_t pltn, size_t size) > +{ > + return (pltn & ~PA_GP_RELOC )/ size; > +} Ok, > diff --git a/sysdeps/x86_64/dl-runtime.c b/sysdeps/x86_64/dl-runtime.c > deleted file mode 100644 > index b625d1e88257..000000000000 > --- a/sysdeps/x86_64/dl-runtime.c > +++ /dev/null > @@ -1,9 +0,0 @@ > -/* The ABI calls for the PLT stubs to pass the index of the relocation > - and not its offset. In _dl_profile_fixup and _dl_call_pltexit we > - also use the index. Therefore it is wasteful to compute the offset > - in the trampoline just to reverse the operation immediately > - afterwards. */ > -#define reloc_offset reloc_arg * sizeof (PLTREL) > -#define reloc_index reloc_arg > - > -#include Ok. > diff --git a/sysdeps/x86_64/dl-runtime.h b/sysdeps/x86_64/dl-runtime.h > new file mode 100644 > index 000000000000..b82fdce8367d > --- /dev/null > +++ b/sysdeps/x86_64/dl-runtime.h > @@ -0,0 +1,35 @@ > +/* Helpers for On-demand PLT fixup for shared objects. x86_64 version. Double space after period. > + Copyright (C) 2020 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, write to the Free > + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA > + 02111-1307 USA. */ > + > +/* The ABI calls for the PLT stubs to pass the index of the relocation > + and not its offset. In _dl_profile_fixup and _dl_call_pltexit we > + also use the index. Therefore it is wasteful to compute the offset > + in the trampoline just to reverse the operation immediately > + afterwards. */ > +static inline uintptr_t > +reloc_offset (uintptr_t plt0, uintptr_t pltn) > +{ > + return pltn * sizeof (ElfW(Rela)); > +} > + > +static inline uintptr_t > +reloc_index (uintptr_t plt0, uintptr_t pltn, size_t size) > +{ > + return pltn; > +} > Ok.