[mach-o]: support -syslibroot and -l options
authorTim Northover <tnorthover@apple.com>
Thu, 10 Jul 2014 11:21:06 +0000 (11:21 +0000)
committerTim Northover <tnorthover@apple.com>
Thu, 10 Jul 2014 11:21:06 +0000 (11:21 +0000)
commit77d82202d156e5b6e9e6d339e222a1bb2f0e8203
tree13531de0ec012a81c21443e4672271aaaf20b817
parentdf8d0caab72214ae5619e5f6bce7a4bd8beb2dc4
[mach-o]: support -syslibroot and -l options

These behave slightly idiosyncratically in the best of cases, and have
additional hacks layered on top of that for compatibility with badly behaved
build systems (via ld64).

For -lXYZ:
  + If XYZ is actually XY.o then search all library paths for XY.o
  + Otherwise search all library paths, first for libXYZ.dylib, then libXYZ.a
  + By default the library paths are /usr/lib and /usr/local/lib in that order.

For -syslibroot:
  + -syslibroot options apply to absolute paths in the search order.
  + All -syslibroot prefixes that exist are added to the search path *instead*
    of the original.
  + If no -syslibroot prefixed path exists, the original is kept.
  + Hacks^WExceptions:
      + If only 1 -syslibroot is given and doesn't contain /usr/lib or
        /usr/local/lib, that path is dropped entirely. (rdar://problem/6438270).
      + If the last -syslibroot is "/", all of them are ignored entirely.
        (rdar://problem/5829579).

At least, that's my best interpretation of what ld64 does in buildSearchPaths.

llvm-svn: 212706
12 files changed:
lld/include/lld/ReaderWriter/MachOLinkingContext.h
lld/lib/Driver/DarwinLdDriver.cpp
lld/lib/Driver/DarwinLdOptions.td
lld/lib/ReaderWriter/MachO/MachOLinkingContext.cpp
lld/test/mach-o/Inputs/lib-search-paths/usr/lib/libmyshared.dylib [new file with mode: 0755]
lld/test/mach-o/Inputs/lib-search-paths/usr/lib/libmystatic.a [new file with mode: 0644]
lld/test/mach-o/Inputs/lib-search-paths/usr/local/lib/file.o [new file with mode: 0644]
lld/test/mach-o/lib-search-paths.yaml [new file with mode: 0644]
lld/test/mach-o/libresolve-bizarre-root-override.yaml [new file with mode: 0644]
lld/test/mach-o/libresolve-multiple-syslibroots.yaml [new file with mode: 0644]
lld/test/mach-o/libresolve-one-syslibroot.yaml [new file with mode: 0644]
lld/test/mach-o/libresolve-simple.yaml [new file with mode: 0644]