[PATCH] [ELF] Fix the file look up algorithm used in the linker script GROUP command.

Shankar Kalpathi Easwaran shankarke at gmail.com
Wed Apr 30 12:48:28 PDT 2014


================
Comment at: include/lld/ReaderWriter/ELFLinkingContext.h:176-180
@@ -175,1 +175,7 @@
 
+  /// \brief Searches directories for a match on the input file.
+  /// If \p fileName is an absolute path and \p isSysRooted is true, check
+  /// the file under sysroot directory. If \p fileName is a relative path
+  /// and is not in the current directory, search the file through library
+  /// search directories.
+  ErrorOr<StringRef> searchFile(StringRef fileName, bool isSysRooted) const;
----------------
There is also a third thing, to support namespaces. You could refer to -l:mylib.a, the linker would search by not adding a prefix 'lib'.

================
Comment at: lib/Driver/GnuLdInputGraph.cpp:76-86
@@ -72,1 +75,13 @@
 
+static bool isPathUnderSysroot(StringRef sysroot, StringRef path) {
+  // TODO: Handle the case when 'sysroot' and/or 'path' are symlinks.
+  if (sysroot.empty() || sysroot.size() >= path.size())
+    return false;
+  if (llvm::sys::path::is_separator(sysroot.back()))
+    sysroot = sysroot.substr(0, sysroot.size() - 1);
+  if (!llvm::sys::path::is_separator(path[sysroot.size()]))
+    return false;
+
+  return llvm::sys::fs::equivalent(sysroot, path.substr(0, sysroot.size()));
+}
+
----------------
can we just use realpath and compare if the file is a prefix of another ?


================
Comment at: lib/Driver/GnuLdInputGraph.cpp:95
@@ +94,3 @@
+  StringRef sysRoot = _elfLinkingContext.getSysroot();
+  if (!sysRoot.empty() && isPathUnderSysroot(sysRoot, *getPath(ctx)))
+    attributes.setSysRooted(true);
----------------
we should probably reject sysroot being empty during parsing command line options, that way we can get rid of empty() comparison.

http://reviews.llvm.org/D3575






More information about the llvm-commits mailing list