diff mbox series

[v3,1/3] add sysdeps/{generic,mips}/elfxx-r_debug.h

Message ID 03e68d009c7a029270de44f2f2c4b7f3d787ddab.camel@mengyan1223.wang
State Superseded
Headers show
Series mips: add target-specific r_debug offset | expand

Checks

Context Check Description
dj/TryBot-apply_patch fail Patch failed to apply to master at the time it was sent

Commit Message

Xi Ruoyao Jan. 28, 2022, 10:05 p.m. UTC
Some targets (notably, MIPS) have target-specific way to get the address
of r_debug instead of the normal DT_DEBUG.  Add a header wrapping the
difference.
---
 sysdeps/generic/elfxx-r_debug.h | 26 ++++++++++++++++++
 sysdeps/mips/elfxx-r_debug.h    | 48 +++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)
 create mode 100644 sysdeps/generic/elfxx-r_debug.h
 create mode 100644 sysdeps/mips/elfxx-r_debug.h
diff mbox series

Patch

diff --git a/sysdeps/generic/elfxx-r_debug.h b/sysdeps/generic/elfxx-
r_debug.h
new file mode 100644
index 0000000000..7083c95e36
--- /dev/null
+++ b/sysdeps/generic/elfxx-r_debug.h
@@ -0,0 +1,26 @@ 
+/* Function to access r_debug structure.
+   Copyright (C) 2020-2022 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/>.  */
+
+static EW(Addr)
+E(r_debug_offset) (EW(Dyn) *d, int, EW(Addr))
+{
+  if (d->d_tag == DT_DEBUG)
+    return (EW(Addr)) d->d_un.d_ptr;
+
+  return 0;
+}
diff --git a/sysdeps/mips/elfxx-r_debug.h b/sysdeps/mips/elfxx-r_debug.h
new file mode 100644
index 0000000000..a13d069c35
--- /dev/null
+++ b/sysdeps/mips/elfxx-r_debug.h
@@ -0,0 +1,48 @@ 
+/* Function to access r_debug structure, MIPS specific version.
+   Copyright (C) 2020-2022 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/>.  */
+
+static EW(Addr)
+E(r_debug_offset) (EW(Dyn) *d, int memfd, EW(Addr) d_addr)
+{
+  EW(Addr) ptr;
+
+#ifdef R_DEBUG_IN_PROCESS
+  d_addr = (EW(Addr)) d;
+#endif
+
+  switch (d->d_tag)
+    {
+    case DT_MIPS_RLD_MAP_REL:
+      ptr = d_addr + d->d_un.d_val;
+      break;
+    case DT_MIPS_RLD_MAP:
+      ptr = d->d_un.d_ptr;
+      break;
+    default:
+      return 0;
+    }
+
+#ifdef R_DEBUG_IN_PROCESS
+  ptr = *(EW(Addr) *) ptr;
+#else
+  if (pread (memfd, &ptr, sizeof (ptr), ptr) != sizeof (ptr))
+    return 0;
+#endif
+
+  return ptr;
+}