[pathname] Use physical directory when resolving symlinks

https://github.com/Homebrew/homebrew/issues/26524

Instead of dirname+readlink (or equivalent) when resolving symlinks,
use dirname.realpath+readlink. This distinction is important in the
case that the symlink is relative, and the dirname itself is a symlink.
This change only affects relative symlinks.