[PATCH] D117933: [ELF] Don't consider directories of the same name as libraries

Roland McGrath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 24 13:47:21 PST 2022


mcgrathr added a comment.

In D117933#3267443 <https://reviews.llvm.org/D117933#3267443>, @MaskRay wrote:

> Currently a deplib name (`${name}`) indicates either the literal `${name}` or the -l style `lib${name}.{a,so}`.
> We have a conflict if `${name}` is `foo` and there is a directory named `foo`.
>
> What if we do
>
>   if (name.endswith(".a") || name.endswith(".so"))
>     findFromSearchPaths
>   else
>     searchLibraryBaseName
>
> ?
>
> That should avoid the conflict, too. A directory is unlikely named `.so` or `.a`.

I don't think introducing more magical rules about naming patterns ever makes things easier.

It is surprising at first blush that deplibs searches for "foo" and not just what "-lfoo" would do, but it makes sense if you want to allow saying "libfoo.a" in deplibs to avoid matching "libfoo.so" in arcane cases.
So I think just the fix here to make all cases of not-existing-files candidates on search paths be ignored robustly is sufficient.  The extra set of candidates that deplibs cases will attempt is tolerable and IMHO it's far preferable to having any more magic in the semantics of the behavior than there already is



================
Comment at: lld/ELF/InputFiles.cpp:119
+    int val = ec.value();
+    if (!skipDirectory || (val != ENOENT && val != ENOTDIR && val != EISDIR))
+      error("cannot open " + path + ": " + ec.message());
----------------
MaskRay wrote:
> Remove `ENOTDIR`. It is for diagnostics when the file type is expected to be a directory.
> 
> We may need to check whether `category()` is https://en.cppreference.com/w/cpp/error/system_category
This is inaccurate.  ENOTDIR is also an expected error for certain cases of a nonexistent path, for example `foo/bar/baz` when `foo/bar` is an existing non-directory file is expected to be ignored and not stop continuing to search the next path candidate.  The only case when open without O_DIRECTORY returns ENOTDIR is a case that should be treated as equivalent to ENOENT for this use.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117933/new/

https://reviews.llvm.org/D117933



More information about the llvm-commits mailing list