[hurd,commited 2/3] hurd: Add __readlink and readlink to dl-sysdep.c

Samuel Thibault <[email protected]> Tue, 21 Jul 2026 09:17:40 +0200
Newsgroups gmane.os.hurd.cvs,gmane.comp.lib.glibc.alpha
Message-ID <[email protected]>
Fixes fcea66cd4685f9f3719e09cac52c73b9ece4bade
("Add system-wide tunables: Filters")
which adds calling it from rtld.
---
 sysdeps/mach/hurd/Versions             |  2 ++
 sysdeps/mach/hurd/dl-sysdep.c          | 42 ++++++++++++++++++++++++++
 sysdeps/mach/hurd/i386/ld.abilist      |  1 +
 sysdeps/mach/hurd/i386/localplt.data   |  1 +
 sysdeps/mach/hurd/x86_64/ld.abilist    |  1 +
 sysdeps/mach/hurd/x86_64/localplt.data |  1 +
 6 files changed, 48 insertions(+)

diff --git a/sysdeps/mach/hurd/Versions b/sysdeps/mach/hurd/Versions
index ce8694fc88..e340ccc727 100644
--- a/sysdeps/mach/hurd/Versions
+++ b/sysdeps/mach/hurd/Versions
@@ -37,6 +37,7 @@ ld {
     __close; __getpid;
     __mmap; __open; __read; __sbrk; __strtoul_internal;
     __write; __writev;
+    readlink;
     _exit; _hurd_intr_rpc_mach_msg;
     abort;
   }
@@ -57,6 +58,7 @@ ld {
 
     # functions that must be shared with libc
     __access; __libc_read; __libc_write; __libc_lseek64;
+    __readlink;
     __close_nocancel;
     __open_nocancel;
     __read_nocancel; __pread64_nocancel;
diff --git a/sysdeps/mach/hurd/dl-sysdep.c b/sysdeps/mach/hurd/dl-sysdep.c
index 4d32c04069..29acbe1c76 100644
--- a/sysdeps/mach/hurd/dl-sysdep.c
+++ b/sysdeps/mach/hurd/dl-sysdep.c
@@ -377,6 +377,48 @@ __read (int fd, void *buf, size_t nbytes)
 libc_hidden_weak (__read)
 weak_alias (__read, __read_nocancel)
 
+check_no_hidden(__readlink);
+__ssize_t weak_function
+__readlink (const char *path, char *buf, size_t len)
+{
+  mach_port_t port;
+  error_t err;
+  struct stat64 st;
+  char *rbuf = buf;
+  mach_msg_type_number_t nread = len;
+
+  err = open_file (path, O_READ | O_NOLINK, &port, 0);
+  if (err)
+    return __hurd_fail (err);
+
+  err = __io_stat (port, &st);
+  if (err)
+    goto out;
+
+  if (!S_ISLNK (st.st_mode))
+    {
+      err = EINVAL;
+      goto out;
+    }
+
+  err = __io_read (port, &rbuf, &nread, 0, len);
+  if (err)
+    goto out;
+
+  len = nread;
+  if (rbuf != buf)
+    {
+      memcpy (buf, rbuf, len);
+      __vm_deallocate (__mach_task_self (), (vm_address_t) rbuf, nread);
+    }
+
+out:
+  __mach_port_deallocate (__mach_task_self (), port);
+  return err ? __hurd_fail (err) : len;
+}
+libc_hidden_weak (__readlink)
+weak_alias (__readlink, readlink)
+
 check_no_hidden(__write);
 check_no_hidden(__write_nocancel);
 __ssize_t weak_function
diff --git a/sysdeps/mach/hurd/i386/ld.abilist b/sysdeps/mach/hurd/i386/ld.abilist
index ebba31f770..3e25d7cfde 100644
--- a/sysdeps/mach/hurd/i386/ld.abilist
+++ b/sysdeps/mach/hurd/i386/ld.abilist
@@ -14,6 +14,7 @@ GLIBC_2.2.6 _dl_mcount F
 GLIBC_2.2.6 _hurd_intr_rpc_mach_msg F
 GLIBC_2.2.6 _r_debug D 0x14
 GLIBC_2.2.6 abort F
+GLIBC_2.2.6 readlink F
 GLIBC_2.3 ___tls_get_addr F
 GLIBC_2.3 __tls_get_addr F
 GLIBC_2.34 __rtld_version_placeholder F
diff --git a/sysdeps/mach/hurd/i386/localplt.data b/sysdeps/mach/hurd/i386/localplt.data
index f0bddf933f..2befcd3748 100644
--- a/sysdeps/mach/hurd/i386/localplt.data
+++ b/sysdeps/mach/hurd/i386/localplt.data
@@ -32,6 +32,7 @@ ld.so: __getpid
 ld.so: __getcwd
 ld.so: _exit ?
 ld.so: abort
+ld.so: readlink
 ld.so: _hurd_intr_rpc_mach_msg
 ld.so: __errno_location
 ld.so: _dl_init_first
diff --git a/sysdeps/mach/hurd/x86_64/ld.abilist b/sysdeps/mach/hurd/x86_64/ld.abilist
index 2297a5f354..df6942d69a 100644
--- a/sysdeps/mach/hurd/x86_64/ld.abilist
+++ b/sysdeps/mach/hurd/x86_64/ld.abilist
@@ -15,3 +15,4 @@ GLIBC_2.38 _dl_mcount F
 GLIBC_2.38 _hurd_intr_rpc_mach_msg F
 GLIBC_2.38 _r_debug D 0x28
 GLIBC_2.38 abort F
+GLIBC_2.38 readlink F
diff --git a/sysdeps/mach/hurd/x86_64/localplt.data b/sysdeps/mach/hurd/x86_64/localplt.data
index 710abff73e..fda28cd983 100644
--- a/sysdeps/mach/hurd/x86_64/localplt.data
+++ b/sysdeps/mach/hurd/x86_64/localplt.data
@@ -31,6 +31,7 @@ ld.so: __getpid
 ld.so: __getcwd
 ld.so: _exit ?
 ld.so: abort
+ld.so: readlink
 ld.so: _hurd_intr_rpc_mach_msg
 ld.so: __errno_location
 ld.so: _dl_init_first
-- 
2.53.0