Re: [PATCH 04/10 v3] libdw: Add rwlocks for Dwarf and Dwarf_CU

2024-08-16 Thread Mark Wielaard
Hi Aaron,

On Fri, 2024-08-02 at 19:38 -0400, Aaron Merey wrote:
> From: Heather McIntyre 
> 
> Add dwarf_lock for Dwarf as well as abbrev_lock for Dwarf_CU.
> 
>   * libdw/dwarf_begin_elf.c (dwarf_begin_elf): Init dwarf_lock.
>   * libdw/dwarf_end.c (cu_free): Free abbrev_lock.
>   (dwarf_end): Free dwarf_lock.
>   * libdw/libdwP.h (struct Dwarf): Define dwarf_lock.
>   (struct Dwarf_CU): Define abbrev_lock.
>   * libdw/libdw_findcu.c (__libdw_intern_next_unit): Init
> abbrev_lock.
> 
> Signed-off-by: Heather S. McIntyre 
> Signed-off-by: Aaron Merey 
> 
> ---
> v3 changes:
> New patch added in v3 that contains rwlock changes previously in patch 3/9 v2.

The patch itself looks correct. But I think I would have introduced the
locks separately and/or in the first patch that used them (dwarf_getalt
for the dwarf_lock, dwarf_formref_die and __libdw_dieabbrev for
abbrev_lock).

It might also be a good idea to explicitly document which structure
fields are "protected" by the separate locks to make reasoning about
them a little easier.

Cheers,

Mark


Re: [PATCH 05/10 v3] libdw: make dwarf_getalt and dwarf_setalt thread-safe

2024-08-16 Thread Mark Wielaard
On Fri, 2024-08-02 at 19:38 -0400, Aaron Merey wrote:
> From: Heather McIntyre 
> 
>   * libdw/dwarf_getalt.c (dwarf_getalt): Add locking.
>   * libdw/dwarf_setalt.c (dwarf_setalt): Ditto.
> 
> Signed-off-by: Heather S. McIntyre 
> Signed-off-by: Aaron Merey 
> Signed-off-by: Mark Wielaard 
> 
> ---
> v3 changes:
> 
> Check for NULL argument before acquiring lock. Assign result before
> releasing lock.  Include dwarf_setalt.c changes that were previously
> included in patch 5/9 v2.

Cleanups look good. This patch looks good to go.

Thanks,

Mark


Re: [PATCH 09/10 v3] tests: Add eu-search tests

2024-08-16 Thread Mark Wielaard
Hi,

On Fri, 2024-08-02 at 19:38 -0400, Aaron Merey wrote:
> From: Heather McIntyre 
> 
> * tests/eu_search_cfi.c: New file.
> * tests/eu_search_die.c: New file.
> * tests/eu_search_lines.c: New file.
> * tests/eu_search_macros.c: New file.
> * tests/run-eu-search-tests.sh: New test.
> * tests/Makefile.am: Add USE_LOCKS condition for -pthread.
> (check_PROGRAMS): Add eu_search_cfi, eu_search_die,
> eu_search_lines, and eu_search_macros.
> (TESTS): Add run-eu-search-tests.sh
> (eu_search_cfi_LDADD): New variable.
> (eu_search_die_LDADD): New variable.
> (eu_search_lines_LDADD): New variable.
> (eu_search_macros_LDADD): New variable.
> (eu_search_cfi_LDFLAGS): New variable.
> Add -pthread if USE_LOCKS is not defined.
> (eu_search_die_LDFLAGS): Likewise.
> (eu_search_lines_LDFLAGS): Likewise.
> (eu_search_macros_LDFLAGS): Likewise.
> 
> Signed-off-by: Heather S. McIntyre 
> Signed-off-by: Aaron Merey 
> Signed-off-by: Mark Wielaard 
> 
> ---
> No changes between v2 and v3.
> 
> The elfutils testsuite (including the tests added in this patch) passes
> for me on the sourceware buildbots.  However the buildbots do not configure
> elfutils with --enable-thread-safety.  I think we should include this
> configure option when the buildbots run elfutils tests.

yes, once these new tests go in we should add a buildbot build that
uses --enable-thread-safety.

I am sorry to ask for even more work, but could you split this into 4
separate tests/patches with separate run wrappers? That makes things
easier to review. It makes it possible to run them in parallel. And
provides easier to interpret test results.

Also could you fixup the indentation of the tests so it uses the
formatting as in other code, specifically the wide indentation makes
things slightly less readable.

The run-eu-search-tests.sh wrapper is slightly "wrong". The way it runs
the tests under valgrind --tool=helgrind doesn't use/set the test
environment (specifically LD_LIBRARY_PATH) so it is actually testing
the tests against the installed libelf and libdw instead of the just
build libraries.

Also it could just run the tests without valgrind being available. The
tests do various useful sanity tests themselves that are useful even
without extra valgrind checking.

Or if valgrind is available and the user configured using --enable-
valgrind then running the tests under valgrind memcheck would still be
useful.

I suggest adding a new configure option --enable-helgrind and handle
that like --enable-valgrind in the tests/Makefile.am. So it would do
something like:

if USE_HELGRIND
valgrind_cmd=valgrind -q --tool=helgrind --error-exitcode=1
endif

So all tests are run under helgrind (it wouldn't do much for the non-
threaded testcases, but it would be consistent and makes it so
individual new tests don't need any special tricks to be tested under
helgrind).

Thanks,

Mark


Re: [PATCH 07/10 v3] libdw: Make libdw_find_split_unit thread-safe

2024-08-16 Thread Mark Wielaard
Hi,

On Fri, Aug 02, 2024 at 07:38:06PM -0400, Aaron Merey wrote:
> From: Heather McIntyre 
> 
>   * libdw/libdwP.h (struct Dwarf_CU): Add split_lock.
>   * libdw/libdw_find_split_unit.c (__libdw_find_split_unit):
> Add locking.
> 
> Signed-off-by: Heather S. McIntyre 
> Signed-off-by: Aaron Merey 
> Signed-off-by: Mark Wielaard 
> 
> ---
> v3 changes:
> Move Dwarf split_lock code from patch 3/9 v2 to this patch.
> Assign return value before releasing lock.

Looks good this way.

Thanks,

Mark

>  libdw/dwarf_end.c |  1 +
>  libdw/libdwP.h|  3 +++
>  libdw/libdw_find_split_unit.c | 15 +--
>  libdw/libdw_findcu.c  |  1 +
>  4 files changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/libdw/dwarf_end.c b/libdw/dwarf_end.c
> index 487d6ce7..ee3ed74e 100644
> --- a/libdw/dwarf_end.c
> +++ b/libdw/dwarf_end.c
> @@ -69,6 +69,7 @@ cu_free (void *arg)
>  {
>Dwarf_Abbrev_Hash_free (&p->abbrev_hash);
>rwlock_fini (p->abbrev_lock);
> +  rwlock_fini (p->split_lock);
>  
>/* Free split dwarf one way (from skeleton to split).  */
>if (p->unit_type == DW_UT_skeleton
> diff --git a/libdw/libdwP.h b/libdw/libdwP.h
> index 48c34871..8f942433 100644
> --- a/libdw/libdwP.h
> +++ b/libdw/libdwP.h
> @@ -454,6 +454,9 @@ struct Dwarf_CU
>/* Synchronize Dwarf_Die abbrev access.  */
>rwlock_define(, abbrev_lock);
>  
> +  /* Synchronize split Dwarf access.  */
> +  rwlock_define(, split_lock);
> +
>/* Memory boundaries of this CU.  */
>void *startp;
>void *endp;
> diff --git a/libdw/libdw_find_split_unit.c b/libdw/libdw_find_split_unit.c
> index 4005793b..f4f34c5d 100644
> --- a/libdw/libdw_find_split_unit.c
> +++ b/libdw/libdw_find_split_unit.c
> @@ -150,9 +150,18 @@ Dwarf_CU *
>  internal_function
>  __libdw_find_split_unit (Dwarf_CU *cu)
>  {
> +  /* Set result before releasing the lock.  */
> +  Dwarf_CU *result;
> +
> +  rwlock_wrlock(cu->split_lock);
> +
>/* Only try once.  */
>if (cu->split != (Dwarf_CU *) -1)
> -return cu->split;
> +{
> +  result = cu->split;
> +  rwlock_unlock(cu->split_lock);
> +  return result;
> +}
>  
>/* We need a skeleton unit with a comp_dir and [GNU_]dwo_name attributes.
>   The split unit will be the first in the dwo file and should have the
> @@ -207,5 +216,7 @@ __libdw_find_split_unit (Dwarf_CU *cu)
>if (cu->split == (Dwarf_CU *) -1)
>  cu->split = NULL;
>  
> -  return cu->split;
> +  result = cu->split;
> +  rwlock_unlock(cu->split_lock);
> +  return result;
>  }
> diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c
> index 0f46d777..c74e895e 100644
> --- a/libdw/libdw_findcu.c
> +++ b/libdw/libdw_findcu.c
> @@ -178,6 +178,7 @@ __libdw_intern_next_unit (Dwarf *dbg, bool debug_types)
>newp->endp = data->d_buf + newp->end;
>eu_search_tree_init (&newp->locs_tree);
>rwlock_init (newp->abbrev_lock);
> +  rwlock_init (newp->split_lock);
>  
>/* v4 debug type units have version == 4 and unit_type == DW_UT_type.  */
>if (debug_types)
> -- 
> 2.45.2
> 


Re: [PATCH 08/10 v3] libdw: Make libdw_findcu thread-safe

2024-08-16 Thread Mark Wielaard
Hi,

On Fri, Aug 02, 2024 at 07:38:07PM -0400, Aaron Merey wrote:
> From: Heather McIntyre 
> 
>   * libdw/libdw_findcu.c (__libdw_findcu): Add locking.
> 
> Signed-off-by: Heather S. McIntyre 
> Signed-off-by: Aaron Merey 
> Signed-off-by: Mark Wielaard 
> 
> ---
> v3 changes:
> Fix indentation and move rwlock_init calls to other patches in this
> series.

So this is basically a lock around __libdw_intern_next_unit. But there
is also a call to __libdw_intern_next_unit from dwarf_formref_die. So
there should also be a lock there?

>  libdw/libdw_findcu.c | 38 +-
>  1 file changed, 25 insertions(+), 13 deletions(-)
> 
> diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c
> index c74e895e..ee5d 100644
> --- a/libdw/libdw_findcu.c
> +++ b/libdw/libdw_findcu.c
> @@ -245,27 +245,39 @@ __libdw_findcu (Dwarf *dbg, Dwarf_Off start, bool 
> v4_debug_types)
>/* Maybe we already know that CU.  */
>struct Dwarf_CU fake = { .start = start, .end = 0 };
>struct Dwarf_CU **found = eu_tfind (&fake, tree, findcu_cb);
> +  struct Dwarf_CU *result = NULL;
>if (found != NULL)
>  return *found;
>  
> +  rwlock_wrlock (dbg->dwarf_lock);
> +
>if (start < *next_offset)
> +__libdw_seterrno (DWARF_E_INVALID_DWARF);
> +  else
>  {
> -  __libdw_seterrno (DWARF_E_INVALID_DWARF);
> -  return NULL;
> -}
> +  /* No.  Then read more CUs.  */
> +  while (1)
> + {
> +   struct Dwarf_CU *newp
> + = __libdw_intern_next_unit (dbg, v4_debug_types);
>  
> -  /* No.  Then read more CUs.  */
> -  while (1)
> -{
> -  struct Dwarf_CU *newp = __libdw_intern_next_unit (dbg, v4_debug_types);
> -  if (newp == NULL)
> - return NULL;
> +   if (newp == NULL)
> + {
> +   result = NULL;
> +   break;
> + }
>  
> -  /* Is this the one we are looking for?  */
> -  if (start < *next_offset || start == newp->start)
> - return newp;
> +   /* Is this the one we are looking for?  */
> +   if (start < *next_offset || start == newp->start)
> + {
> +   result = newp;
> +   break;
> + }
> + }
>  }
> -  /* NOTREACHED */
> +
> +  rwlock_unlock (dbg->dwarf_lock);
> +  return result;
>  }
>  
>  struct Dwarf_CU *
> -- 
> 2.45.2
> 


Re: [PATCH 06/10 v3] libdwP.h: Add locking to dwarf_formref_die and __libdw_dieabbrev

2024-08-16 Thread Mark Wielaard
On Fri, Aug 02, 2024 at 07:38:05PM -0400, Aaron Merey wrote:
> From: Heather McIntyre 
> 
>   * libdw/dwarf_formref_die.c (dwarf_formref_die): Add locking
> around call to __libdw_intern_next_unit.
> * libdw/libdwP.h (__libdw_dieabbrev): Add locking.
> 
> Signed-off-by: Heather S. McIntyre 
> Signed-off-by: Aaron Merey 
> Signed-off-by: Mark Wielaard 
> 
> v3 changes:
> Move dwarf_setalt.c changes to patch 5/9 v3.
> Set __libdw_dieabbrev result before releasing lock.
> ---
>  libdw/dwarf_formref_die.c |  3 +++
>  libdw/libdwP.h| 25 +
>  2 files changed, 24 insertions(+), 4 deletions(-)
> 
> diff --git a/libdw/dwarf_formref_die.c b/libdw/dwarf_formref_die.c
> index 48ba8194..69d1bf1c 100644
> --- a/libdw/dwarf_formref_die.c
> +++ b/libdw/dwarf_formref_die.c
> @@ -92,7 +92,10 @@ dwarf_formref_die (Dwarf_Attribute *attr, Dwarf_Die 
> *result)
> bool scan_debug_types = false;
> do
>   {
> +   rwlock_wrlock(attr->cu->dbg->dwarf_lock);
> cu = __libdw_intern_next_unit (attr->cu->dbg, scan_debug_types);
> +   rwlock_unlock(attr->cu->dbg->dwarf_lock);
> +
> if (cu == NULL)
>   {
> if (scan_debug_types == false)

Aha, sorry, so there is extra locking around __libdw_intern_next_unit
here. Shouldn't this be combined with the next patch?

Thanks,

Mark


Re: [PATCH 0/3] aarch64: add some core note types name

2024-08-16 Thread Mark Wielaard
Hi,

On Wed, Aug 14, 2024 at 04:51:17PM +0800, Kuan-Ying Lee wrote:
> Patch 1:
>  - Add MTE related regset in core note
> Patch 2:
>  - Add PAC related regset in core note
> Patch 3:
>  - Add some core note types name

This look good. Thanks.  For elf.h we try to keep it in sync with the
glibc elf/elf.h.  Since they recently added the same (and more)
NT_ARM_* constants I'll sync that file seperately before incorporating
your patch.

Did you test the output on a core file that has these new regsets and
core notes with eu-readelf to see if it looks correct?

Thanks,

Mark


[COMMITTED] libelf: Sync elf.h from glibc

2024-08-16 Thread Mark Wielaard
* libelf/elf.h: Adds NT_ARM_{SSVE,ZA,ZT,FPRM}

Signed-off-by: Mark Wielaard 
---
 libelf/elf.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/libelf/elf.h b/libelf/elf.h
index 081742a9c38c..33aea7f743b8 100644
--- a/libelf/elf.h
+++ b/libelf/elf.h
@@ -831,6 +831,10 @@ typedef struct
   control.  */
 #define NT_ARM_PAC_ENABLED_KEYS0x40a   /* AArch64 pointer 
authentication
   enabled keys.  */
+#define NT_ARM_SSVE0x40b   /* ARM Streaming SVE registers.  */
+#define NT_ARM_ZA  0x40c   /* ARM SME ZA registers.  */
+#define NT_ARM_ZT  0x40d   /* ARM SME ZT registers.  */
+#define NT_ARM_FPMR0x40e   /* ARM floating point mode register.  */
 #define NT_VMCOREDD0x700   /* Vmcore Device Dump Note.  */
 #define NT_MIPS_DSP0x800   /* MIPS DSP ASE registers.  */
 #define NT_MIPS_FP_MODE0x801   /* MIPS floating-point mode.  */
-- 
2.46.0



Re: [PATCH 1/3] aarch64: Add NT_ARM_TAGGED_ADDR_CTRL regset

2024-08-16 Thread Mark Wielaard
On Wed, Aug 14, 2024 at 04:51:18PM +0800, Kuan-Ying Lee wrote:
> Add the NT_ARM_TAGGED_ADDR_CTRL regset for aarch64.
> Recognize and print this new core itme.

Thanks, found the description (The corresponding regset is 1 element
of 8 bytes) here
https://docs.kernel.org/arch/arm64/memory-tagging-extension.html

Implementation looks correct.

Pushed,

Mark

> 
> Signed-off-by: Kuan-Ying Lee 
> ---
>  backends/aarch64_corenote.c  | 11 ++-
>  libebl/eblcorenotetypename.c |  1 +
>  2 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/backends/aarch64_corenote.c b/backends/aarch64_corenote.c
> index 905a4b8ab9f5..bd0a4a725411 100644
> --- a/backends/aarch64_corenote.c
> +++ b/backends/aarch64_corenote.c
> @@ -107,6 +107,14 @@ static const Ebl_Core_Item aarch64_syscall_items [] =
>  }
>};
>  
> +static const Ebl_Core_Item aarch64_mte_items [] =
> +  {
> +{
> +  .name = "tag_ctrl", .type = ELF_T_XWORD, .format = 'x',
> +  .offset = 0, .group = "register"
> +}
> +  };
> +
>  #define AARCH64_HWBP_REG(KIND, N)\
>  {
> \
>.name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', 
> \
> @@ -167,6 +175,7 @@ AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
>EXTRA_ITEMS (NT_ARM_TLS, 8, aarch64_tls_items) \
>EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)\
>EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)\
> -  EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items)
> +  EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items) \
> +  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items)
>  
>  #include "linux-core-note.c"
> diff --git a/libebl/eblcorenotetypename.c b/libebl/eblcorenotetypename.c
> index 0e790d062de5..49331bdf76e8 100644
> --- a/libebl/eblcorenotetypename.c
> +++ b/libebl/eblcorenotetypename.c
> @@ -92,6 +92,7 @@ ebl_core_note_type_name (Ebl *ebl, uint32_t type, char 
> *buf, size_t len)
>   KNOWNSTYPE (ARM_HW_BREAK);
>   KNOWNSTYPE (ARM_HW_WATCH);
>   KNOWNSTYPE (ARM_SYSTEM_CALL);
> + KNOWNSTYPE (ARM_TAGGED_ADDR_CTRL);
>   KNOWNSTYPE (SIGINFO);
>   KNOWNSTYPE (FILE);
>  #undef KNOWNSTYPE
> -- 
> 2.43.0
> 


[Bug debuginfod/32063] let debuginfod-find locate pre-installed (/usr/lib/.debug or similar) exec / .debug files

2024-08-16 Thread osandov at osandov dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=32063

Omar Sandoval  changed:

   What|Removed |Added

 CC||osandov at osandov dot com

--- Comment #2 from Omar Sandoval  ---
(In reply to Mark Wielaard from comment #1)
> It actually seems nice to add this functionality to libdebuginfod-client.
> Maybe by adding the same kind of "magic" search paths with something like
> new debuginfod_add_search_paths (debuginfod_client *client, const char
> *paths);
> 
> Where the paths are like those for dwfl_standard_find_debuginfo
> 
> /* The default used by dwfl_standard_find_debuginfo.  */
> #define DEFAULT_DEBUGINFO_PATH ":.debug:/usr/lib/debug"
> 
> hmmm, I see there is no documentation what that search path string means.
> But that could be fixed :)

It's documented in the comment for dwfl_build_id_find_elf:
https://sourceware.org/git/?p=elfutils.git;a=blob;f=libdwfl/libdwfl.h;hb=0abdd2e7979fc18fc5d71af43f95b4827783b0b1#l254.

I think this is a neat idea for the client library, but preferably opt-in since
(as you pointed out) many existing users handle the system paths themselves and
fall back to debuginfod.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Re: [PATCH 2/3] aarch64: Add NT_ARM_PAC_* regset

2024-08-16 Thread Mark Wielaard
Hi,

On Wed, Aug 14, 2024 at 04:51:19PM +0800, Kuan-Ying Lee wrote:
> Add the NT_ARM_PAC_MASK and NT_ARM_PAC_ENABLED_KEYS for aarch64.
> Recognize and print the new core item.

For NT_ARM_PAC_MASK it looks like the user_pac_mask struct, so two 8
byte words. But for NT_ARM_PAC_ENABLED_KEYS I cannot find the
definition. This assumes it is just one 8 byte word. Is that correct?
Can it be more than one?

Thanks,

Mark

> Signed-off-by: Kuan-Ying Lee 
> ---
>  backends/aarch64_corenote.c  | 24 +++-
>  libebl/eblcorenotetypename.c |  2 ++
>  2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/backends/aarch64_corenote.c b/backends/aarch64_corenote.c
> index bd0a4a725411..35c8e8012c7b 100644
> --- a/backends/aarch64_corenote.c
> +++ b/backends/aarch64_corenote.c
> @@ -115,6 +115,26 @@ static const Ebl_Core_Item aarch64_mte_items [] =
>  }
>};
>  
> +static const Ebl_Core_Item aarch64_pac_enabled_items [] =
> +  {
> +{
> +  .name = "enabled_keys", .type = ELF_T_XWORD, .format = 'x',
> +  .offset = 0, .group = "register"
> +}
> +  };
> +
> +static const Ebl_Core_Item aarch64_pac_mask_items [] =
> +  {
> +{
> +  .name = "pauth_dmask", .type = ELF_T_XWORD, .format = 'x',
> +  .offset = 0, .group = "register"
> +},
> +{
> +  .name = "pauth_cmask", .type = ELF_T_XWORD, .format = 'x',
> +  .offset = 8, .group = "register"
> +}
> +  };
> +
>  #define AARCH64_HWBP_REG(KIND, N)\
>  {
> \
>.name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', 
> \
> @@ -176,6 +196,8 @@ AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
>EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)\
>EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)\
>EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items) \
> -  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items)
> +  EXTRA_ITEMS (NT_ARM_TAGGED_ADDR_CTRL, 8, aarch64_mte_items) \
> +  EXTRA_ITEMS (NT_ARM_PAC_ENABLED_KEYS, 8, aarch64_pac_enabled_items) \
> +  EXTRA_ITEMS (NT_ARM_PAC_MASK, 16, aarch64_pac_mask_items)
>  
>  #include "linux-core-note.c"
> diff --git a/libebl/eblcorenotetypename.c b/libebl/eblcorenotetypename.c
> index 49331bdf76e8..3e2f8daa0fd5 100644
> --- a/libebl/eblcorenotetypename.c
> +++ b/libebl/eblcorenotetypename.c
> @@ -93,6 +93,8 @@ ebl_core_note_type_name (Ebl *ebl, uint32_t type, char 
> *buf, size_t len)
>   KNOWNSTYPE (ARM_HW_WATCH);
>   KNOWNSTYPE (ARM_SYSTEM_CALL);
>   KNOWNSTYPE (ARM_TAGGED_ADDR_CTRL);
> + KNOWNSTYPE (ARM_PAC_ENABLED_KEYS);
> + KNOWNSTYPE (ARM_PAC_MASK);
>   KNOWNSTYPE (SIGINFO);
>   KNOWNSTYPE (FILE);
>  #undef KNOWNSTYPE
> -- 
> 2.43.0
> 


Re: [PATCH 3/3] aarch64: add some new core note types name

2024-08-16 Thread Mark Wielaard
Hi,

On Wed, Aug 14, 2024 at 04:51:20PM +0800, Kuan-Ying Lee wrote:
> Recognize names of some new core note types in ebl_core_note_type_name.

Thanks. Pushed the eblcorenotetypename.c part.
I pushed a glibc elf.h sync separately (commit 0abdd2e79).

Cheers,

Mark


Re: [PATCH 5/5] libdwfl, aarch64: Read PAC mask from core

2024-08-16 Thread Mark Wielaard
Hi Steve,

On Fri, Jun 14, 2024 at 03:47:19PM +0100, Steve Capper wrote:
> We need to read the PAC mask from a core file when debugging offline
> as the information is still needed to demangle return addresses.
> 
> This commit pulls out the NT_ARM_PAC_MASK info from the core and feeds
> it through to dwfl_thread_state_aarch64_pauth for each thread.

Sorry, I was on vacation and started reviewing patches posted while I
was away. Should have started at the other end of the queue.

This patch partially overlaps with:
https://patchwork.sourceware.org/project/elfutils/patch/20240814085134.109500-3-kuan-ying@canonical.com/

Luckily the patches agree on the definition of the the pac_items
(modulo the name data_mask/insn_mask vs pauth_dmask/pauth_cmask).

This patch doesn't introduce a regset for ARM_PAC_ENABLED_KEYS that
the other one does. Is this not necessary?

Thanks,

Mark

> Signed-off-by: Steve Capper 
> ---
>  backends/aarch64_corenote.c | 15 ++-
>  libdwfl/linux-core-attach.c | 34 ++
>  2 files changed, 48 insertions(+), 1 deletion(-)
> 
> diff --git a/backends/aarch64_corenote.c b/backends/aarch64_corenote.c
> index 905a4b8a..f612d2ce 100644
> --- a/backends/aarch64_corenote.c
> +++ b/backends/aarch64_corenote.c
> @@ -107,6 +107,18 @@ static const Ebl_Core_Item aarch64_syscall_items [] =
>  }
>};
>  
> +static const Ebl_Core_Item aarch64_pac_items [] =
> +  {
> +{
> +  .name = "data_mask", .type = ELF_T_XWORD, .format = 'x',
> +  .offset = 0, .group = "register"
> +},
> +{
> +  .name = "insn_mask", .type = ELF_T_XWORD, .format = 'x',
> +  .offset = 8, .group = "register"
> +}
> +  };
> +
>  #define AARCH64_HWBP_REG(KIND, N)\
>  {
> \
>.name = "DBG" KIND "VR" #N "_EL1", .type = ELF_T_XWORD, .format = 'x', 
> \
> @@ -167,6 +179,7 @@ AARCH64_BP_WP_GROUP ("W", aarch64_hw_wp_items);
>EXTRA_ITEMS (NT_ARM_TLS, 8, aarch64_tls_items) \
>EXTRA_ITEMS (NT_ARM_HW_BREAK, 264, aarch64_hw_bp_items)\
>EXTRA_ITEMS (NT_ARM_HW_WATCH, 264, aarch64_hw_wp_items)\
> -  EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items)
> +  EXTRA_ITEMS (NT_ARM_SYSTEM_CALL, 4, aarch64_syscall_items) \
> +  EXTRA_ITEMS (NT_ARM_PAC_MASK, 16, aarch64_pac_items)
>  
>  #include "linux-core-note.c"
> diff --git a/libdwfl/linux-core-attach.c b/libdwfl/linux-core-attach.c
> index d6f9e971..91a5461a 100644
> --- a/libdwfl/linux-core-attach.c
> +++ b/libdwfl/linux-core-attach.c
> @@ -289,6 +289,40 @@ core_set_initial_registers (Dwfl_Thread *thread, void 
> *thread_arg_voidp)
> reg_desc += regloc->pad;
>   }
>  }
> +
> +  /* look for any Pointer Authentication code masks on AArch64 machines */
> +  GElf_Ehdr ehdr_mem;
> +  GElf_Ehdr *ehdr = gelf_getehdr(core, &ehdr_mem);
> +  if (ehdr && ehdr->e_machine == EM_AARCH64)
> +  {
> +while (offset < note_data->d_size
> +   && (offset = gelf_getnote (note_data, offset,
> + &nhdr, &name_offset, &desc_offset)) > 0)
> +{
> +  if (nhdr.n_type != NT_ARM_PAC_MASK)
> +continue;
> +
> +  name = (nhdr.n_namesz == 0 ? "" : note_data->d_buf + name_offset);
> +  desc = note_data->d_buf + desc_offset;
> +  core_note_err = ebl_core_note (core_arg->ebl, &nhdr, name, desc,
> +®s_offset, &nregloc, ®locs,
> +&nitems, &items);
> +  if (!core_note_err)
> +break;
> +
> +  for (item = items; item < items + nitems; item++)
> +if (strcmp(item->name, "insn_mask") == 0)
> +  break;
> +
> +  if (item == items + nitems)
> +continue;
> +
> +  uint64_t insn_mask = read_8ubyte_unaligned_noncvt(desc + item->offset);
> +  dwfl_thread_state_aarch64_pauth(thread, insn_mask);
> +  break;
> +}
> +  }
> +
>return true;
>  }
>  
> -- 
> 2.39.2
>