[PATCH] D109977: LLVM Driver Multicall tool

2022-07-20 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Ok, I've made D130158  as an absolutely 
minimal change that seems to fix it for me. Basically, I'm skipping all the 
driver-related logic that's not strictly necessary when 
`LLVM_TOOL_LLVM_DRIVER_BUILD` is off. The driver remains broken when dylib is 
used but at least it shouldn't affect people who don't enable it now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-19 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Unsurprisingly, it fails just the same because using an undefined variable is 
equivalent to not using it at all, so once again you're trying to link to 
static libraries that are *not there*. When dylib linking is used, you can't 
link to static libraries here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-19 Thread Alex Brachet via Phabricator via cfe-commits
abrachet added a comment.

In D109977#3662859 , @mgorny wrote:

> The actual problem is that you're passing `${USE_SHARED}` to `llvm_config()` 
> (in `add_llvm_executable`) before it's defined. Moving the definition earlier 
> fixed this error but uncovers another problem:

Thanks for looking into it more. As for what @maskray said this mode won't work 
with `LLVM_TOOL_LLVM_DRIVER_BUILD=On` and it looks like because we were using 
this variable before setting, it was always empty anyway. For the reproducer 
that you gave the following diff works. Do you want to try this diff with the 
full gentoo build that was breaking? If it works then we can commit this.

  diff --git a/llvm/cmake/modules/AddLLVM.cmake 
b/llvm/cmake/modules/AddLLVM.cmake
  index 8e1385e90b82..5563a7848ec3 100644
  --- a/llvm/cmake/modules/AddLLVM.cmake
  +++ b/llvm/cmake/modules/AddLLVM.cmake
  @@ -909,7 +909,7 @@ macro(add_llvm_executable name)
   
   set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOLS ${name})
   target_link_libraries(${obj_name} ${LLVM_PTHREAD_LIB})
  -llvm_config(${obj_name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} )
  +llvm_config(${obj_name} ${LLVM_LINK_COMPONENTS})
 endif()
   
 add_windows_version_resource_file(ALL_FILES ${ALL_FILES})




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-19 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

If you didn't apply my patch, then it works from in-tree build because it uses 
static libs instead of the dylib.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-19 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D109977#3662859 , @mgorny wrote:

> Ok, I think the key to reproducing it is `-DLLVM_LINK_LLVM_DYLIB=ON`. We pass 
> that while building LLVM, so it gets passed on to clang but I suppose passing 
> it to clang build might be sufficient to reproduce the problem.
> ...



  cmake -Sllvm -B/tmp/out/play -G Ninja -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_PROJECTS='llvm;clang' -DLLVM_BUILD_LLVM_DYLIB=ON 
-DLLVM_LINK_LLVM_DYLIB=ON
  ninja -C /tmp/out/play all

works on my Debian testing machine at main (without any patch).

---

If I enable `-DLLVM_TOOL_LLVM_DRIVER_BUILD=on`, there is an incompatibility due 
to some `cl::opt` options registered more than once.
This is a classical error. I think at this point 
`-DLLVM_TOOL_LLVM_DRIVER_BUILD=on` users are not supposed to use 
-DLLVM_BUILD_LLVM_DYLIB=ON,
but it'll be useful to fix this to get more size reduction.

  % ninja -C /tmp/out/play bin/llvm
  % /tmp/out/play/bin/llvm clang --help
  : CommandLine Error: Option 'arm-implicit-it' registered more than once!
  LLVM ERROR: inconsistency in registered CommandLine options
  [1]160970 IOT instruction  /tmp/out/play/bin/llvm clang --help


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-19 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Ok, I think the key to reproducing it is `-DLLVM_LINK_LLVM_DYLIB=ON`. We pass 
that while building LLVM, so it gets passed on to clang but I suppose passing 
it to clang build might be sufficient to reproduce the problem.

The actual problem is that you're passing `${USE_SHARED}` to `llvm_config()` 
(in `add_llvm_executable`) before it's defined. Moving the definition earlier 
fixed this error but uncovers another problem:

  CMake Error at cmake/modules/AddClang.cmake:188 (target_link_libraries):
The keyword signature for target_link_libraries has already been used with
the target "obj.clang".  All uses of target_link_libraries with a target
must be either all-keyword or all-plain.
  
The uses of the keyword signature are here:
  
 * /usr/lib/llvm/15/lib64/cmake/llvm/LLVM-Config.cmake:92 
(target_link_libraries)
  
  Call Stack (most recent call first):
tools/driver/CMakeLists.txt:37 (clang_target_link_libraries)

Now, if you move `USE_SHARED` definition using the following patch:

  diff --git a/llvm/cmake/modules/AddLLVM.cmake 
b/llvm/cmake/modules/AddLLVM.cmake
  index 8e1385e90b82..c37c1c3aa59d 100644
  --- a/llvm/cmake/modules/AddLLVM.cmake
  +++ b/llvm/cmake/modules/AddLLVM.cmake
  @@ -890,6 +890,10 @@ macro(add_llvm_executable name)
   set_target_properties(${obj_name} PROPERTIES FOLDER "Object Libraries")
 endif()
   
  +  if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
  +set(USE_SHARED USE_SHARED)
  +  endif()
  +
 if (ARG_GENERATE_DRIVER)
   string(REPLACE "-" "_" TOOL_NAME ${name})
   foreach(path ${CMAKE_MODULE_PATH})
  @@ -964,10 +968,6 @@ macro(add_llvm_executable name)
   add_llvm_symbol_exports( ${name} ${LLVM_EXPORTED_SYMBOL_FILE} )
 endif(LLVM_EXPORTED_SYMBOL_FILE)
   
  -  if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
  -set(USE_SHARED USE_SHARED)
  -  endif()
  -
 set(EXCLUDE_FROM_ALL OFF)
 set_output_directory(${name} BINARY_DIR ${LLVM_RUNTIME_OUTPUT_INTDIR} 
LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
 llvm_config( ${name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} )

you should be able to reproduce the latter error using a regular in-tree build, 
e.g.:

  cmake ../llvm -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo 
-DLLVM_ENABLE_PROJECTS='llvm;clang' -DLLVM_BUILD_LLVM_DYLIB=ON 
-DLLVM_LINK_LLVM_DYLIB=ON


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-19 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Unfortunately, that doesn't seem to be it. I think at this point it would be 
easier for both of us if I tried to figure it out myself on Gentoo rather than 
trying to make it reproducible elsewhere. If you want, you could try grabbing 
e.g. a Gentoo stage3 image (e.g. via Docker or systemd-nspawn) and trying 
`ACCEPT_KEYWORDS=** emerge -v clang:15` there but I suppose you'd have to 
figure out some Gentoo basics anyway (and then you'd realize it's the best 
distro in the world and waste years of your life developing it :-P).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-19 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

Hmm, I have another idea. Do you have individual LLVM static (or shared) 
libraries installed? On Gentoo we install only the dylib and a few unavoidable 
static libs:

  /usr/lib/llvm/15/lib64/libRemarks.so
  /usr/lib/llvm/15/lib64/libRemarks.so.15git
  /usr/lib/llvm/15/lib64/libLLVM-15git.so
  /usr/lib/llvm/15/lib64/libLLVM.so
  /usr/lib/llvm/15/lib64/libLLVM-15.0.0git.so
  /usr/lib/llvm/15/lib64/libLTO.so
  /usr/lib/llvm/15/lib64/libLTO.so.15git
  /usr/lib/llvm/15/lib64/libLLVMTableGen.a
  /usr/lib/llvm/15/lib64/libLLVMSupport.a
  /usr/lib/llvm/15/lib64/libLLVMDemangle.a

On my end, I'm going to check if installing full set of static libs changes 
anything.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-19 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

> Personally I really wish that the build system issue can be fixed in the 
> upcoming 15.0.0 release and encourage distributions to use it to decrease 
> executable sizes.

Me too, not because of multicall but because right now it's impossible to even 
build clang with multicall disabled. It's a complete 100% blocker for us.

In D109977#3661581 , @abrachet wrote:

> When running just `cmake ../clang -G Ninja` did you delete CMakeCache.txt?

I'm pretty sure I did.

> If you didn't then perhaps something from the full command you gave stayed 
> around and caused the error. I suspect then I will need the full command you 
> have supplied above including gentoo_common_config.cmake. Likely I will not 
> need gentoo_toolchain.cmake

I'm going to start by trying against with today's main, maybe (hopefully) 
something changed. I just hoped I wouldn't have to spend the time I don't 
really have on this but I guess I have no other option :-(.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-19 Thread Alex Brachet via Phabricator via cfe-commits
abrachet added a comment.

Thanks @mgorny I was able to get CMake to run. Although I didn't end up with 
the same error as you. I simply had warnings:

  CMake Warning (dev) at /usr/local/lib/cmake/llvm/TableGen.cmake:103 
(add_custom_command):
Policy CMP0116 is not set: Ninja generators transform DEPFILEs from
add_custom_command().  Run "cmake --help-policy CMP0116" for policy
details.  Use the cmake_policy command to set the policy and suppress this
warning.
  Call Stack (most recent call first):
cmake/modules/AddClang.cmake:25 (tablegen)
include/clang/AST/CMakeLists.txt:1 (clang_tablegen)
  This warning is for project developers.  Use -Wno-dev to suppress it.

When running just `cmake ../clang -G Ninja` did you delete CMakeCache.txt? If 
you didn't then perhaps something from the full command you gave stayed around 
and caused the error. I suspect then I will need the full command you have 
supplied above including gentoo_common_config.cmake. Likely I will not need 
gentoo_toolchain.cmake

In D109977#3660778 , @MaskRay wrote:

> Personally I really wish that the build system issue can be fixed in the 
> upcoming 15.0.0 release and encourage distributions to use it to decrease 
> executable sizes.

Me too. For these tools to be installable as symlinks to the llvm driver, 
D127800  will need to land, as well as a 
follow up after that patch. Maybe I could entice you to take a look :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D109977#3660734 , @mgorny wrote:

> In D109977#3660006 , @abrachet 
> wrote:
>
>> In D109977#3652467 , @mgorny wrote:
>>
>>> Though I can reproduce it with much shorter:
>>>
>>>   mkdir build
>>>   cd build
>>>   cmake ../clang -G Ninja
>>>
>>> (matching installed version of LLVM 15 must be on PATH)
>>
>> Are you sure it should be in PATH? I have added installed LLVM from ToT to a 
>> directory, put that in path yet CMake still finds 
>> /usr/lib/llvm-13/cmake/AddLLVM.cmake instead. I can't find any documentation 
>> on the standalone build, unfortunately.
>
> I'm sorry, what does "ToT" mean here? Also, what's `i`? Perhaps it's picking 
> it up from some other variable. In my case, it's finding the installed LLVM 
> 14 because that's the first PATH entry. Note that CMake looks into 
> `../lib*/cmake` and `../share/cmake` relative to PATH entries. FWICS it also 
> looks at `CMAKE_MODULE_PATH`.

"Top of Trunk" (or tree?) which indicates the latest commit of origin/main . 
"Trunk" was a term inherited from the old subversion days.

Debian installs different llvm packages to `/usr/lib/llvm-*`:

  % ls /usr/lib/llvm-* 
  /usr/lib/llvm-11:
  bin/  build/  cmake@  include/  lib/  share/
  
  /usr/lib/llvm-13:
  bin/  build/  cmake@  include/  lib/  share/
  
  /usr/lib/llvm-9:
  bin/  build/  cmake@  include/  lib/  share/

For downstream reports (e.g. Debian, Gentoo), it is worth stripping the 
distribution specific knowledge so that a patch author doesn't need to install 
a particular distribution to reproduce an issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-18 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

In D109977#3660006 , @abrachet wrote:

> In D109977#3652467 , @mgorny wrote:
>
>> Though I can reproduce it with much shorter:
>>
>>   mkdir build
>>   cd build
>>   cmake ../clang -G Ninja
>>
>> (matching installed version of LLVM 15 must be on PATH)
>
> Are you sure it should be in PATH? I have added installed LLVM from ToT to a 
> directory, put that in path yet CMake still finds 
> /usr/lib/llvm-13/cmake/AddLLVM.cmake instead. I can't find any documentation 
> on the standalone build, unfortunately.

I'm sorry, what does "ToT" mean here? Also, what's `/usr/lib/llvm-13/cmake`? 
Perhaps it's picking it up from some other variable. In my case, it's finding 
the installed LLVM 14 because that's the first PATH entry. Note that CMake 
looks into `../lib*/cmake` and `../share/cmake` relative to PATH entries. FWICS 
it also looks at `CMAKE_MODULE_PATH`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-18 Thread Alex Brachet via Phabricator via cfe-commits
abrachet added a comment.

In D109977#3652467 , @mgorny wrote:

> In D109977#3652091 , @abrachet 
> wrote:
>
>> Could I have a cmake invocation or a bot link?
>
> The exact CMake invocation for clang is:
>
>   cmake -C 
> /var/tmp/portage/sys-devel/clang-15.0.0./work/x/y/clang-abi_x86_64.amd64/gentoo_common_config.cmake
>  -G Ninja -DCMAKE_INSTALL_PREFIX=/usr 
> -DLLVM_CMAKE_PATH=/usr/lib/llvm/15/lib64/cmake/llvm 
> -DCMAKE_INSTALL_PREFIX=/usr/lib/llvm/15 
> -DCMAKE_INSTALL_MANDIR=/usr/lib/llvm/15/share/man 
> -DCLANG_RESOURCE_DIR=../../../../lib/clang/15.0.0 -DBUILD_SHARED_LIBS=OFF 
> -DCLANG_LINK_CLANG_DYLIB=ON 
> -DLLVM_DISTRIBUTION_COMPONENTS="clang-cmake-exports;clang-headers;clang-resource-headers;libclang-headers;clang-cpp;libclang;bash-autocomplete;libclang-python-bindings;c-index-test;clang;clang-format;clang-offload-bundler;clang-offload-wrapper;clang-refactor;clang-repl;clang-rename;clang-scan-deps;diagtool;hmaptool;clang-apply-replacements;clang-change-namespace;clang-doc;clang-include-fixer;clang-move;clang-query;clang-reorder-fields;clang-tidy;clang-tidy-headers;clangd;find-all-symbols;modularize;pp-trace;docs-clang-man;docs-clang-tools-man;clang-check;clang-extdef-mapping;scan-build;scan-build-py;scan-view;"
>  
> -DLLVM_TARGETS_TO_BUILD="SystemZ;WebAssembly;BPF;Hexagon;VE;XCore;X86;Sparc;NVPTX;ARM;AVR;Lanai;AMDGPU;Mips;AArch64;PowerPC;MSP430;RISCV"
>  -DLLVM_BUILD_TESTS=no -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON 
> -DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=no -DCLANG_DEFAULT_OPENMP_RUNTIME=libomp 
> -DCMAKE_DISABLE_FIND_PACKAGE_CUDA=ON -DCLANG_DEFAULT_CXX_STDLIB= 
> -DCLANG_DEFAULT_RTLIB= -DCLANG_DEFAULT_LINKER= 
> -DCLANG_DEFAULT_PIE_ON_LINUX=yes -DCLANG_DEFAULT_UNWINDLIB= 
> -DCLANG_ENABLE_ARCMT=yes -DCLANG_ENABLE_STATIC_ANALYZER=yes 
> -DPython3_EXECUTABLE=/usr/bin/python3.10 -DLLVM_BUILD_DOCS=ON 
> -DLLVM_ENABLE_SPHINX=ON 
> -DCLANG_INSTALL_SPHINX_HTML_DIR=/usr/share/doc/clang-15.0.0./html 
> -DCLANG-TOOLS_INSTALL_SPHINX_HTML_DIR=/usr/share/doc/clang-15.0.0./tools-extra
>  -DSPHINX_WARNINGS_AS_ERRORS=OFF 
> -DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=/var/tmp/portage/sys-devel/clang-15.0.0./work/clang-tools-extra
>  -DCLANG_INCLUDE_DOCS=ON -DCLANG_TOOLS_EXTRA_INCLUDE_DOCS=ON 
> -DCMAKE_BUILD_TYPE=RelWithDebInfo 
> -DCMAKE_TOOLCHAIN_FILE=/var/tmp/portage/sys-devel/clang-15.0.0./work/x/y/clang-abi_x86_64.amd64/gentoo_toolchain.cmake
>  /var/tmp/portage/sys-devel/clang-15.0.0./work/clang

This won't work for me because I will need gentoo_common_config.cmake, though I 
would rather work with the shorter reproducer you have provided.

> Though I can reproduce it with much shorter:
>
>   mkdir build
>   cd build
>   cmake ../clang -G Ninja
>
> (matching installed version of LLVM 15 must be on PATH)

Are you sure it should be in PATH? I have added installed LLVM from ToT to a 
directory, put that in path yet CMake still finds 
/usr/lib/llvm-13/cmake/AddLLVM.cmake instead. I can't find any documentation on 
the standalone build, unfortunately.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-14 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

In D109977#3652091 , @abrachet wrote:

> Could I have a cmake invocation or a bot link?

The exact CMake invocation for clang is:

  cmake -C 
/var/tmp/portage/sys-devel/clang-15.0.0./work/x/y/clang-abi_x86_64.amd64/gentoo_common_config.cmake
 -G Ninja -DCMAKE_INSTALL_PREFIX=/usr 
-DLLVM_CMAKE_PATH=/usr/lib/llvm/15/lib64/cmake/llvm 
-DCMAKE_INSTALL_PREFIX=/usr/lib/llvm/15 
-DCMAKE_INSTALL_MANDIR=/usr/lib/llvm/15/share/man 
-DCLANG_RESOURCE_DIR=../../../../lib/clang/15.0.0 -DBUILD_SHARED_LIBS=OFF 
-DCLANG_LINK_CLANG_DYLIB=ON 
-DLLVM_DISTRIBUTION_COMPONENTS="clang-cmake-exports;clang-headers;clang-resource-headers;libclang-headers;clang-cpp;libclang;bash-autocomplete;libclang-python-bindings;c-index-test;clang;clang-format;clang-offload-bundler;clang-offload-wrapper;clang-refactor;clang-repl;clang-rename;clang-scan-deps;diagtool;hmaptool;clang-apply-replacements;clang-change-namespace;clang-doc;clang-include-fixer;clang-move;clang-query;clang-reorder-fields;clang-tidy;clang-tidy-headers;clangd;find-all-symbols;modularize;pp-trace;docs-clang-man;docs-clang-tools-man;clang-check;clang-extdef-mapping;scan-build;scan-build-py;scan-view;"
 
-DLLVM_TARGETS_TO_BUILD="SystemZ;WebAssembly;BPF;Hexagon;VE;XCore;X86;Sparc;NVPTX;ARM;AVR;Lanai;AMDGPU;Mips;AArch64;PowerPC;MSP430;RISCV"
 -DLLVM_BUILD_TESTS=no -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON 
-DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=no -DCLANG_DEFAULT_OPENMP_RUNTIME=libomp 
-DCMAKE_DISABLE_FIND_PACKAGE_CUDA=ON -DCLANG_DEFAULT_CXX_STDLIB= 
-DCLANG_DEFAULT_RTLIB= -DCLANG_DEFAULT_LINKER= -DCLANG_DEFAULT_PIE_ON_LINUX=yes 
-DCLANG_DEFAULT_UNWINDLIB= -DCLANG_ENABLE_ARCMT=yes 
-DCLANG_ENABLE_STATIC_ANALYZER=yes -DPython3_EXECUTABLE=/usr/bin/python3.10 
-DLLVM_BUILD_DOCS=ON -DLLVM_ENABLE_SPHINX=ON 
-DCLANG_INSTALL_SPHINX_HTML_DIR=/usr/share/doc/clang-15.0.0./html 
-DCLANG-TOOLS_INSTALL_SPHINX_HTML_DIR=/usr/share/doc/clang-15.0.0./tools-extra
 -DSPHINX_WARNINGS_AS_ERRORS=OFF 
-DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=/var/tmp/portage/sys-devel/clang-15.0.0./work/clang-tools-extra
 -DCLANG_INCLUDE_DOCS=ON -DCLANG_TOOLS_EXTRA_INCLUDE_DOCS=ON 
-DCMAKE_BUILD_TYPE=RelWithDebInfo 
-DCMAKE_TOOLCHAIN_FILE=/var/tmp/portage/sys-devel/clang-15.0.0./work/x/y/clang-abi_x86_64.amd64/gentoo_toolchain.cmake
 /var/tmp/portage/sys-devel/clang-15.0.0./work/clang

Though I can reproduce it with much shorter:

  mkdir build
  cd build
  cmake ../clang -G Ninja

(matching installed version of LLVM 15 must be on PATH)

In D109977#3652117 , @beanz wrote:

> @mgorny Have you updated your LLVM with this change?

Obviously. I always build matching git commit of all LLVM components when 
testing the most recent state.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-14 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

In D109977#3652091 , @abrachet wrote:

> In D109977#3611683 , @mgorny wrote:
>
>> This seems to have broken standalone builds for Gentoo.
>>
>> While building Clang, I get:
>>
>>   CMake Error at /usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:138 
>> (message):
>> Target Sparc is not in the set of libraries.
>>   Call Stack (most recent call first):
>> /usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:263 
>> (llvm_expand_pseudo_components)
>> /usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:102 
>> (llvm_map_components_to_libnames)
>> /usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:95 
>> (explicit_llvm_config)
>> /usr/lib/llvm/15/lib/cmake/llvm/AddLLVM.cmake:901 (llvm_config)
>> cmake/modules/AddClang.cmake:146 (add_llvm_executable)
>> cmake/modules/AddClang.cmake:156 (add_clang_executable)
>> tools/driver/CMakeLists.txt:25 (add_clang_tool)
>>
>> (or a similar message for another target)
>
> Could I have a cmake invocation or a bot link?

@mgorny Have you updated your LLVM with this change?

If not, I suspect this breakage is expected.

@mgorny is building against an installed llvm-15 that if it doesn't have the 
changes from this patch, mixing that with a ToT clang which does will not work.

In that case the solution is that @mgorny will need to update the LLVM install 
to handle the revlock.

LLVM & Clang do rev lock from time to time during trunk development, usually 
when LLVM APIs change, but the build system can cause rev locks too since Clang 
reuses LLVM's CMake modules.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-07-14 Thread Alex Brachet via Phabricator via cfe-commits
abrachet marked an inline comment as done.
abrachet added a comment.

In D109977#3611683 , @mgorny wrote:

> This seems to have broken standalone builds for Gentoo.
>
> While building Clang, I get:
>
>   CMake Error at /usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:138 
> (message):
> Target Sparc is not in the set of libraries.
>   Call Stack (most recent call first):
> /usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:263 
> (llvm_expand_pseudo_components)
> /usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:102 
> (llvm_map_components_to_libnames)
> /usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:95 
> (explicit_llvm_config)
> /usr/lib/llvm/15/lib/cmake/llvm/AddLLVM.cmake:901 (llvm_config)
> cmake/modules/AddClang.cmake:146 (add_llvm_executable)
> cmake/modules/AddClang.cmake:156 (add_clang_executable)
> tools/driver/CMakeLists.txt:25 (add_clang_tool)
>
> (or a similar message for another target)

Could I have a cmake invocation or a bot link?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-27 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

This seems to have broken standalone builds for Gentoo.

While building Clang, I get:

  CMake Error at /usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:138 
(message):
Target Sparc is not in the set of libraries.
  Call Stack (most recent call first):
/usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:263 
(llvm_expand_pseudo_components)
/usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:102 
(llvm_map_components_to_libnames)
/usr/lib/llvm/15/lib/cmake/llvm/LLVM-Config.cmake:95 (explicit_llvm_config)
/usr/lib/llvm/15/lib/cmake/llvm/AddLLVM.cmake:901 (llvm_config)
cmake/modules/AddClang.cmake:146 (add_llvm_executable)
cmake/modules/AddClang.cmake:156 (add_clang_executable)
tools/driver/CMakeLists.txt:25 (add_clang_tool)

(or a similar message for another target)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-09 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: llvm/cmake/modules/AddLLVM.cmake:890
+configure_file(
+  ${LLVM_MAIN_SRC_DIR}/cmake/driver-template.cpp.in
+  ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp)

nikic wrote:
> nikic wrote:
> > chapuni wrote:
> > > Do you have a plan to export the template?
> > Unsurprisingly, this breaks standalone builds. However, I think that the 
> > multicall tool is fundamentally incompatible with standalone builds, in the 
> > sense that all tools included in it must be part of the initial build 
> > configuration -- you can't first build the LLVM multicall tool and then add 
> > clang to it afterwards.
> > 
> > So I think we just need to guard this code by LLVM_TOOL_LLVM_DRIVER_BUILD, 
> > so we don't try to read a non-exported driver-template.cpp.in file even if 
> > we're not actually building the multicall tool.
> Ah, I misunderstood how this works. Generating the driver file is necessary 
> for //normal// usage, not for the mutlicall tool, so it's not possible to 
> just guard this code. We do need to export driver-template.cpp.in as part of 
> the LLVM cmake installation.
I've put up https://reviews.llvm.org/D127384 to fix this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-09 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: llvm/cmake/modules/AddLLVM.cmake:890
+configure_file(
+  ${LLVM_MAIN_SRC_DIR}/cmake/driver-template.cpp.in
+  ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp)

nikic wrote:
> chapuni wrote:
> > Do you have a plan to export the template?
> Unsurprisingly, this breaks standalone builds. However, I think that the 
> multicall tool is fundamentally incompatible with standalone builds, in the 
> sense that all tools included in it must be part of the initial build 
> configuration -- you can't first build the LLVM multicall tool and then add 
> clang to it afterwards.
> 
> So I think we just need to guard this code by LLVM_TOOL_LLVM_DRIVER_BUILD, so 
> we don't try to read a non-exported driver-template.cpp.in file even if we're 
> not actually building the multicall tool.
Ah, I misunderstood how this works. Generating the driver file is necessary for 
//normal// usage, not for the mutlicall tool, so it's not possible to just 
guard this code. We do need to export driver-template.cpp.in as part of the 
LLVM cmake installation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-09 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: llvm/cmake/modules/AddLLVM.cmake:890
+configure_file(
+  ${LLVM_MAIN_SRC_DIR}/cmake/driver-template.cpp.in
+  ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp)

chapuni wrote:
> Do you have a plan to export the template?
Unsurprisingly, this breaks standalone builds. However, I think that the 
multicall tool is fundamentally incompatible with standalone builds, in the 
sense that all tools included in it must be part of the initial build 
configuration -- you can't first build the LLVM multicall tool and then add 
clang to it afterwards.

So I think we just need to guard this code by LLVM_TOOL_LLVM_DRIVER_BUILD, so 
we don't try to read a non-exported driver-template.cpp.in file even if we're 
not actually building the multicall tool.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: llvm/test/lit.cfg.py:142
 tools = [
+ToolSubst('%llvm', FindTool('llvm')),
 ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),

abrachet wrote:
> thakis wrote:
> > This causes `llvm-lit: 
> > /Users/thakis/src/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126: note: 
> > Did not find llvm in /Users/thakis/src/llvm-build-2/bin` if llvm-driver 
> > isn't enabled (which it isn't by default). Any reason not to add this one 
> > only `if config.have_llvm_driver`?
> Fixed in rG553c2af5360b993376d3c000cf53850605940307
Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-06 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added a comment.

An interesting improvement. Thanks.




Comment at: llvm/cmake/modules/AddLLVM.cmake:890
+configure_file(
+  ${LLVM_MAIN_SRC_DIR}/cmake/driver-template.cpp.in
+  ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp)

Do you have a plan to export the template?



Comment at: utils/bazel/llvm-project-overlay/clang/BUILD.bazel:1932
+src = "//llvm:cmake/driver-template.cpp.in",
+out = "clang_main.cpp",
+substitutions = {

Could we unify generated names.cpp between cmake and bazel?

I am running a builder to compare each object file between  cmake and bazel. 
Such a difference appears in a few sections, at least in elf.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-06 Thread Alex Brachet via Phabricator via cfe-commits
abrachet marked an inline comment as done.
abrachet added inline comments.



Comment at: llvm/test/lit.cfg.py:142
 tools = [
+ToolSubst('%llvm', FindTool('llvm')),
 ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),

thakis wrote:
> This causes `llvm-lit: 
> /Users/thakis/src/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126: note: 
> Did not find llvm in /Users/thakis/src/llvm-build-2/bin` if llvm-driver isn't 
> enabled (which it isn't by default). Any reason not to add this one only `if 
> config.have_llvm_driver`?
Fixed in rG553c2af5360b993376d3c000cf53850605940307


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-06 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: llvm/test/lit.cfg.py:142
 tools = [
+ToolSubst('%llvm', FindTool('llvm')),
 ToolSubst('%lli', FindTool('lli'), post='.', extra_args=lli_args),

This causes `llvm-lit: 
/Users/thakis/src/llvm-project/llvm/utils/lit/lit/llvm/subst.py:126: note: Did 
not find llvm in /Users/thakis/src/llvm-build-2/bin` if llvm-driver isn't 
enabled (which it isn't by default). Any reason not to add this one only `if 
config.have_llvm_driver`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-05 Thread Alex Brachet via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
abrachet marked 2 inline comments as done.
Closed by commit rGf06abbb39380: LLVM Driver Multicall tool (authored by beanz, 
committed by abrachet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

Files:
  clang/cmake/modules/AddClang.cmake
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/driver.cpp
  llvm/CMakeLists.txt
  llvm/cmake/driver-template.cpp.in
  llvm/cmake/modules/AddLLVM.cmake
  llvm/lib/Support/Path.cpp
  llvm/lib/Support/Unix/Path.inc
  llvm/lib/Support/Windows/Path.inc
  llvm/test/CMakeLists.txt
  llvm/test/lit.cfg.py
  llvm/test/lit.site.cfg.py.in
  llvm/test/tools/llvm-driver/help-passthrough.test
  llvm/test/tools/llvm-driver/help.test
  llvm/test/tools/llvm-driver/symlink-call.test
  llvm/tools/CMakeLists.txt
  llvm/tools/dsymutil/CMakeLists.txt
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-ar/CMakeLists.txt
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-cxxfilt/CMakeLists.txt
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-driver/CMakeLists.txt
  llvm/tools/llvm-driver/llvm-driver.cpp
  llvm/tools/llvm-objcopy/CMakeLists.txt
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp
  utils/bazel/llvm-project-overlay/clang/BUILD.bazel
  utils/bazel/llvm-project-overlay/llvm/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -2594,12 +2594,21 @@
 td_srcs = ["include/llvm/Option/OptParser.td"],
 )
 
+template_rule(
+name = "dsymutil_main",
+src = "cmake/driver-template.cpp.in",
+out = "dsymutil_main.cpp",
+substitutions = {
+"@TOOL_NAME@": "dsymutil"
+},
+)
+
 cc_binary(
 name = "dsymutil",
 srcs = glob([
 "tools/dsymutil/*.cpp",
 "tools/dsymutil/*.h",
-]),
+]) + ["dsymutil_main.cpp"],
 copts = llvm_copts,
 stamp = 0,
 deps = [
@@ -2689,12 +2698,21 @@
 ],
 )
 
+template_rule(
+name = "ar_main",
+src = "cmake/driver-template.cpp.in",
+out = "ar_main.cpp",
+substitutions = {
+"@TOOL_NAME@": "llvm_ar"
+},
+)
+
 cc_binary(
 name = "llvm-ar",
 srcs = glob([
 "tools/llvm-ar/*.cpp",
 "tools/llvm-ar/*.h",
-]),
+]) + ["ar_main.cpp"],
 copts = llvm_copts,
 stamp = 0,
 deps = [
@@ -2882,12 +2900,21 @@
 td_srcs = ["include/llvm/Option/OptParser.td"],
 )
 
+template_rule(
+name = "cxxfilt_main",
+src = "cmake/driver-template.cpp.in",
+out = "cxxfilt_main.cpp",
+substitutions = {
+"@TOOL_NAME@": "llvm_cxxfilt"
+},
+)
+
 cc_binary(
 name = "llvm-cxxfilt",
 srcs = glob([
 "tools/llvm-cxxfilt/*.cpp",
 "tools/llvm-cxxfilt/*.h",
-]),
+]) + ["cxxfilt_main.cpp"],
 copts = llvm_copts,
 stamp = 0,
 deps = [
@@ -3416,12 +3443,22 @@
 ],
 )
 
+template_rule(
+name = "objcopy_main",
+src = "cmake/driver-template.cpp.in",
+out = "objcopy_main.cpp",
+substitutions = {
+"@TOOL_NAME@": "llvm_objcopy"
+},
+)
+
+
 cc_binary(
 name = "llvm-objcopy",
 srcs = glob([
 "tools/llvm-objcopy/*.cpp",
 "tools/llvm-objcopy/*.h",
-]),
+]) + ["objcopy_main.cpp"],
 copts = llvm_copts,
 stamp = 0,
 deps = [
Index: utils/bazel/llvm-project-overlay/clang/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -5,6 +5,7 @@
 load("//llvm:tblgen.bzl", "gentbl")
 load("//llvm:binary_alias.bzl", "binary_alias")
 load("//llvm:cc_plugin_library.bzl", "cc_plugin_library")
+load("//llvm:template_rule.bzl", "template_rule")
 
 package(
 default_visibility = ["//visibility:public"],
@@ -1925,12 +1926,21 @@
 ],
 )
 
+template_rule(
+name = "clang_main",
+src = "//llvm:cmake/driver-template.cpp.in",
+out = "clang_main.cpp",
+substitutions = {
+"@TOOL_NAME@": "clang"
+},
+)
+
 cc_library(
 name = "clang-driver",
 srcs = glob([
 "tools/driver/*.cpp",
 "tools/driver/*.h",
-]),
+]) + ["clang_main.cpp"],
 copts = [
 # Disable stack frame size checks in the driver because
 # clang::ensureStackAddressSpace allocates a large array on the stack.
Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -223,7 +223,7 @@
   return Error::success();
 }
 
-int main(int argc, char **argv) {
+int llvm_objcopy_main(int argc, char **argv) {
   InitLLVM X(argc, argv);
   

[PATCH] D109977: LLVM Driver Multicall tool

2022-06-05 Thread Alex Brachet via Phabricator via cfe-commits
abrachet marked 2 inline comments as done.
abrachet added inline comments.



Comment at: llvm/cmake/modules/AddLLVM.cmake:2030
+string(REPLACE "-" "_" key ${link_name})
+string(REPLACE "+" "p" key ${key})
+string(REPLACE "llvm-" "" tool_name ${link_name})

phosek wrote:
> Alternative substitution for `+` would be `x` which is used elsewhere in 
> LLVM, for example `libcxx`, `libcxxabi` or `cxxfilt`.
Upon closer inspection we are no longer using that parameter of the macro, so I 
have removed it.



Comment at: llvm/tools/llvm-driver/llvm-driver.cpp:50
+  bool ConsumeFirstArg = false;
+  if (LaunchedTool == "llvm") {
+if (Argc < 2)

MaskRay wrote:
> abrachet wrote:
> > MaskRay wrote:
> > > Some distributions may want to use something like llvm-15. See some 
> > > binary utilities how the version is handled.
> > Thank's I've taken this from objcopy's code
> The format of `cl::PrintVersionMessage();` is not so good for user-facing 
> tools. Consider omitting it.
> 
> `llvm-objcopy --version` should probably use a style similar to `clang 
> --version` but the priority isn't high.
I've just removed `--version` completely for now. I don't think it is that 
pressing. 


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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-05 Thread Alex Brachet via Phabricator via cfe-commits
abrachet updated this revision to Diff 434370.
abrachet marked an inline comment as done.
abrachet added a comment.

- Fix bazel build, `llvm-driver` can't be built by bazel, but the existing 
tools which lost their `main` will still work.
- Remove `--version`
- Fix `dsymutil` not depending on `DsymutilTableGen` which caused a dependency 
ordering problem on the bots


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

https://reviews.llvm.org/D109977

Files:
  clang/cmake/modules/AddClang.cmake
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/driver.cpp
  llvm/CMakeLists.txt
  llvm/cmake/driver-template.cpp.in
  llvm/cmake/modules/AddLLVM.cmake
  llvm/lib/Support/Path.cpp
  llvm/lib/Support/Unix/Path.inc
  llvm/lib/Support/Windows/Path.inc
  llvm/test/CMakeLists.txt
  llvm/test/lit.cfg.py
  llvm/test/lit.site.cfg.py.in
  llvm/test/tools/llvm-driver/help-passthrough.test
  llvm/test/tools/llvm-driver/help.test
  llvm/test/tools/llvm-driver/symlink-call.test
  llvm/tools/CMakeLists.txt
  llvm/tools/dsymutil/CMakeLists.txt
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-ar/CMakeLists.txt
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-cxxfilt/CMakeLists.txt
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-driver/CMakeLists.txt
  llvm/tools/llvm-driver/llvm-driver.cpp
  llvm/tools/llvm-objcopy/CMakeLists.txt
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp
  utils/bazel/llvm-project-overlay/clang/BUILD.bazel
  utils/bazel/llvm-project-overlay/llvm/BUILD.bazel

Index: utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -2594,12 +2594,21 @@
 td_srcs = ["include/llvm/Option/OptParser.td"],
 )
 
+template_rule(
+name = "dsymutil_main",
+src = "cmake/driver-template.cpp.in",
+out = "dsymutil_main.cpp",
+substitutions = {
+"@TOOL_NAME@": "dsymutil"
+},
+)
+
 cc_binary(
 name = "dsymutil",
 srcs = glob([
 "tools/dsymutil/*.cpp",
 "tools/dsymutil/*.h",
-]),
+]) + ["dsymutil_main.cpp"],
 copts = llvm_copts,
 stamp = 0,
 deps = [
@@ -2689,12 +2698,21 @@
 ],
 )
 
+template_rule(
+name = "ar_main",
+src = "cmake/driver-template.cpp.in",
+out = "ar_main.cpp",
+substitutions = {
+"@TOOL_NAME@": "llvm_ar"
+},
+)
+
 cc_binary(
 name = "llvm-ar",
 srcs = glob([
 "tools/llvm-ar/*.cpp",
 "tools/llvm-ar/*.h",
-]),
+]) + ["ar_main.cpp"],
 copts = llvm_copts,
 stamp = 0,
 deps = [
@@ -2882,12 +2900,21 @@
 td_srcs = ["include/llvm/Option/OptParser.td"],
 )
 
+template_rule(
+name = "cxxfilt_main",
+src = "cmake/driver-template.cpp.in",
+out = "cxxfilt_main.cpp",
+substitutions = {
+"@TOOL_NAME@": "llvm_cxxfilt"
+},
+)
+
 cc_binary(
 name = "llvm-cxxfilt",
 srcs = glob([
 "tools/llvm-cxxfilt/*.cpp",
 "tools/llvm-cxxfilt/*.h",
-]),
+]) + ["cxxfilt_main.cpp"],
 copts = llvm_copts,
 stamp = 0,
 deps = [
@@ -3416,12 +3443,22 @@
 ],
 )
 
+template_rule(
+name = "objcopy_main",
+src = "cmake/driver-template.cpp.in",
+out = "objcopy_main.cpp",
+substitutions = {
+"@TOOL_NAME@": "llvm_objcopy"
+},
+)
+
+
 cc_binary(
 name = "llvm-objcopy",
 srcs = glob([
 "tools/llvm-objcopy/*.cpp",
 "tools/llvm-objcopy/*.h",
-]),
+]) + ["objcopy_main.cpp"],
 copts = llvm_copts,
 stamp = 0,
 deps = [
Index: utils/bazel/llvm-project-overlay/clang/BUILD.bazel
===
--- utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -5,6 +5,7 @@
 load("//llvm:tblgen.bzl", "gentbl")
 load("//llvm:binary_alias.bzl", "binary_alias")
 load("//llvm:cc_plugin_library.bzl", "cc_plugin_library")
+load("//llvm:template_rule.bzl", "template_rule")
 
 package(
 default_visibility = ["//visibility:public"],
@@ -1925,12 +1926,21 @@
 ],
 )
 
+template_rule(
+name = "clang_main",
+src = "//llvm:cmake/driver-template.cpp.in",
+out = "clang_main.cpp",
+substitutions = {
+"@TOOL_NAME@": "clang"
+},
+)
+
 cc_library(
 name = "clang-driver",
 srcs = glob([
 "tools/driver/*.cpp",
 "tools/driver/*.h",
-]),
+]) + ["clang_main.cpp"],
 copts = [
 # Disable stack frame size checks in the driver because
 # clang::ensureStackAddressSpace allocates a large array on the stack.
Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -223,7 +223,7 @@
   return Error::success();
 }
 
-int main(int argc, char **argv) {
+int 

[PATCH] D109977: LLVM Driver Multicall tool

2022-06-05 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.

LGTM




Comment at: llvm/cmake/modules/AddLLVM.cmake:2030
+string(REPLACE "-" "_" key ${link_name})
+string(REPLACE "+" "p" key ${key})
+string(REPLACE "llvm-" "" tool_name ${link_name})

Alternative substitution for `+` would be `x` which is used elsewhere in LLVM, 
for example `libcxx`, `libcxxabi` or `cxxfilt`.


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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

LGTM from my perspective, but this needs someone else's review.




Comment at: llvm/tools/llvm-driver/llvm-driver.cpp:50
+  bool ConsumeFirstArg = false;
+  if (LaunchedTool == "llvm") {
+if (Argc < 2)

abrachet wrote:
> MaskRay wrote:
> > Some distributions may want to use something like llvm-15. See some binary 
> > utilities how the version is handled.
> Thank's I've taken this from objcopy's code
The format of `cl::PrintVersionMessage();` is not so good for user-facing 
tools. Consider omitting it.

`llvm-objcopy --version` should probably use a style similar to `clang 
--version` but the priority isn't high.


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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-05 Thread Alex Brachet via Phabricator via cfe-commits
abrachet marked 5 inline comments as done.
abrachet added a comment.

In D109977#3558762 , @MaskRay wrote:

> Thanks for picking up the change. I confirm that I can build `llvm` without 
> an error and it appears to work fine.
>
>> llvm-driver can be disabled from builds by setting 
>> LLVM_TOOL_LLVM_DRIVER_BUILD=Off.
>
> I think this should be opt-in. The new `llvm` executable takes a lot of space 
> and not needed by many developers/build bots.
> It's useful to some groups (distributions) but they can specify the option 
> themselves.
> I think the modified code is quite stable, so don't worry about regressions 
> just because this is not opt-in.

I didn't update the commits message, now it properly says that it can be opted 
in by setting `LLVM_TOOL_LLVM_DRIVER_BUILD` to `On`

In D109977#3558768 , @MaskRay wrote:

>   % /tmp/out/custom1/bin/llvm --help
>   ...

The output now looks like:

  OVERVIEW: llvm toolchain driver
  
  USAGE: llvm [subcommand] [options]
  
  SUBCOMMANDS:
  
ar
clang
dsymutil
cxxfilt
objcopy
ranlib
lib
dlltool
clang++
clang-cl
clang-cpp
install-name-tool
bitcode-strip
strip
  
Type "llvm  --help" to get more help on a specific subcommand
  
  OPTIONS:
  
--help - Display this message

What do you think?




Comment at: llvm/tools/llvm-driver/llvm-driver.cpp:50
+  bool ConsumeFirstArg = false;
+  if (LaunchedTool == "llvm") {
+if (Argc < 2)

MaskRay wrote:
> Some distributions may want to use something like llvm-15. See some binary 
> utilities how the version is handled.
Thank's I've taken this from objcopy's code


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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-05 Thread Alex Brachet via Phabricator via cfe-commits
abrachet updated this revision to Diff 434352.
abrachet marked an inline comment as done.
abrachet edited the summary of this revision.
abrachet added a comment.

Better handling of names with version, ie `llvm-cxxfilt-15` -> `cxxfilt`


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

https://reviews.llvm.org/D109977

Files:
  clang/cmake/modules/AddClang.cmake
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/driver.cpp
  llvm/CMakeLists.txt
  llvm/cmake/driver-template.cpp.in
  llvm/cmake/modules/AddLLVM.cmake
  llvm/lib/Support/Path.cpp
  llvm/lib/Support/Unix/Path.inc
  llvm/lib/Support/Windows/Path.inc
  llvm/test/CMakeLists.txt
  llvm/test/lit.cfg.py
  llvm/test/lit.site.cfg.py.in
  llvm/test/tools/llvm-driver/help-passthrough.test
  llvm/test/tools/llvm-driver/help.test
  llvm/test/tools/llvm-driver/symlink-call.test
  llvm/tools/CMakeLists.txt
  llvm/tools/dsymutil/CMakeLists.txt
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-ar/CMakeLists.txt
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-cxxfilt/CMakeLists.txt
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-driver/CMakeLists.txt
  llvm/tools/llvm-driver/llvm-driver.cpp
  llvm/tools/llvm-objcopy/CMakeLists.txt
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp

Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -223,7 +223,7 @@
   return Error::success();
 }
 
-int main(int argc, char **argv) {
+int llvm_objcopy_main(int argc, char **argv) {
   InitLLVM X(argc, argv);
   ToolName = argv[0];
 
Index: llvm/tools/llvm-objcopy/CMakeLists.txt
===
--- llvm/tools/llvm-objcopy/CMakeLists.txt
+++ llvm/tools/llvm-objcopy/CMakeLists.txt
@@ -30,6 +30,7 @@
   ObjcopyOptsTableGen
   InstallNameToolOptsTableGen
   StripOptsTableGen
+  GENERATE_DRIVER
   )
 
 add_llvm_tool_symlink(llvm-install-name-tool llvm-objcopy)
Index: llvm/tools/llvm-driver/llvm-driver.cpp
===
--- /dev/null
+++ llvm/tools/llvm-driver/llvm-driver.cpp
@@ -0,0 +1,79 @@
+//===-- llvm-driver.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
+
+using namespace llvm;
+
+#define LLVM_DRIVER_TOOL(tool, entry, key) \
+  int entry##_main(int argc, char **argv);
+#include "LLVMDriverTools.def"
+
+constexpr char subcommands[] =
+#define LLVM_DRIVER_TOOL(tool, entry, key) "  " tool "\n"
+#include "LLVMDriverTools.def"
+;
+
+static void printHelpMessage() {
+  llvm::outs() << "OVERVIEW: llvm toolchain driver\n\n"
+   << "USAGE: llvm [subcommand] [options]\n\n"
+   << "SUBCOMMANDS:\n\n"
+   << subcommands
+   << "\n  Type \"llvm  --help\" to get more help on a "
+  "specific subcommand\n\n"
+   << "OPTIONS:\n\n  --help - Display this message";
+}
+
+static int findTool(int Argc, char **Argv) {
+  if (!Argc) {
+printHelpMessage();
+return 1;
+  }
+
+  StringRef ToolName = Argv[0];
+
+  if (ToolName == "--help") {
+printHelpMessage();
+return 0;
+  }
+  if (ToolName == "--version") {
+cl::PrintVersionMessage();
+return 0;
+  }
+
+  StringRef Stem = sys::path::stem(ToolName);
+  auto Is = [=](StringRef Tool) {
+auto I = Stem.rfind_insensitive(Tool);
+return I != StringRef::npos && (I + Tool.size() == Stem.size() ||
+!llvm::isAlnum(Stem[I + Tool.size()]));
+  };
+
+#define LLVM_DRIVER_TOOL(tool, entry, key) \
+  if (Is(tool))\
+return entry##_main(Argc, Argv);
+#include "LLVMDriverTools.def"
+
+  if (Is("llvm"))
+return findTool(Argc - 1, Argv + 1);
+
+  printHelpMessage();
+  return 1;
+}
+
+extern bool IsLLVMDriver;
+
+int main(int Argc, char **Argv) {
+  IsLLVMDriver = true;
+  return findTool(Argc, Argv);
+}
Index: llvm/tools/llvm-driver/CMakeLists.txt
===
--- /dev/null
+++ llvm/tools/llvm-driver/CMakeLists.txt
@@ -0,0 +1,31 @@
+get_property(LLVM_COMMON_DEPENDS GLOBAL PROPERTY LLVM_DRIVER_DEPS)
+get_property(LLVM_DRIVER_OBJLIBS GLOBAL PROPERTY LLVM_DRIVER_OBJLIBS)
+

[PATCH] D109977: LLVM Driver Multicall tool

2022-06-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

  % /tmp/out/custom1/bin/llvm --help
  OVERVIEW: llvm compiler driver
  
  USAGE: llvm [subcommand] [options]
  
  SUBCOMMANDS:
  
ar- ar  ## should be llvm-ar
bitcode-strip - bitcode-strip   ### should be llvm-bitcode-strip
clang - clang
clang++   - clang++
clang-cl  - clang-cl
clang-cpp - clang-cpp
cxxfilt   - cxxfilt   ### ditto
dlltool   - dlltool
dsymutil  - dsymutil
install-name-tool - install-name-tool
lib   - lib  # this is confusing. llvm-lib
objcopy   - objcopy
ranlib- ranlib
strip - strip
  
Type "llvm  --help" to get more help on a specific subcommand
  
  OPTIONS:
  
  Generic Options:
  
--help  - Display available options (--help-hidden for more)
--help-list - Display list of available options (--help-list-hidden for 
more)
--version   - Display the version of this program


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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> llvm-driver can be disabled from builds by setting 
> LLVM_TOOL_LLVM_DRIVER_BUILD=Off.

I think this should be opt-in. The new `llvm` executable takes a lot of space 
and not needed by many developers/build bots.
It's useful to some groups (distributions) but they can specify the option 
themselves.
I think the modified code is quite stable, so don't worry about regressions 
just because this is not opt-in.




Comment at: llvm/tools/llvm-driver/llvm-driver.cpp:24
+// --help or --version are passed directly to the llvm driver.
+int UnknownMain(int Argc, char **Argv) {
+  cl::OptionCategory LLVMDriverCategory("llvm options");

`static int unknownMain`




Comment at: llvm/tools/llvm-driver/llvm-driver.cpp:25
+int UnknownMain(int Argc, char **Argv) {
+  cl::OptionCategory LLVMDriverCategory("llvm options");
+#define LLVM_DRIVER_TOOL(tool, entry, key) 
\

Prefer OptTable to cl:: for user-facing utilities. If simple, just open coding 
the help message.



Comment at: llvm/tools/llvm-driver/llvm-driver.cpp:37
+
+  llvm_unreachable("We should never get here, parsing should always exit.");
+  return 1;

https://llvm.org/docs/CodingStandards.html#error-and-warning-messages



Comment at: llvm/tools/llvm-driver/llvm-driver.cpp:50
+  bool ConsumeFirstArg = false;
+  if (LaunchedTool == "llvm") {
+if (Argc < 2)

Some distributions may want to use something like llvm-15. See some binary 
utilities how the version is handled.



Comment at: llvm/tools/llvm-driver/llvm-driver.cpp:58
+  // if it is launched through a symlink that is the tool name.
+  typedef int (*MainFunction)(int, char **);
+  MainFunction Func = StringSwitch(LaunchedTool)

If only used once, don't add a typedef (using is preferred)


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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-04 Thread Alex Brachet via Phabricator via cfe-commits
abrachet marked 5 inline comments as done.
abrachet added a comment.

In D109977#3378312 , @phosek wrote:

> Another potential future improvement is error reporting for subcommands:
>
>   $ ./bin/llvm clang   
>   llvm: error: no input files
>   $ ./bin/clang
>   clang-15: error: no input files
>
> Ideally, the multicall tool would produce the same error message.

It's difficult to make the error message the same, ie `clang-15`, but hopefully 
the name the tool was invoked with is enough.




Comment at: llvm/tools/llvm-driver/llvm-driver.cpp:43
+  if (LaunchedTool == "llvm") {
+LaunchedTool = Argv[1];
+ConsumeFirstArg = true;

phosek wrote:
> When the tool is invoked without any arguments (that is, simply as 
> `./bin/llvm`) this will lead to out-of-bounds array access. We should handle 
> this case explicitly.
This will now print the help message



Comment at: llvm/tools/llvm-objcopy/llvm-objcopy.cpp:404
 
-int main(int argc, char **argv) {
+int llvm_objcopy_main(int argc, char **argv) {
   InitLLVM X(argc, argv);

beanz wrote:
> aganea wrote:
> > Shouldn't we say:
> > ```
> > int objcopy_main(int argc, char **argv) {
> > ```
> > here and the other places + all supporting code, if we want `llvm objcopy` 
> > (without the dash) like @phosek suggests?
> I had a different thought for that. I think we want the tools to respond to 
> llvm-objcopy since we will want them to exist in parallel to binutils tools 
> just like the current tools do today.
> 
> Many of the current tools also support symlink-redirection, to support that 
> we'll need to have a multiplex where multiple tool names point to the same 
> `main` function.
> 
> Handling that was my point (1) in the `main` commit message, and I intended 
> to work on it in a follow-on commit.
> Shouldn't we say:
> ```
> int objcopy_main(int argc, char **argv) {
> ```
> here and the other places + all supporting code, if we want `llvm objcopy` 
> (without the dash) like @phosek suggests?

I've kept name of the function as is, but `llvm objcopy` is now supported, and 
`llvm llvm-objcopy` is not


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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-04 Thread Alex Brachet via Phabricator via cfe-commits
abrachet updated this revision to Diff 434277.
abrachet added a comment.
Herald added a subscriber: hiraditya.

- `llvm llvm-$tool` -> `llvm $tool`
- Error messages will now show `$tool: error: ...` instead of `error: ...`


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

https://reviews.llvm.org/D109977

Files:
  clang/cmake/modules/AddClang.cmake
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/driver.cpp
  llvm/CMakeLists.txt
  llvm/cmake/driver-template.cpp.in
  llvm/cmake/modules/AddLLVM.cmake
  llvm/lib/Support/Path.cpp
  llvm/lib/Support/Unix/Path.inc
  llvm/lib/Support/Windows/Path.inc
  llvm/test/CMakeLists.txt
  llvm/test/lit.cfg.py
  llvm/test/lit.site.cfg.py.in
  llvm/test/tools/llvm-driver/help-passthrough.test
  llvm/test/tools/llvm-driver/help.test
  llvm/test/tools/llvm-driver/symlink-call.test
  llvm/tools/CMakeLists.txt
  llvm/tools/dsymutil/CMakeLists.txt
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-ar/CMakeLists.txt
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-cxxfilt/CMakeLists.txt
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-driver/CMakeLists.txt
  llvm/tools/llvm-driver/llvm-driver.cpp
  llvm/tools/llvm-objcopy/CMakeLists.txt
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp

Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -223,7 +223,7 @@
   return Error::success();
 }
 
-int main(int argc, char **argv) {
+int llvm_objcopy_main(int argc, char **argv) {
   InitLLVM X(argc, argv);
   ToolName = argv[0];
 
Index: llvm/tools/llvm-objcopy/CMakeLists.txt
===
--- llvm/tools/llvm-objcopy/CMakeLists.txt
+++ llvm/tools/llvm-objcopy/CMakeLists.txt
@@ -30,6 +30,7 @@
   ObjcopyOptsTableGen
   InstallNameToolOptsTableGen
   StripOptsTableGen
+  GENERATE_DRIVER
   )
 
 add_llvm_tool_symlink(llvm-install-name-tool llvm-objcopy)
Index: llvm/tools/llvm-driver/llvm-driver.cpp
===
--- /dev/null
+++ llvm/tools/llvm-driver/llvm-driver.cpp
@@ -0,0 +1,72 @@
+//===-- llvm-driver.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
+
+using namespace llvm;
+
+#define LLVM_DRIVER_TOOL(tool, entry, key) \
+  int entry##_main(int argc, char **argv);
+#include "LLVMDriverTools.def"
+
+// This function handles the case of not recognizing the tool requested, or if
+// --help or --version are passed directly to the llvm driver.
+int UnknownMain(int Argc, char **Argv) {
+  cl::OptionCategory LLVMDriverCategory("llvm options");
+#define LLVM_DRIVER_TOOL(tool, entry, key) \
+  cl::SubCommand key##Subcommand(tool, tool);
+#include "LLVMDriverTools.def"
+
+  cl::HideUnrelatedOptions(LLVMDriverCategory);
+  cl::ParseCommandLineOptions(Argc, Argv, "llvm compiler driver\n");
+  if (Argc < 2) {
+cl::PrintHelpMessage();
+return 1;
+  }
+
+  llvm_unreachable("We should never get here, parsing should always exit.");
+  return 1;
+}
+
+extern bool IsLLVMDriver;
+
+int main(int Argc, char **Argv) {
+  IsLLVMDriver = true;
+  llvm::StringRef LaunchedTool = sys::path::stem(Argv[0]);
+  // If the driver is launched directly.
+  int PassThroughArgC = Argc;
+  char **PassThroughArgV = Argv;
+  bool ConsumeFirstArg = false;
+  if (LaunchedTool == "llvm") {
+if (Argc < 2)
+  return UnknownMain(Argc, Argv);
+LaunchedTool = Argv[1];
+ConsumeFirstArg = true;
+  }
+
+  // if it is launched through a symlink that is the tool name.
+  typedef int (*MainFunction)(int, char **);
+  MainFunction Func = StringSwitch(LaunchedTool)
+
+#define LLVM_DRIVER_TOOL(tool, entry, key) .Case(tool, entry##_main)
+#include "LLVMDriverTools.def"
+  .Default(UnknownMain);
+  // If the main function is unknown we don't consume any args, so that we can
+  // print the appropriate help spew.
+  if (Func != UnknownMain && ConsumeFirstArg) {
+--PassThroughArgC;
+++PassThroughArgV;
+  }
+
+  return Func(PassThroughArgC, PassThroughArgV);
+}
Index: llvm/tools/llvm-driver/CMakeLists.txt
===
--- /dev/null
+++ llvm/tools/llvm-driver/CMakeLists.txt
@@ -0,0 +1,31 @@
+get_property(LLVM_COMMON_DEPENDS GLOBAL PROPERTY LLVM_DRIVER_DEPS)

[PATCH] D109977: LLVM Driver Multicall tool

2022-06-04 Thread Alex Brachet via Phabricator via cfe-commits
abrachet commandeered this revision.
abrachet added a reviewer: beanz.
abrachet added a comment.

I spoke to @beanz offline to make sure he is still ok with the patch being 
commandeered. Thanks for the patch @beanz, very excited about this :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-03-24 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

In D109977#3405687 , @phosek wrote:

> @beanz Let me know if you need help, I'm happy to commandeer the change if 
> you're too busy.

Please feel free to commandeer it. I'm really sorry I've held this up so long 
and I'm totally swamped right now :(.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-03-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.
Herald added a subscriber: StephenFan.

@beanz Let me know if you need help, I'm happy to commandeer the change if 
you're too busy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-03-13 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

Another potential future improvement is error reporting for subcommands:

  $ ./bin/llvm clang   
  llvm: error: no input files
  $ ./bin/clang
  clang-15: error: no input files

Ideally, the multicall tool would produce the same error message.




Comment at: llvm/cmake/modules/AddLLVM.cmake:897
+set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_TOOLS ${name})
+target_link_libraries(${obj_name} PUBLIC ${LLVM_PTHREAD_LIB})
+llvm_config(${obj_name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} )

The error that @MaskRay reported is because we use `PUBLIC` with 
`target_link_libraries()` here, but we use plain form of 
`target_link_libraries()` later in  `explicit_llvm_config` that is invoked 
`llvm_config` (see 
https://github.com/llvm/llvm-project/blob/1643f01232b41b93e5f3a21d89b111efab0e378a/llvm/cmake/modules/LLVM-Config.cmake#L110).
 Omitting `PUBLIC` here appears to be sufficient to avoid the error.



Comment at: llvm/tools/CMakeLists.txt:59
+# scrape up tools from other projects into itself.
+add_subdirectory(llvm-driver)

Should this be guarded by `LLVM_TOOL_LLVM_DRIVER_BUILD` to behave as the commit 
message says? Currently the `llvm-driver` appears to be built regardless of 
`LLVM_TOOL_LLVM_DRIVER_BUILD`.



Comment at: llvm/tools/llvm-driver/llvm-driver.cpp:43
+  if (LaunchedTool == "llvm") {
+LaunchedTool = Argv[1];
+ConsumeFirstArg = true;

When the tool is invoked without any arguments (that is, simply as 
`./bin/llvm`) this will lead to out-of-bounds array access. We should handle 
this case explicitly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-03-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.
Herald added a project: All.

In D109977#3282545 , @MaskRay wrote:

> I have tried the latest diff but 
> `-DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;flang;lldb;lld;compiler-rt;openmp;mlir;cross-project-tests'
>  -DLLVM_TOOL_LLVM_DRIVER_BUILD=on` gives me:
>
>   CMake Error at cmake/modules/LLVM-Config.cmake:110 (target_link_libraries): 
> 
> The keyword signature for target_link_libraries has already been used 
> with
> the target "obj.dsymutil".  All uses of target_link_libraries with a 
> target   
> must be either all-keyword or all-plain.  
> 
>   
> 
> The uses of the keyword signature are here:   
>   
>   
> 
>  * cmake/modules/AddLLVM.cmake:897 (target_link_libraries)
> 
>   
> 
>   Call Stack (most recent call first):
> 
> cmake/modules/LLVM-Config.cmake:95 (explicit_llvm_config) 
> 
> cmake/modules/AddLLVM.cmake:898 (llvm_config) 
>   
> cmake/modules/AddLLVM.cmake:1264 (add_llvm_executable)
>   
> tools/dsymutil/CMakeLists.txt:21 (add_llvm_tool)

⬆️


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-01-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Hope that someone familiar with CMake can take a look.

> As currently implemented llvm-driver contains dsymutil, llvm-ar, 
> llvm-cxxfilt, llvm-objcopy, and clang (if clang is included in the build).

I think either (bundled clang+binary utilities) or (bundled lld+binary 
utilities) is fine.
Some folks are interested in PGO builds for clang and lld. Not bundling clang 
and lld together can make both optimized.
The performance of binary utilities likely does not matter that much, so 
bundling them with either clang or lld should be fine.

---

I have tried the latest diff but 
`-DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;flang;lldb;lld;compiler-rt;openmp;mlir;cross-project-tests'
 -DLLVM_TOOL_LLVM_DRIVER_BUILD=on` gives me:

  CMake Error at cmake/modules/LLVM-Config.cmake:110 (target_link_libraries):   
  
The keyword signature for target_link_libraries has already been used with  
  
the target "obj.dsymutil".  All uses of target_link_libraries with a target 
  
must be either all-keyword or all-plain.
  

  
The uses of the keyword signature are here: 


  
 * cmake/modules/AddLLVM.cmake:897 (target_link_libraries)  
  

  
  Call Stack (most recent call first):  
  
cmake/modules/LLVM-Config.cmake:95 (explicit_llvm_config)   
  
cmake/modules/AddLLVM.cmake:898 (llvm_config)   

cmake/modules/AddLLVM.cmake:1264 (add_llvm_executable)  

tools/dsymutil/CMakeLists.txt:21 (add_llvm_tool)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-01-28 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 404114.
beanz added a comment.

Adding support for multiple subcommands mapping to the same entry.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

Files:
  clang/cmake/modules/AddClang.cmake
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/driver.cpp
  llvm/cmake/driver-template.cpp.in
  llvm/cmake/modules/AddLLVM.cmake
  llvm/test/CMakeLists.txt
  llvm/test/lit.cfg.py
  llvm/test/lit.site.cfg.py.in
  llvm/test/tools/llvm-driver/help-passthrough.test
  llvm/test/tools/llvm-driver/help.test
  llvm/test/tools/llvm-driver/symlink-call.test
  llvm/tools/CMakeLists.txt
  llvm/tools/dsymutil/CMakeLists.txt
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-ar/CMakeLists.txt
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-cxxfilt/CMakeLists.txt
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-driver/CMakeLists.txt
  llvm/tools/llvm-driver/llvm-driver.cpp
  llvm/tools/llvm-objcopy/CMakeLists.txt
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp

Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -402,7 +402,7 @@
   return Error::success();
 }
 
-int main(int argc, char **argv) {
+int llvm_objcopy_main(int argc, char **argv) {
   InitLLVM X(argc, argv);
   ToolName = argv[0];
 
Index: llvm/tools/llvm-objcopy/CMakeLists.txt
===
--- llvm/tools/llvm-objcopy/CMakeLists.txt
+++ llvm/tools/llvm-objcopy/CMakeLists.txt
@@ -43,6 +43,7 @@
   ObjcopyOptsTableGen
   InstallNameToolOptsTableGen
   StripOptsTableGen
+  GENERATE_DRIVER
   )
 
 add_llvm_tool_symlink(llvm-install-name-tool llvm-objcopy)
Index: llvm/tools/llvm-driver/llvm-driver.cpp
===
--- /dev/null
+++ llvm/tools/llvm-driver/llvm-driver.cpp
@@ -0,0 +1,62 @@
+//===-- llvm-driver.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
+
+using namespace llvm;
+
+#define LLVM_DRIVER_TOOL(tool, entry, key) \
+  int entry##_main(int argc, char **argv);
+#include "LLVMDriverTools.def"
+
+// This function handles the case of not recognizing the tool requested, or if
+// --help or --version are passed directly to the llvm driver.
+int UnknownMain(int Argc, char **Argv) {
+  cl::OptionCategory LLVMDriverCategory("llvm options");
+#define LLVM_DRIVER_TOOL(tool, entry, key) \
+  cl::SubCommand key##Subcommand(tool, tool);
+#include "LLVMDriverTools.def"
+
+  cl::HideUnrelatedOptions(LLVMDriverCategory);
+  cl::ParseCommandLineOptions(Argc, Argv, "llvm compiler driver\n");
+  llvm_unreachable("We should never get here, parsing should always exit.");
+  return 1;
+}
+
+int main(int Argc, char **Argv) {
+  llvm::StringRef LaunchedTool = sys::path::stem(Argv[0]);
+  // If the driver is launched directly.
+  int PassThroughArgC = Argc;
+  char **PassThroughArgV = Argv;
+  bool ConsumeFirstArg = false;
+  if (LaunchedTool == "llvm") {
+LaunchedTool = Argv[1];
+ConsumeFirstArg = true;
+  }
+
+  // if it is launched through a symlink that is the tool name.
+  typedef int (*MainFunction)(int, char **);
+  MainFunction Func = StringSwitch(LaunchedTool)
+
+#define LLVM_DRIVER_TOOL(tool, entry, key) .Case(tool, entry##_main)
+#include "LLVMDriverTools.def"
+  .Default(UnknownMain);
+  // If the main function is unknown we don't consume any args, so that we can
+  // print the appropriate help spew.
+  if (Func != UnknownMain && ConsumeFirstArg) {
+--PassThroughArgC;
+++PassThroughArgV;
+  }
+
+  return Func(PassThroughArgC, PassThroughArgV);
+}
Index: llvm/tools/llvm-driver/CMakeLists.txt
===
--- /dev/null
+++ llvm/tools/llvm-driver/CMakeLists.txt
@@ -0,0 +1,30 @@
+get_property(LLVM_COMMON_DEPENDS GLOBAL PROPERTY LLVM_DRIVER_DEPS)
+get_property(LLVM_DRIVER_OBJLIBS GLOBAL PROPERTY LLVM_DRIVER_OBJLIBS)
+
+get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
+
+foreach(tool ${LLVM_DRIVER_TOOLS})
+  string(REPLACE "-" "_" tool_entry ${tool})
+  set(def_decl "${def_decl}LLVM_DRIVER_TOOL(\"${tool}\", ${tool_entry}, ${tool_entry})\n")
+endforeach()
+

[PATCH] D109977: LLVM Driver Multicall tool

2022-01-28 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

Sorry for disappearing on this. I'm working right now on adding support for 
multi-entry tools (like objcopy). I'll get an update in today.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2022-01-28 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Ping @beanz


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2021-10-22 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

@beanz Is this ready to land or do you plan on making any more changes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2021-09-17 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: llvm/tools/llvm-objcopy/llvm-objcopy.cpp:404
 
-int main(int argc, char **argv) {
+int llvm_objcopy_main(int argc, char **argv) {
   InitLLVM X(argc, argv);

aganea wrote:
> Shouldn't we say:
> ```
> int objcopy_main(int argc, char **argv) {
> ```
> here and the other places + all supporting code, if we want `llvm objcopy` 
> (without the dash) like @phosek suggests?
I had a different thought for that. I think we want the tools to respond to 
llvm-objcopy since we will want them to exist in parallel to binutils tools 
just like the current tools do today.

Many of the current tools also support symlink-redirection, to support that 
we'll need to have a multiplex where multiple tool names point to the same 
`main` function.

Handling that was my point (1) in the `main` commit message, and I intended to 
work on it in a follow-on commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2021-09-17 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

This is really a great change, thanks @beanz!




Comment at: llvm/tools/llvm-objcopy/llvm-objcopy.cpp:404
 
-int main(int argc, char **argv) {
+int llvm_objcopy_main(int argc, char **argv) {
   InitLLVM X(argc, argv);

Shouldn't we say:
```
int objcopy_main(int argc, char **argv) {
```
here and the other places + all supporting code, if we want `llvm objcopy` 
(without the dash) like @phosek suggests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2021-09-17 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 373300.
beanz added a comment.

Renaming llvm-driver binary to llvm.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

Files:
  clang/cmake/modules/AddClang.cmake
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/driver.cpp
  llvm/cmake/driver-template.cpp.in
  llvm/cmake/modules/AddLLVM.cmake
  llvm/test/CMakeLists.txt
  llvm/test/lit.cfg.py
  llvm/test/lit.site.cfg.py.in
  llvm/test/tools/llvm-driver/help-passthrough.test
  llvm/test/tools/llvm-driver/help.test
  llvm/test/tools/llvm-driver/symlink-call.test
  llvm/tools/CMakeLists.txt
  llvm/tools/dsymutil/CMakeLists.txt
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-ar/CMakeLists.txt
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-cxxfilt/CMakeLists.txt
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-driver/CMakeLists.txt
  llvm/tools/llvm-driver/llvm-driver.cpp
  llvm/tools/llvm-objcopy/CMakeLists.txt
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp

Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -401,7 +401,7 @@
   return Error::success();
 }
 
-int main(int argc, char **argv) {
+int llvm_objcopy_main(int argc, char **argv) {
   InitLLVM X(argc, argv);
   ToolName = argv[0];
 
Index: llvm/tools/llvm-objcopy/CMakeLists.txt
===
--- llvm/tools/llvm-objcopy/CMakeLists.txt
+++ llvm/tools/llvm-objcopy/CMakeLists.txt
@@ -43,6 +43,7 @@
   ObjcopyOptsTableGen
   InstallNameToolOptsTableGen
   StripOptsTableGen
+  GENERATE_DRIVER
   )
 
 add_llvm_tool_symlink(llvm-install-name-tool llvm-objcopy)
Index: llvm/tools/llvm-driver/llvm-driver.cpp
===
--- /dev/null
+++ llvm/tools/llvm-driver/llvm-driver.cpp
@@ -0,0 +1,61 @@
+//===-- llvm-driver.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
+
+using namespace llvm;
+
+#define LLVM_DRIVER_TOOL(tool, entry) int entry##_main(int argc, char **argv);
+#include "LLVMDriverTools.def"
+
+// This function handles the case of not recognizing the tool requested, or if
+// --help or --version are passed directly to the llvm driver.
+int UnknownMain(int Argc, char **Argv) {
+  cl::OptionCategory LLVMDriverCategory("llvm options");
+#define LLVM_DRIVER_TOOL(tool, entry)  \
+  cl::SubCommand entry##Subcommand(tool, tool);
+#include "LLVMDriverTools.def"
+
+  cl::HideUnrelatedOptions(LLVMDriverCategory);
+  cl::ParseCommandLineOptions(Argc, Argv, "llvm compiler driver\n");
+  llvm_unreachable("We should never get here, parsing should always exit.");
+  return 1;
+}
+
+int main(int Argc, char **Argv) {
+  llvm::StringRef LaunchedTool = sys::path::stem(Argv[0]);
+  // If the driver is launched directly.
+  int PassThroughArgC = Argc;
+  char **PassThroughArgV = Argv;
+  bool ConsumeFirstArg = false;
+  if (LaunchedTool == "llvm") {
+LaunchedTool = Argv[1];
+ConsumeFirstArg = true;
+  }
+
+  // if it is launched through a symlink that is the tool name.
+  typedef int (*MainFunction)(int, char **);
+  MainFunction Func = StringSwitch(LaunchedTool)
+
+#define LLVM_DRIVER_TOOL(tool, entry) .Case(tool, entry##_main)
+#include "LLVMDriverTools.def"
+  .Default(UnknownMain);
+  // If the main function is unknown we don't consume any args, so that we can
+  // print the appropriate help spew.
+  if (Func != UnknownMain && ConsumeFirstArg) {
+--PassThroughArgC;
+++PassThroughArgV;
+  }
+
+  return Func(PassThroughArgC, PassThroughArgV);
+}
Index: llvm/tools/llvm-driver/CMakeLists.txt
===
--- /dev/null
+++ llvm/tools/llvm-driver/CMakeLists.txt
@@ -0,0 +1,28 @@
+get_property(LLVM_COMMON_DEPENDS GLOBAL PROPERTY LLVM_DRIVER_DEPS)
+get_property(LLVM_DRIVER_OBJLIBS GLOBAL PROPERTY LLVM_DRIVER_OBJLIBS)
+
+get_property(LLVM_DRIVER_TOOLS GLOBAL PROPERTY LLVM_DRIVER_TOOLS)
+
+foreach(tool ${LLVM_DRIVER_TOOLS})
+  string(REPLACE "-" "_" tool_entry ${tool})
+  set(def_decl "${def_decl}LLVM_DRIVER_TOOL(\"${tool}\", ${tool_entry})\n")
+endforeach()
+
+file(WRITE
+  "${CMAKE_CURRENT_BINARY_DIR}/LLVMDriverTools.def"
+  "${def_decl}#undef 

[PATCH] D109977: LLVM Driver Multicall tool

2021-09-17 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: llvm/tools/llvm-driver/CMakeLists.txt:17
+
+add_llvm_tool(llvm-driver
+  llvm-driver.cpp

phosek wrote:
> As was already suggested on D104686, I'd prefer naming this just `llvm` so 
> you can invoke tools with `llvm name` which doesn't require any additional 
> typing compared to `llvm-name`.
Can do


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2021-09-17 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

In D109977#3006687 , @mehdi_amini 
wrote:

> That's pretty nice! Have you thought about looking into a lit option 
> (triggered by a cmake flag maybe) that would change the substitution for the 
> tools that are enabled by llvm-driver to use the latter instead when running 
> the tests?

That's an awesome idea. I had been thinking about having a CMake option to 
generate symlinks instead of the tools, but you could totally bake this into 
the lit substitutions. I'll take a look at that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2021-09-17 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: llvm/tools/llvm-driver/CMakeLists.txt:17
+
+add_llvm_tool(llvm-driver
+  llvm-driver.cpp

As was already suggested on D104686, I'd prefer naming this just `llvm` so you 
can invoke tools with `llvm name` which doesn't require any additional typing 
compared to `llvm-name`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2021-09-17 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

That's pretty nice! Have you thought about looking into a lit option (triggered 
by a cmake flag maybe) that would change the substitution for the tools that 
are enabled by llvm-driver to use the latter instead when running the tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109977: LLVM Driver Multicall tool

2021-09-17 Thread Chris Bieneman via Phabricator via cfe-commits
beanz created this revision.
beanz added reviewers: leonardchan, phosek, MaskRay, compnerd, mehdi_amini.
Herald added subscribers: rupprecht, mgorny.
Herald added a reviewer: JDevlieghere.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: rupprecht.
Herald added a reviewer: jhenderson.
beanz requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

This patch adds an llvm-driver multicall tool that can combine multiple
LLVM-based tools. The build infrastructure is enabled for a tool by
adding the `GENERATE_DRIVER` option to the `add_llvm_executable` CMake
call, and changing the tool's `main` function to a canonicalized
`tool_name_main` format (i.e. llvm_ar_main, clang_main, etc...).

As currently implemented llvm-driver contains dsymutil, llvm-ar,
llvm-cxxfilt, llvm-objcopy, and clang (if clang is included in the
build).

llvm-driver can be disabled from builds by setting
LLVM_TOOL_LLVM_DRIVER_BUILD=Off.

There are several limitations in the current implementation, which can
be addressed in subsequent patches:

(1) the multicall binary cannot currently properly handle
multi-dispatch tools. This means symlinking llvm-ranlib to llvm-driver
will not properly result in llvm-ar's main being called.
(2) the multicall binary cannot be comprised of tools containing
conflicting cl::opt options as the global cl::opt option list cannot
contain duplicates.

These limitations can be addressed in subsequent patches.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109977

Files:
  clang/cmake/modules/AddClang.cmake
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/driver.cpp
  llvm/cmake/driver-template.cpp
  llvm/cmake/modules/AddLLVM.cmake
  llvm/test/CMakeLists.txt
  llvm/test/lit.cfg.py
  llvm/test/lit.site.cfg.py.in
  llvm/test/tools/llvm-driver/help-passthrough.test
  llvm/test/tools/llvm-driver/help.test
  llvm/test/tools/llvm-driver/symlink-call.test
  llvm/tools/CMakeLists.txt
  llvm/tools/dsymutil/CMakeLists.txt
  llvm/tools/dsymutil/dsymutil.cpp
  llvm/tools/llvm-ar/CMakeLists.txt
  llvm/tools/llvm-ar/llvm-ar.cpp
  llvm/tools/llvm-cxxfilt/CMakeLists.txt
  llvm/tools/llvm-cxxfilt/llvm-cxxfilt.cpp
  llvm/tools/llvm-driver/CMakeLists.txt
  llvm/tools/llvm-driver/llvm-driver.cpp
  llvm/tools/llvm-objcopy/CMakeLists.txt
  llvm/tools/llvm-objcopy/llvm-objcopy.cpp

Index: llvm/tools/llvm-objcopy/llvm-objcopy.cpp
===
--- llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -401,7 +401,7 @@
   return Error::success();
 }
 
-int main(int argc, char **argv) {
+int llvm_objcopy_main(int argc, char **argv) {
   InitLLVM X(argc, argv);
   ToolName = argv[0];
 
Index: llvm/tools/llvm-objcopy/CMakeLists.txt
===
--- llvm/tools/llvm-objcopy/CMakeLists.txt
+++ llvm/tools/llvm-objcopy/CMakeLists.txt
@@ -43,6 +43,7 @@
   ObjcopyOptsTableGen
   InstallNameToolOptsTableGen
   StripOptsTableGen
+  GENERATE_DRIVER
   )
 
 add_llvm_tool_symlink(llvm-install-name-tool llvm-objcopy)
Index: llvm/tools/llvm-driver/llvm-driver.cpp
===
--- /dev/null
+++ llvm/tools/llvm-driver/llvm-driver.cpp
@@ -0,0 +1,61 @@
+//===-- llvm-driver.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/WithColor.h"
+
+using namespace llvm;
+
+#define LLVM_DRIVER_TOOL(tool, entry) int entry##_main(int argc, char **argv);
+#include "LLVMDriverTools.def"
+
+// This function handles the case of not recognizing the tool requested, or if
+// --help or --version are passed directly to llvm-driver.
+int UnknownMain(int Argc, char **Argv) {
+  cl::OptionCategory LLVMDriverCategory("llvm-driver options");
+#define LLVM_DRIVER_TOOL(tool, entry)  \
+  cl::SubCommand entry##Subcommand(tool, tool);
+#include "LLVMDriverTools.def"
+
+  cl::HideUnrelatedOptions(LLVMDriverCategory);
+  cl::ParseCommandLineOptions(Argc, Argv, "llvm compiler driver\n");
+  llvm_unreachable("We should never get here, parsing should always exit.");
+  return 1;
+}
+
+int main(int Argc, char **Argv) {
+  llvm::StringRef LaunchedTool = sys::path::stem(Argv[0]);
+  // If the driver is launched directly.
+  int PassThroughArgC = Argc;
+  char **PassThroughArgV = Argv;
+  bool ConsumeFirstArg = false;
+  if (LaunchedTool == "llvm-driver") {