Page MenuHomeFreeBSD

Remove unneeded calls to access(2) from rtld(1)
ClosedPublic

Authored by trasz on Oct 23 2017, 11:58 AM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 14 2024, 4:36 AM
Unknown Object (File)
Dec 20 2023, 7:44 AM
Unknown Object (File)
Oct 12 2023, 12:44 AM
Unknown Object (File)
Sep 30 2023, 1:37 PM
Unknown Object (File)
Sep 4 2023, 10:38 PM
Unknown Object (File)
Aug 30 2023, 10:44 AM
Unknown Object (File)
Aug 30 2023, 10:44 AM
Unknown Object (File)
Aug 30 2023, 10:26 AM
Subscribers

Details

Summary

Remove unneeded calls to access(2) from rtld(1); just call open(2) instead.
The result looks like this:

--- przed       2017-10-21 23:19:21.445034000 +0100
+++ po  2017-10-21 23:18:50.031865000 +0100
@@ -11,7 +11,6 @@ mmap(0x0,102,PROT_READ,MAP_PRIVATE,3,0x0)      = 343665418
 close(3)                                        = 0 (0x0)
 open("/usr/local/etc/libmap.d",O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC,0165) ERR#2 'No such file or directory'
 munmap(0x80067d000,102)                                 = 0 (0x0)
-access("/usr/local/lib/libintl.so.8",F_OK)      = 0 (0x0)
 openat(AT_FDCWD,"/usr/local/lib/libintl.so.8",O_RDONLY|O_CLOEXEC|O_VERIFY,00) = 3 (0x3)
 fstat(3,{ mode=-rw-r--r-- ,inode=642560,size=55188,blksize=32768 }) = 0 (0x0)
 mmap(0x0,4096,PROT_READ,MAP_PRIVATE|MAP_PREFAULT_READ,3,0x0) = 34366541824 (0x80067d000)
@@ -20,14 +19,13 @@ mmap(0x800877000,40960,PROT_READ|PROT_EXEC,MAP_PRIVATE
 mmap(0x800a81000,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED|MAP_PREFAULT_READ,3,0xa000) = 34370752512 (0x800a81000)
 munmap(0x80067d000,4096)                        = 0 (0x0)
 close(3)                                        = 0 (0x0)
-access("/usr/local/lib/libc.so.7",F_OK)                 ERR#2 'No such file or directory'
+openat(AT_FDCWD,"/usr/local/lib/libc.so.7",O_RDONLY|O_CLOEXEC|O_VERIFY,00) ERR#2 'No such file or directory'
 openat(AT_FDCWD,"/var/run/ld-elf.so.hints",O_RDONLY|O_CLOEXEC,00) = 3 (0x3)
 read(3,"Ehnt\^A\0\0\0\M^@\0\0\0\M-2\0\0"...,128) = 128 (0x80)
 fstat(3,{ mode=-r--r--r-- ,inode=970684,size=306,blksize=32768 }) = 0 (0x0)
 lseek(3,0x80,SEEK_SET)                          = 128 (0x80)
 read(3,"/lib:/usr/lib:/usr/lib/compat:/u"...,178) = 178 (0xb2)
 close(3)                                        = 0 (0x0)
-access("/lib/libc.so.7",F_OK)                   = 0 (0x0)
 openat(AT_FDCWD,"/lib/libc.so.7",O_RDONLY|O_CLOEXEC|O_VERIFY,00) = 3 (0x3)
 fstat(3,{ mode=-r--r--r-- ,inode=1605239,size=1910320,blksize=32768 }) = 0 (0x0)
 mmap(0x0,4096,PROT_READ,MAP_PRIVATE|MAP_PREFAULT_READ,3,0x0) = 34366541824 (0x80067d000)

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

trasz retitled this revision from Remove unneeded calls to access(2) from rtld(1). to Remove unneeded calls to access(2) from rtld(1).Oct 23 2017, 11:59 AM
trasz edited the summary of this revision. (Show Details)
trasz added a reviewer: kib.

In principle, I do not object against this.

But the thing that makes me lunge is the fact that your trace shows the load of two libc.so.7 from different paths. I do not care about your (testing) configuration, but generally, rtld should not load two libraries with the same name. Can you re-check that this is not something introduced by your patch ?

libexec/rtld-elf/rtld.c
1644 ↗(On Diff #34250)

The lines in these blocks are already too long, your patch enlarges them even more. The lines must be wrapped.

Also, since you change more than half of all function lines, use normal style(9) indents for the
find_library() function. Perhaps, do this in the preliminary commit.

Also, I suggest to extract assignments to pathname from the if () conditionals. I.e. do

pathname = search_library_path();
if (pathname != NULL)
  return (pathname);
3009 ↗(On Diff #34250)

Fix style.

3051 ↗(On Diff #34250)

Too many empty lines.

I only see one libc.so.7 - from /lib. There's an attempt to load it from /usr/local/lib, but that fails with ENOENT.

I only see one libc.so.7 - from /lib. There's an attempt to load it from /usr/local/lib, but that fails with ENOENT.

Ah, ok, it is before the system libc.so.7 is loaded. I misread the log.

I am fine with this in general, but see previous notes about style.

Rebase after commiting the style fixes.

kib added inline comments.
libexec/rtld-elf/rtld.c
3047 ↗(On Diff #34279)

I suggest to complement the dbg statement with one after open to log error code or noting success.

This revision is now accepted and ready to land.Oct 24 2017, 12:17 PM
This revision was automatically updated to reflect the committed changes.