linux-snps-arc.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Vineet Gupta <Vineet.Gupta1@synopsys.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
	"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>
Cc: arcml <linux-snps-arc@lists.infradead.org>
Subject: Re: [PATCH v6 01/13] ARC: ABI Implementation
Date: Wed, 27 May 2020 22:15:29 +0000	[thread overview]
Message-ID: <f36112c7-b7d6-243a-73eb-74d5b3772135@synopsys.com> (raw)
In-Reply-To: <88508d10-2d29-026a-bb54-ad607154ab87@linaro.org>

On 5/27/20 11:26 AM, Adhemerval Zanella via Libc-alpha wrote:
> 
> 
> On 22/04/2020 22:41, Vineet Gupta via Libc-alpha wrote:
>> This code deals with the ARC ABI.
>>
>> Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
> 
> We do not use DCO, but rather copyright assignment.

Right, removed that now.

> Looks ok in general, with some comments below.

Thx for taking a look.

>> +;@ r1 = value that setjmp( ) will return due to this longjmp
> 
> Since all .S files are processed by gcc assembly implementation usually
> use C style comment (/* ... */). Same applies to other assembly
> implementations.

OK, I can update throughout, although I like the small assembler comments which
are on the same line.


>> diff --git a/sysdeps/arc/dl-runtime.c b/sysdeps/arc/dl-runtime.c
>> new file mode 100644
>> index 000000000000..b28da38329f1
>> --- /dev/null
>> +++ b/sysdeps/arc/dl-runtime.c
>> @@ -0,0 +1,33 @@
>> +/* dl-runtime helpers for ARC.
>> +   Copyright (C) 2017-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, see
>> +   <https://www.gnu.org/licenses/>.  */
>> +
>> +/* PLT jump into resolver passes PC of PLTn, while _dl_fixup expects the
>> +   address of corresponding .rela.plt entry.  */
>> +
>> +#define reloc_index						\
>> +({								\
>> +  unsigned long int plt0 = D_PTR (l, l_info[DT_PLTGOT]);	\
>> +  unsigned long int pltn = reloc_arg;				\
>> +  /* Exclude PLT0 and PLT1.  */					\
>> +  unsigned long int idx = ((pltn - plt0) / 16) - 2;		\
>> +  idx;								\
>> +})
>> +
>> +#define reloc_offset reloc_index * sizeof (PLTREL)
>> +
>> +#include <elf/dl-runtime.c>
> 
> Ok, although this kid of macro are really error-prone: it relies on
> not specified arguments (l, reloc_arg) and its variable definition might
> clash.
> 
> I wonder if it would be better to refactor both reloc_index and
> reloc_offset to inline function that might be overriden by the
> architecture where required. Something like:
> 
> diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c
> index cf5f1d3e82..62f9057937 100644
> --- a/elf/dl-runtime.c
> +++ b/elf/dl-runtime.c
> @@ -27,6 +27,7 @@
>  #include "dynamic-link.h"
>  #include <tls.h>
>  #include <dl-irel.h>
> +#include <dl-runtime.h>
>  
>  
>  #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);
> @@ -182,7 +179,8 @@ _dl_profile_fixup (
>  
>    /* 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 (reloc_arg, sizeof (PLTREL))];
>  
>   /* CONCURRENCY NOTES:
>  
> @@ -219,8 +217,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;
> @@ -489,7 +490,8 @@ _dl_call_pltexit (struct link_map *l, ElfW(Word) reloc_arg,
>       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 (reloc_arg, sizeof (PLTREL))];
>    ElfW(Sym) *defsym = ((ElfW(Sym) *) D_PTR (reloc_result->bound,
>  					    l_info[DT_SYMTAB])
>  		       + reloc_result->boundndx);
> diff --git a/elf/dl-runtime.h b/elf/dl-runtime.h
> new file mode 100644
> index 0000000000..901249f912
> --- /dev/null
> +++ b/elf/dl-runtime.h
> @@ -0,0 +1,11 @@
> +static inline uintptr_t
> +reloc_offset (uintptr_t plt0, uintptr_t pltn)
> +{
> +  return pltn;
> +}
> +
> +static inline uintptr_t
> +reloc_index (uintptr_t pltn, size_t size)
> +{
> +  return pltn / size;
> +}
> diff --git a/sysdeps/hppa/dl-runtime.c b/sysdeps/hppa/dl-runtime.c
> index 885a3f1837..2d061b150f 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 <elf/dl-runtime.c>
>  
>  /* The caller has encountered a partially relocated function descriptor.
> diff --git a/sysdeps/hppa/dl-runtime.h b/sysdeps/hppa/dl-runtime.h
> new file mode 100644
> index 0000000000..dc12fd1071
> --- /dev/null
> +++ b/sysdeps/hppa/dl-runtime.h
> @@ -0,0 +1,12 @@
> +/* 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 pltn, size_t size)
> +{
> +  return (pltn & ~PA_GP_RELOC )/ size;
> +}
> diff --git a/sysdeps/x86_64/dl-runtime.c b/sysdeps/x86_64/dl-runtime.h
> similarity index 60%
> rename from sysdeps/x86_64/dl-runtime.c
> rename to sysdeps/x86_64/dl-runtime.h
> index b625d1e882..494ff47b70 100644
> --- a/sysdeps/x86_64/dl-runtime.c
> +++ b/sysdeps/x86_64/dl-runtime.h
> @@ -3,7 +3,14 @@
>     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
> +static inline uintptr_t
> +reloc_offset (uintptr_t plt0, uintptr_t pltn)
> +{
> +  return pltn * sizeof (ElfW(Rela));
> +}
>  
> -#include <elf/dl-runtime.c>
> +static inline uintptr_t
> +reloc_index (uintptr_t pltn, size_t size)
> +{
> +  return pltn;
> +}

Indeed looks much sane now. Do you want me to break out this code as a separate
patch, ahead of the series ?

>> +
>> +.macro RESTORE_CALLER_SAVED_BUT_R0
>> +	ld.ab	blink,[sp, 4]
>> +	cfi_adjust_cfa_offset (-4)
>> +	cfi_restore (blink)
>> +	ld.ab	r9, [sp, 4]
>> +	ld.ab	r8, [sp, 4]
>> +	ld.ab	r7, [sp, 4]
>> +	ld.ab	r6, [sp, 4]
>> +	ld.ab	r5, [sp, 4]
>> +	ld.ab	r4, [sp, 4]
>> +	pop_s   r3
>> +	pop_s   r2
>> +	pop_s   r1
>> +	cfi_adjust_cfa_offset (-36)
>> +.endm
>> +
>> +/* Upon entry, PLTn, which led us here, sets up the following regs
>> +	r11 = Module info (tpnt pointer as expected by resolver)
>> +	r12 = PC of the PLTn itself - needed by resolver to find
>> +	      corresponding .rela.plt entry.  */
>> +
>> +ENTRY (_dl_runtime_resolve)
>> +	; args to func being resolved, which resolver might clobber
>> +	SAVE_CALLER_SAVED
>> +
>> +	mov_s 	r1, r12
>> +	bl.d  	_dl_fixup
>> +	mov   	r0, r11
>> +
>> +	RESTORE_CALLER_SAVED_BUT_R0
>> +	j_s.d   [r0]    /* r0 has resolved function addr.  */
>> +	pop_s   r0      /* restore first arg to resolved call.  */
>> +	cfi_adjust_cfa_offset (-4)
>> +	cfi_restore (r0)
>> +END (_dl_runtime_resolve)
> 
> Ok, although I am not seeing why exactly you need asm macros here.

Yes this is just a relic of code from the past, I can opencode it.

>> diff --git a/sysdeps/arc/gccframe.h b/sysdeps/arc/gccframe.h
>> new file mode 100644
>> index 000000000000..5d547fd40a6c
>> --- /dev/null
>> +++ b/sysdeps/arc/gccframe.h
>> @@ -0,0 +1,21 @@
>> +/* Definition of object in frame unwind info.  ARC version.
>> +   Copyright (C) 2017-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, see
>> +   <https://www.gnu.org/licenses/>.  */
>> +
>> +#define FIRST_PSEUDO_REGISTER 40
>> +
>> +#include <sysdeps/generic/gccframe.h>
> 
> Ok.
> 
>> diff --git a/sysdeps/arc/jmpbuf-offsets.h b/sysdeps/arc/jmpbuf-offsets.h
>> new file mode 100644

>> +
>> +/* Callee Regs.  */
>> +#define JB_R13 0
>> +#define JB_R14 1
>> +#define JB_R15 2
>> +#define JB_R16 3
>> +#define JB_R17 4
>> +#define JB_R18 5
>> +#define JB_R19 6
>> +#define JB_R20 7
>> +#define JB_R21 8
>> +#define JB_R22 9
>> +#define JB_R23 10
>> +#define JB_R24 11
>> +#define JB_R25 12

I'll probably drop these as these are not used anyways. Also will help declutter
on the next architecture where the ABI for callee regs is changed from r13-25 to
r14-r26.

>> +
>> +/* Frame Pointer, Stack Pointer, Branch-n-link.  */
>> +#define JB_FP  13
>> +#define JB_SP  14
>> +#define JB_BLINK  15
>> +
>> +/* We save space for some extra state to accommodate future changes
>> +   This is number of words.  */
>> +#define JB_NUM	32
>> +
>> +/* Helper for generic ____longjmp_chk.  */
>> +#define JB_FRAME_ADDRESS(buf) ((void *) (unsigned long int) (buf[JB_SP]))
> 
> Ok.
> 

>> diff --git a/sysdeps/arc/memusage.h b/sysdeps/arc/memusage.h

>> +
>> +#define GETSP() ({ register uintptr_t stack_ptr asm ("sp"); stack_ptr; })
>> +
>> +#define uatomic32_t unsigned int
> 
> Not sure if this is really required now that we are moving to C11 atomic
> model withing glibc itself. Maybe we could just use uint32_t on
> malloc/memusage.c and rely on atomic macros instead.

But that would be much bigger change, and orthogonal to the port. So perhaps we
add it for now and then do the bigger/sweeping change.
_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

  parent reply	other threads:[~2020-05-27 22:16 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-23  1:41 [PATCH v6 00/13] glibc port to ARC processors Vineet Gupta
2020-04-23  1:41 ` [PATCH v6 01/13] ARC: ABI Implementation Vineet Gupta
     [not found]   ` <88508d10-2d29-026a-bb54-ad607154ab87@linaro.org>
2020-05-27 22:15     ` Vineet Gupta [this message]
2020-05-29 13:56       ` Adhemerval Zanella
     [not found]     ` <a56a35d4-3e9e-9a88-4be5-8553d5f11ad3@synopsys.com>
     [not found]       ` <87mu5jxkv7.fsf@oldenburg2.str.redhat.com>
2020-06-04 19:01         ` Vineet Gupta
2020-06-04 23:56           ` Vineet Gupta
2020-04-23  1:41 ` [PATCH v6 02/13] ARC: startup and dynamic linking code Vineet Gupta
     [not found]   ` <17957ee6-2bc1-f43b-f184-f0703ba2765f@linaro.org>
2020-05-28  1:14     ` Vineet Gupta
2020-04-23  1:41 ` [PATCH v6 03/13] ARC: Thread Local Storage support Vineet Gupta
     [not found]   ` <4f7a67fb-6f96-57e6-b827-d1ab5dd6733f@linaro.org>
2020-05-28  1:36     ` Vineet Gupta
2020-06-01 18:53       ` Adhemerval Zanella
2020-04-23  1:41 ` [PATCH v6 04/13] ARC: Atomics and Locking primitives Vineet Gupta
     [not found]   ` <03f4a9b3-b1ca-90fa-0b6a-609a3135267d@linaro.org>
2020-04-24  7:23     ` Vineet Gupta
     [not found]     ` <20200427215938.14136-1-vgupta@synopsys.com>
2020-04-27 22:13       ` [PATCH] semaphore: consolidate arch headers into a generic one Vineet Gupta
     [not found]       ` <ac93c301-36d3-b20a-d31c-50c1f3264c68@linaro.org>
2020-05-05 22:59         ` Vineet Gupta
2020-05-08 13:32           ` Adhemerval Zanella
2020-04-23  1:41 ` [PATCH v6 05/13] ARC: math soft float support Vineet Gupta
2020-04-23  1:41 ` [PATCH v6 06/13] ARC: hardware floating point support Vineet Gupta
2020-05-29 14:12   ` Adhemerval Zanella
2020-05-29 22:28     ` Vineet Gupta
2020-05-29 23:50       ` Vineet Gupta
2020-06-02 17:51         ` Joseph Myers
     [not found]         ` <07887c48-7e07-9f89-035d-3f336a16f2da@synopsys.com>
2020-06-02 18:13           ` static inline math functions (was Re: [PATCH v6 06/13] ARC: hardware floating point support) Joseph Myers
2020-06-02 18:35             ` Adhemerval Zanella
2020-06-05  4:44         ` [PATCH v6 06/13] ARC: hardware floating point support Vineet Gupta
2020-06-05 17:22           ` Adhemerval Zanella
2020-06-02 17:48       ` Joseph Myers
2020-04-23  1:41 ` [PATCH v6 07/13] ARC: Linux Syscall Interface Vineet Gupta
2020-05-29 16:49   ` Adhemerval Zanella
2020-05-30  2:02     ` Vineet Gupta
2020-06-03 19:46     ` Vineet Gupta
2020-06-03 20:04       ` Adhemerval Zanella
2020-06-03 20:17         ` Vineet Gupta
2020-06-04 11:06           ` Adhemerval Zanella
2020-04-23  1:41 ` [PATCH v6 08/13] ARC: Linux ABI Vineet Gupta
2020-04-23  1:41 ` [PATCH v6 09/13] ARC: Linux Startup and Dynamic Loading Vineet Gupta
2020-04-23  1:41 ` [PATCH v6 10/13] ARC: ABI lists Vineet Gupta
2020-04-23  1:41 ` [PATCH v6 11/13] ARC: Build Infrastructure Vineet Gupta
2020-06-03 19:58   ` Adhemerval Zanella
2020-06-04 15:25     ` Vineet Gupta
2020-06-04 17:05       ` Adhemerval Zanella
2020-06-08  4:18         ` Vineet Gupta
2020-04-23  1:41 ` [PATCH v6 12/13] build-many-glibcs.py: Enable ARC builds Vineet Gupta
2020-04-23  1:41 ` [PATCH v6 13/13] Documentation for ARC port Vineet Gupta
2020-05-04 21:21 ` [PATCH v6 00/13] glibc port to ARC processors Vineet Gupta
2020-05-15  0:45   ` Vineet Gupta
2020-05-27  1:49     ` Vineet Gupta
     [not found]       ` <d7f1176c-87c6-90c6-161c-4705a47837ea@linaro.org>
2020-05-27 18:38         ` Vineet Gupta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f36112c7-b7d6-243a-73eb-74d5b3772135@synopsys.com \
    --to=vineet.gupta1@synopsys.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-snps-arc@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).