diff mbox series

[3/4] Use LFS readdir in generic POSIX getcwd [BZ# 22899]

Message ID 20200826210246.2830973-3-adhemerval.zanella@linaro.org
State New
Headers show
Series [1/4] Sync getcwd with gnulib | expand

Commit Message

Adhemerval Zanella Aug. 26, 2020, 9:02 p.m. UTC
Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 sysdeps/posix/getcwd.c              | 9 +++++----
 sysdeps/unix/sysv/linux/readdir64.c | 4 ++++
 2 files changed, 9 insertions(+), 4 deletions(-)

Comments

Florian Weimer Aug. 27, 2020, 9:58 a.m. UTC | #1
* Adhemerval Zanella via Libc-alpha:

> diff --git a/sysdeps/unix/sysv/linux/readdir64.c b/sysdeps/unix/sysv/linux/readdir64.c
> index 7d4b0001b3..170a889c51 100644
> --- a/sysdeps/unix/sysv/linux/readdir64.c
> +++ b/sysdeps/unix/sysv/linux/readdir64.c
> @@ -42,7 +42,11 @@ weak_alias (__readdir64, readdir)
>  /* The compat code expects the 'struct direct' with d_ino being a __ino_t
>     instead of __ino64_t.  */
>  # include <shlib-compat.h>
> +# if IS_IN(rtld)
> +weak_alias (__readdir64, readdir64)
> +# else
>  versioned_symbol (libc, __readdir64, readdir64, GLIBC_2_2);
> +# endif

I don't think we need the full getcwd in the dynamic loader.  We only
use the fallback code if the kernel getcwd fails.  But that code does
not produce a path that is usable for the dynamic loader because it
cannot be used in open calls (it's too long for that).

I think for rtld, we should build getcwd without the fallback, and then
the change above won't be needed.

Thanks,
Florian
diff mbox series

Patch

diff --git a/sysdeps/posix/getcwd.c b/sysdeps/posix/getcwd.c
index 3876e1a641..1e6fc9b845 100644
--- a/sysdeps/posix/getcwd.c
+++ b/sysdeps/posix/getcwd.c
@@ -96,11 +96,12 @@ 
 # define __lstat64 lstat
 # define __closedir closedir
 # define __opendir opendir
-# define __readdir readdir
+# define __readdir64 readdir
 # define __fdopendir fdopendir
 # define __openat openat
 # define __rewinddir rewinddir
 # define __openat64 openat
+# define dirent64 dirent
 #else
 # include <not-cancel.h>
 #endif
@@ -259,7 +260,7 @@  __getcwd (char *buf, size_t size)
 
   while (!(thisdev == rootdev && thisino == rootino))
     {
-      struct dirent *d;
+      struct dirent64 *d;
       dev_t dotdev;
       ino_t dotino;
       bool mount_point;
@@ -312,7 +313,7 @@  __getcwd (char *buf, size_t size)
           /* Clear errno to distinguish EOF from error if readdir returns
              NULL.  */
           __set_errno (0);
-          d = __readdir (dirstream);
+          d = __readdir64 (dirstream);
 
           /* When we've iterated through all directory entries without finding
              one with a matching d_ino, rewind the stream and consider each
@@ -325,7 +326,7 @@  __getcwd (char *buf, size_t size)
             {
               use_d_ino = false;
               __rewinddir (dirstream);
-              d = __readdir (dirstream);
+              d = __readdir64 (dirstream);
             }
 
           if (d == NULL)
diff --git a/sysdeps/unix/sysv/linux/readdir64.c b/sysdeps/unix/sysv/linux/readdir64.c
index 7d4b0001b3..170a889c51 100644
--- a/sysdeps/unix/sysv/linux/readdir64.c
+++ b/sysdeps/unix/sysv/linux/readdir64.c
@@ -42,7 +42,11 @@  weak_alias (__readdir64, readdir)
 /* The compat code expects the 'struct direct' with d_ino being a __ino_t
    instead of __ino64_t.  */
 # include <shlib-compat.h>
+# if IS_IN(rtld)
+weak_alias (__readdir64, readdir64)
+# else
 versioned_symbol (libc, __readdir64, readdir64, GLIBC_2_2);
+# endif
 # if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2)
 #  include <olddirent.h>
 #  define __READDIR   attribute_compat_text_section __old_readdir64