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

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 24 13:22:32 PST 2022


MaskRay added a comment.

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`.



================
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());
----------------
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


================
Comment at: lld/ELF/ScriptParser.cpp:319
       sys::path::append(path, s);
-      if (sys::fs::exists(path)) {
-        driver->addFile(path, /*withLOption=*/false);
+      if (driver->addFile(path, /*withLOption=*/false, /*skipDirectory=*/true))
         return;
----------------
The comment says `skipDirectory` but it is actually used for `sys::fs::exists(path)`. The semantic is a bit different which may suggest `skipDirectory` is not suitable.


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