Re: [PATCH v1 3/5] cpukit/libdl: Add support for AArch64

2022-07-21 Thread Chris Johns
On 22/7/2022 1:11 am, Ryan Long wrote:
> On 7/20/2022 11:39 PM, Chris Johns wrote:
>> On 21/7/2022 7:36 am, Ryan Long wrote:
>>> rtl-mdreloc-aarch64.c and elf_machdep.h came from NetBSD.
>>> +bool
>>> +rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
>>> +{
>>> +  obj->loader = NULL;
>> You cannot touch this field. It belongs to the format loader.
> I copied this method from rtl-mdreloc-arm.c, and it's the same way there.

I think it is wrong in both places.

Should these calls also be moved to rtl-unwind-arm.[ch]?

>>> +_Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address,
>>> + int*    nrec)
>>> +{
>>> +  rtems_rtl_data*   rtl;
>>> +  rtems_chain_node* node;
>>> +  __EIT_entry*  exidx_start = &__exidx_start;
>>> +  __EIT_entry*  exidx_end = &__exidx_end;
>>> +
>>> +  rtl = rtems_rtl_lock ();
>>> +
>>> +  node = rtems_chain_first (>objects);
>>> +  while (!rtems_chain_is_tail (>objects, node)) {
>>> +    rtems_rtl_obj* obj = (rtems_rtl_obj*) node;
>>> +    if (rtems_rtl_obj_text_inside (obj, (void*) return_address)) {
>>> +  exidx_start = (__EIT_entry*) obj->eh_base;
>>> +  exidx_end = (__EIT_entry*) (obj->eh_base + obj->eh_size);
>>> +  break;
>>> +    }
>>> +    node = rtems_chain_next (node);
>>> +  }
>> Can the RTL chain iterator be used here?
> I got this from rtl-mdreloc-arm.c.

I think using the iterator would a good change once the code moves.

>>> +
>>> +  rtems_rtl_unlock ();
>>> +
>>> +  *nrec = exidx_end - exidx_start;
>>> +
>>> +  return (_Unwind_Ptr) exidx_start;
>>> +}
>> Can this exception unwind support be placed in rtl-unwind-arm.[ch]?
>>
>> I suppose you will need to reference the call from here to bring the symbol 
>> into
>> the link and override the weak version in gcc?
>>
>> Chris
> Is it alright if I implement this and take it out of rtl-mdreloc-aarch64.c and
> rtl-mdreloc-arm.c in a follow up patch?

Of course and thanks.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH v1 3/5] cpukit/libdl: Add support for AArch64

2022-07-21 Thread Ryan Long



On 7/20/2022 11:39 PM, Chris Johns wrote:

On 21/7/2022 7:36 am, Ryan Long wrote:

rtl-mdreloc-aarch64.c and elf_machdep.h came from NetBSD.

Updates #4682
---
  cpukit/libdl/rtl-mdreloc-aarch64.c| 598 ++
  .../cpu/aarch64/include/machine/elf_machdep.h | 256 
  spec/build/cpukit/objdl.yml   |   2 +
  spec/build/cpukit/objdlaarch64.yml|  15 +
  spec/build/cpukit/optlibdl.yml|   1 +
  5 files changed, 872 insertions(+)
  create mode 100644 cpukit/libdl/rtl-mdreloc-aarch64.c
  create mode 100644 cpukit/score/cpu/aarch64/include/machine/elf_machdep.h
  create mode 100644 spec/build/cpukit/objdlaarch64.yml

diff --git a/cpukit/libdl/rtl-mdreloc-aarch64.c 
b/cpukit/libdl/rtl-mdreloc-aarch64.c
new file mode 100644
index 00..ded73ad46b
--- /dev/null
+++ b/cpukit/libdl/rtl-mdreloc-aarch64.c
@@ -0,0 +1,598 @@
+/*
+ * Taken from NetBSD and stripped of the relocations not needed on RTEMS.
+ */
+
+/* $NetBSD: mdreloc.c,v 1.14 2020/06/16 21:01:30 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*-
+ * Copyright (c) 2014-2015 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Andrew Turner
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+#ifndef lint
+__RCSID("$NetBSD: mdreloc.c,v 1.14 2020/06/16 21:01:30 joerg Exp $");
+#endif /* not lint */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "rtl-elf.h"
+#include "rtl-error.h"
+#include 
+#include "rtl-unwind.h"
+
+typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
+typedef _Unwind_Word _uw;
+
+struct tls_data {
+   size_t  td_tlsindex;
+   Elf_Addrtd_tlsoffs;
+};
+
+rtems_rtl_elf_rel_status
+rtems_rtl_elf_reloc_rela (
+  rtems_rtl_obj*obj,
+  const Elf_Rela*   rela,
+  const rtems_rtl_obj_sect* sect,
+  const char*   symname,
+  const Elf_Bytesyminfo,
+  const Elf_Wordsymvalue,
+  const boolparsing
+);
+
+#define __BITS(hi,lo)((~((~(Elf_Addr)0)<<((hi)+1)))&((~(Elf_Addr)0)<<(lo)))

Re: [PATCH v1 3/5] cpukit/libdl: Add support for AArch64

2022-07-20 Thread Chris Johns
On 21/7/2022 7:36 am, Ryan Long wrote:
> rtl-mdreloc-aarch64.c and elf_machdep.h came from NetBSD.
> 
> Updates #4682
> ---
>  cpukit/libdl/rtl-mdreloc-aarch64.c| 598 ++
>  .../cpu/aarch64/include/machine/elf_machdep.h | 256 
>  spec/build/cpukit/objdl.yml   |   2 +
>  spec/build/cpukit/objdlaarch64.yml|  15 +
>  spec/build/cpukit/optlibdl.yml|   1 +
>  5 files changed, 872 insertions(+)
>  create mode 100644 cpukit/libdl/rtl-mdreloc-aarch64.c
>  create mode 100644 cpukit/score/cpu/aarch64/include/machine/elf_machdep.h
>  create mode 100644 spec/build/cpukit/objdlaarch64.yml
> 
> diff --git a/cpukit/libdl/rtl-mdreloc-aarch64.c 
> b/cpukit/libdl/rtl-mdreloc-aarch64.c
> new file mode 100644
> index 00..ded73ad46b
> --- /dev/null
> +++ b/cpukit/libdl/rtl-mdreloc-aarch64.c
> @@ -0,0 +1,598 @@
> +/*
> + * Taken from NetBSD and stripped of the relocations not needed on RTEMS.
> + */
> +
> +/* $NetBSD: mdreloc.c,v 1.14 2020/06/16 21:01:30 joerg Exp $ */
> +
> +/*-
> + * Copyright (c) 2014 The NetBSD Foundation, Inc.
> + * All rights reserved.
> + *
> + * This code is derived from software contributed to The NetBSD Foundation
> + * by Matt Thomas of 3am Software Foundry.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *notice, this list of conditions and the following disclaimer in the
> + *documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
> + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
> LIMITED
> + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
> + * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
> + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +/*-
> + * Copyright (c) 2014-2015 The FreeBSD Foundation
> + * All rights reserved.
> + *
> + * Portions of this software were developed by Andrew Turner
> + * under sponsorship from the FreeBSD Foundation.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + *notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *notice, this list of conditions and the following disclaimer in the
> + *documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#include 
> +#ifndef lint
> +__RCSID("$NetBSD: mdreloc.c,v 1.14 2020/06/16 21:01:30 joerg Exp $");
> +#endif /* not lint */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include "rtl-elf.h"
> +#include "rtl-error.h"
> +#include 
> +#include "rtl-unwind.h"
> +
> +typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
> +typedef _Unwind_Word _uw;
> +
> +struct tls_data {
> + size_t  td_tlsindex;
> + Elf_Addrtd_tlsoffs;
> +};
> +
> +rtems_rtl_elf_rel_status
> +rtems_rtl_elf_reloc_rela (
> +  rtems_rtl_obj*obj,
> +  const Elf_Rela*   rela,
> +  const rtems_rtl_obj_sect* sect,
> +  const char*   symname,
> +  const Elf_Byte  

[PATCH v1 3/5] cpukit/libdl: Add support for AArch64

2022-07-20 Thread Ryan Long
rtl-mdreloc-aarch64.c and elf_machdep.h came from NetBSD.

Updates #4682
---
 cpukit/libdl/rtl-mdreloc-aarch64.c| 598 ++
 .../cpu/aarch64/include/machine/elf_machdep.h | 256 
 spec/build/cpukit/objdl.yml   |   2 +
 spec/build/cpukit/objdlaarch64.yml|  15 +
 spec/build/cpukit/optlibdl.yml|   1 +
 5 files changed, 872 insertions(+)
 create mode 100644 cpukit/libdl/rtl-mdreloc-aarch64.c
 create mode 100644 cpukit/score/cpu/aarch64/include/machine/elf_machdep.h
 create mode 100644 spec/build/cpukit/objdlaarch64.yml

diff --git a/cpukit/libdl/rtl-mdreloc-aarch64.c 
b/cpukit/libdl/rtl-mdreloc-aarch64.c
new file mode 100644
index 00..ded73ad46b
--- /dev/null
+++ b/cpukit/libdl/rtl-mdreloc-aarch64.c
@@ -0,0 +1,598 @@
+/*
+ * Taken from NetBSD and stripped of the relocations not needed on RTEMS.
+ */
+
+/* $NetBSD: mdreloc.c,v 1.14 2020/06/16 21:01:30 joerg Exp $ */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*-
+ * Copyright (c) 2014-2015 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Andrew Turner
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+#ifndef lint
+__RCSID("$NetBSD: mdreloc.c,v 1.14 2020/06/16 21:01:30 joerg Exp $");
+#endif /* not lint */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include "rtl-elf.h"
+#include "rtl-error.h"
+#include 
+#include "rtl-unwind.h"
+
+typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
+typedef _Unwind_Word _uw;
+
+struct tls_data {
+   size_t  td_tlsindex;
+   Elf_Addrtd_tlsoffs;
+};
+
+rtems_rtl_elf_rel_status
+rtems_rtl_elf_reloc_rela (
+  rtems_rtl_obj*obj,
+  const Elf_Rela*   rela,
+  const rtems_rtl_obj_sect* sect,
+  const char*   symname,
+  const Elf_Bytesyminfo,
+  const Elf_Wordsymvalue,
+  const boolparsing
+);
+
+#define __BITS(hi,lo)((~((~(Elf_Addr)0)<<((hi)+1)))&((~(Elf_Addr)0)<<(lo)))
+#define WIDTHMASK(w)  (0xUL >> (64 - (w)))
+
+static inline bool