[PATCH] D151188: [lld] Find resource and lib dir

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 24 06:53:30 PDT 2023


hans added a comment.

In D151188#4367807 <https://reviews.llvm.org/D151188#4367807>, @thieta wrote:

>> Regarding the target handling, what's your opinion on introducing a new option (for example /target:) with the default value being the host target (that is the same behavior that's used by Clang)?
>
> Not a bad idea!

But then we're back to requiring the user to pass flags to the linker (even if it's a nicer flag).

I think we should aim for this to work out of the box:

  C:\src\temp>type a.cc
  int main(int argc, char **argv) {
          __int128 a = 123;
          __int128 b = 1;
          return a / b;
  }
  
  C:\src\temp>clang-cl /c a.cc
  
  C:\src\temp>lld-link a.obj
  lld-link: error: undefined symbol: __divti3
  >>> referenced by a.obj:(main)

For the non-per-target-runtime case it seems relatively easy: if the compiler would add `clang_rt.builtins-x86_64.lib` as a dependent lib, and the linker would implicitly search the compiler's library path, it would work:

  C:\src\temp>clang-cl /c a.cc -Xclang --dependent-lib=clang_rt.builtins-x86_64.lib && lld-link a.obj "/libpath:C:\Program Files\llvm\lib\clang\16\lib\windows"
  (success)

for the per-target-runtime case, how about if the compiler included the target-dependent part of the dir in the dependent lib name, something like `--dependent-lib=x86_64-pc-win32/clang_rt.builtins.lib`? That wouldn't currently work, because lld-link expects the dependent lib to be a filename only.

But MSVC does allow relative paths in the dependent lib names, so lld-link should too:

  C:\src\temp>clang-cl /c a.cc -Xclang --dependent-lib=windows\clang_rt.builtins-x86_64.lib && link a.obj "/libpath:C:\Program Files\llvm\lib\clang\16\lib"
  Microsoft (R) Incremental Linker Version 14.29.30145.0
  Copyright (C) Microsoft Corporation.  All rights reserved.
  
  (success)

So how about we:

- Make `lld-link` implicitly add the compiler's `lib` dir to its library search path (this patch)
- Make clang pass the path to the builtins library, relative to that lib dir, as a `--dependent-lib` (and other libraries as needed)
- Make `lld-link` allow dependent libs to have relative paths

(The ideal would be to only add these dependent libraries when we actually need them, otherwise it breaks linking with link.exe. Or maybe we could do this only with `-fuse-ld=lld`?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151188



More information about the llvm-commits mailing list