Index: llvm/tools/llvm-ifs/CMakeLists.txt =================================================================== --- llvm/tools/llvm-ifs/CMakeLists.txt +++ llvm/tools/llvm-ifs/CMakeLists.txt @@ -1,6 +1,6 @@ set(LLVM_LINK_COMPONENTS BinaryFormat - InterfaceStub + InterfaceStub Object Support TextAPI @@ -18,4 +18,6 @@ DEPENDS IFSOptsTableGen + + GENERATE_DRIVER ) Index: llvm/tools/llvm-ifs/llvm-ifs.cpp =================================================================== --- llvm/tools/llvm-ifs/llvm-ifs.cpp +++ llvm/tools/llvm-ifs/llvm-ifs.cpp @@ -376,7 +376,7 @@ return Config; } -int main(int argc, char *argv[]) { +int llvm_ifs_main(int argc, char *argv[]) { DriverConfig Config = parseArgs(argc, argv); if (Config.InputFilePaths.empty()) Index: llvm/tools/llvm-lipo/CMakeLists.txt =================================================================== --- llvm/tools/llvm-lipo/CMakeLists.txt +++ llvm/tools/llvm-lipo/CMakeLists.txt @@ -16,6 +16,7 @@ llvm-lipo.cpp DEPENDS LipoOptsTableGen + GENERATE_DRIVER ) if(LLVM_INSTALL_CCTOOLS_SYMLINKS) Index: llvm/tools/llvm-lipo/llvm-lipo.cpp =================================================================== --- llvm/tools/llvm-lipo/llvm-lipo.cpp +++ llvm/tools/llvm-lipo/llvm-lipo.cpp @@ -719,7 +719,7 @@ exit(EXIT_SUCCESS); } -int main(int argc, char **argv) { +int llvm_lipo_main(int argc, char **argv) { InitLLVM X(argc, argv); llvm::InitializeAllTargetInfos(); llvm::InitializeAllTargetMCs(); Index: llvm/tools/llvm-mt/CMakeLists.txt =================================================================== --- llvm/tools/llvm-mt/CMakeLists.txt +++ llvm/tools/llvm-mt/CMakeLists.txt @@ -11,4 +11,5 @@ add_llvm_tool(llvm-mt llvm-mt.cpp + GENERATE_DRIVER ) Index: llvm/tools/llvm-mt/llvm-mt.cpp =================================================================== --- llvm/tools/llvm-mt/llvm-mt.cpp +++ llvm/tools/llvm-mt/llvm-mt.cpp @@ -79,7 +79,7 @@ }); } -int main(int Argc, const char **Argv) { +int llvm_mt_main(int Argc, char **Argv) { InitLLVM X(Argc, Argv); CvtResOptTable T; Index: llvm/tools/llvm-nm/CMakeLists.txt =================================================================== --- llvm/tools/llvm-nm/CMakeLists.txt +++ llvm/tools/llvm-nm/CMakeLists.txt @@ -21,6 +21,7 @@ DEPENDS NmOptsTableGen intrinsics_gen + GENERATE_DRIVER ) if(LLVM_INSTALL_BINUTILS_SYMLINKS) Index: llvm/tools/llvm-nm/llvm-nm.cpp =================================================================== --- llvm/tools/llvm-nm/llvm-nm.cpp +++ llvm/tools/llvm-nm/llvm-nm.cpp @@ -2297,7 +2297,7 @@ printExportSymbolList(SymbolList); } -int main(int argc, char **argv) { +int llvm_nm_main(int argc, char **argv) { InitLLVM X(argc, argv); BumpPtrAllocator A; StringSaver Saver(A); @@ -2474,4 +2474,5 @@ if (HadError) return 1; + return 0; } Index: llvm/tools/llvm-profdata/CMakeLists.txt =================================================================== --- llvm/tools/llvm-profdata/CMakeLists.txt +++ llvm/tools/llvm-profdata/CMakeLists.txt @@ -11,4 +11,5 @@ DEPENDS intrinsics_gen + GENERATE_DRIVER ) Index: llvm/tools/llvm-profdata/llvm-profdata.cpp =================================================================== --- llvm/tools/llvm-profdata/llvm-profdata.cpp +++ llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -2826,7 +2826,8 @@ return showMemProfProfile(Filename, ProfiledBinary, OS); } -int main(int argc, const char *argv[]) { +int llvm_profdata_main(int argc, char *argvNonConst[]) { + const char **argv = const_cast(argvNonConst); InitLLVM X(argc, argv); StringRef ProgName(sys::path::filename(argv[0])); Index: llvm/tools/llvm-rc/CMakeLists.txt =================================================================== --- llvm/tools/llvm-rc/CMakeLists.txt +++ llvm/tools/llvm-rc/CMakeLists.txt @@ -19,6 +19,7 @@ ResourceScriptParser.cpp ResourceScriptStmt.cpp ResourceScriptToken.cpp + GENERATE_DRIVER ) add_llvm_tool_symlink(llvm-windres llvm-rc) Index: llvm/tools/llvm-rc/llvm-rc.cpp =================================================================== --- llvm/tools/llvm-rc/llvm-rc.cpp +++ llvm/tools/llvm-rc/llvm-rc.cpp @@ -724,12 +724,12 @@ } // anonymous namespace -int main(int Argc, const char **Argv) { +int llvm_rc_main(int Argc, char **Argv) { InitLLVM X(Argc, Argv); ExitOnErr.setBanner("llvm-rc: "); - const char **DashDash = std::find_if( - Argv + 1, Argv + Argc, [](StringRef Str) { return Str == "--"; }); + char **DashDash = std::find_if(Argv + 1, Argv + Argc, + [](StringRef Str) { return Str == "--"; }); ArrayRef ArgsArr = makeArrayRef(Argv + 1, DashDash); ArrayRef FileArgsArr; if (DashDash != Argv + Argc) Index: llvm/tools/llvm-readobj/CMakeLists.txt =================================================================== --- llvm/tools/llvm-readobj/CMakeLists.txt +++ llvm/tools/llvm-readobj/CMakeLists.txt @@ -27,6 +27,7 @@ Win64EHDumper.cpp WindowsResourceDumper.cpp XCOFFDumper.cpp + GENERATE_DRIVER ) add_llvm_tool_symlink(llvm-readelf llvm-readobj) Index: llvm/tools/llvm-readobj/llvm-readobj.cpp =================================================================== --- llvm/tools/llvm-readobj/llvm-readobj.cpp +++ llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -613,7 +613,7 @@ return std::make_unique(fouts()); } -int main(int argc, char *argv[]) { +int llvm_readobj_main(int argc, char *argv[]) { InitLLVM X(argc, argv); BumpPtrAllocator A; StringSaver Saver(A); Index: llvm/tools/llvm-size/CMakeLists.txt =================================================================== --- llvm/tools/llvm-size/CMakeLists.txt +++ llvm/tools/llvm-size/CMakeLists.txt @@ -12,6 +12,7 @@ llvm-size.cpp DEPENDS SizeOptsTableGen + GENERATE_DRIVER ) if(LLVM_INSTALL_BINUTILS_SYMLINKS) Index: llvm/tools/llvm-size/llvm-size.cpp =================================================================== --- llvm/tools/llvm-size/llvm-size.cpp +++ llvm/tools/llvm-size/llvm-size.cpp @@ -866,7 +866,7 @@ << "(TOTALS)\n"; } -int main(int argc, char **argv) { +int llvm_size_main(int argc, char **argv) { InitLLVM X(argc, argv); BumpPtrAllocator A; StringSaver Saver(A); @@ -941,4 +941,5 @@ if (HadError) return 1; + return 0; } Index: llvm/utils/gn/secondary/llvm/tools/llvm-ifs/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/tools/llvm-ifs/BUILD.gn +++ llvm/utils/gn/secondary/llvm/tools/llvm-ifs/BUILD.gn @@ -1,11 +1,12 @@ import("//llvm/utils/TableGen/tablegen.gni") +import("//llvm/utils/gn/build/driver_executable.gni") tablegen("Opts") { visibility = [ ":llvm-ifs" ] args = [ "-gen-opt-parser-defs" ] } -executable("llvm-ifs") { +driver_executable("llvm-ifs") { deps = [ ":Opts", "//llvm/lib/InterfaceStub", Index: llvm/utils/gn/secondary/llvm/tools/llvm-lipo/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/tools/llvm-lipo/BUILD.gn +++ llvm/utils/gn/secondary/llvm/tools/llvm-lipo/BUILD.gn @@ -1,6 +1,7 @@ import("//llvm/tools/cctools_symlinks.gni") import("//llvm/utils/TableGen/tablegen.gni") import("//llvm/utils/gn/build/symlink_or_copy.gni") +import("//llvm/utils/gn/build/driver_executable.gni") tablegen("LipoOpts") { visibility = [ ":llvm-lipo" ] @@ -23,7 +24,7 @@ } } -executable("llvm-lipo") { +driver_executable("llvm-lipo") { deps = [ ":LipoOpts", "//llvm/lib/Object", Index: llvm/utils/gn/secondary/llvm/tools/llvm-mt/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/tools/llvm-mt/BUILD.gn +++ llvm/utils/gn/secondary/llvm/tools/llvm-mt/BUILD.gn @@ -1,11 +1,12 @@ import("//llvm/utils/TableGen/tablegen.gni") +import("//llvm/utils/gn/build/driver_executable.gni") tablegen("Opts") { visibility = [ ":llvm-mt" ] args = [ "-gen-opt-parser-defs" ] } -executable("llvm-mt") { +driver_executable("llvm-mt") { deps = [ ":Opts", "//llvm/lib/Option", Index: llvm/utils/gn/secondary/llvm/tools/llvm-nm/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/tools/llvm-nm/BUILD.gn +++ llvm/utils/gn/secondary/llvm/tools/llvm-nm/BUILD.gn @@ -1,6 +1,7 @@ import("//llvm/tools/binutils_symlinks.gni") import("//llvm/utils/TableGen/tablegen.gni") import("//llvm/utils/gn/build/symlink_or_copy.gni") +import("//llvm/utils/gn/build/driver_executable.gni") tablegen("Opts") { visibility = [ ":llvm-nm" ] @@ -23,7 +24,7 @@ } } -executable("llvm-nm") { +driver_executable("llvm-nm") { deps = [ ":Opts", "//llvm/lib/Bitcode/Reader", Index: llvm/utils/gn/secondary/llvm/tools/llvm-profdata/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/tools/llvm-profdata/BUILD.gn +++ llvm/utils/gn/secondary/llvm/tools/llvm-profdata/BUILD.gn @@ -1,4 +1,6 @@ -executable("llvm-profdata") { +import("//llvm/utils/gn/build/driver_executable.gni") + +driver_executable("llvm-profdata") { deps = [ "//llvm/lib/IR", "//llvm/lib/ProfileData", Index: llvm/utils/gn/secondary/llvm/tools/llvm-rc/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/tools/llvm-rc/BUILD.gn +++ llvm/utils/gn/secondary/llvm/tools/llvm-rc/BUILD.gn @@ -1,6 +1,7 @@ import("//llvm/tools/binutils_symlinks.gni") import("//llvm/utils/TableGen/tablegen.gni") import("//llvm/utils/gn/build/symlink_or_copy.gni") +import("//llvm/utils/gn/build/driver_executable.gni") tablegen("Opts") { visibility = [ ":llvm-rc" ] @@ -33,7 +34,7 @@ } } -executable("llvm-rc") { +driver_executable("llvm-rc") { deps = [ ":Opts", ":WindresOpts", Index: llvm/utils/gn/secondary/llvm/tools/llvm-readobj/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/tools/llvm-readobj/BUILD.gn +++ llvm/utils/gn/secondary/llvm/tools/llvm-readobj/BUILD.gn @@ -1,6 +1,7 @@ import("//llvm/tools/binutils_symlinks.gni") import("//llvm/utils/TableGen/tablegen.gni") import("//llvm/utils/gn/build/symlink_or_copy.gni") +import("//llvm/utils/gn/build/driver_executable.gni") tablegen("Opts") { visibility = [ ":llvm-readobj" ] @@ -27,7 +28,7 @@ } } -executable("llvm-readobj") { +driver_executable("llvm-readobj") { deps = [ ":Opts", "//llvm/lib/BinaryFormat", Index: llvm/utils/gn/secondary/llvm/tools/llvm-size/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/llvm/tools/llvm-size/BUILD.gn +++ llvm/utils/gn/secondary/llvm/tools/llvm-size/BUILD.gn @@ -1,6 +1,7 @@ import("//llvm/tools/binutils_symlinks.gni") import("//llvm/utils/TableGen/tablegen.gni") import("//llvm/utils/gn/build/symlink_or_copy.gni") +import("//llvm/utils/gn/build/driver_executable.gni") tablegen("Opts") { visibility = [ ":llvm-size" ] @@ -23,7 +24,7 @@ } } -executable("llvm-size") { +driver_executable("llvm-size") { deps = [ ":Opts", "//llvm/lib/Object", 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 @@ -3124,12 +3124,21 @@ td_srcs = ["include/llvm/Option/OptParser.td"], ) +expand_template( + name = "ifs_main", + out = "llvm-ifs-driver.cpp", + substitutions = { + "@TOOL_NAME@": "llvm_ifs", + }, + template = "cmake/modules/llvm-driver-template.cpp.in", +) + cc_binary( name = "llvm-ifs", srcs = glob([ "tools/llvm-ifs/*.cpp", "tools/llvm-ifs/*.h", - ]), + ]) + ["llvm-ifs-driver.cpp"], copts = llvm_copts, stamp = 0, deps = [ @@ -3232,11 +3241,20 @@ td_srcs = ["include/llvm/Option/OptParser.td"], ) +expand_template( + name = "lipo_main", + out = "llvm-lipo-driver.cpp", + substitutions = { + "@TOOL_NAME@": "llvm_lipo", + }, + template = "cmake/modules/llvm-driver-template.cpp.in", +) + cc_binary( name = "llvm-lipo", srcs = [ "tools/llvm-lipo/llvm-lipo.cpp", - ], + ] + ["llvm-lipo-driver.cpp"], copts = llvm_copts, stamp = 0, deps = [ @@ -3391,12 +3409,21 @@ td_srcs = ["include/llvm/Option/OptParser.td"], ) +expand_template( + name = "mt_main", + out = "llvm-mt-driver.cpp", + substitutions = { + "@TOOL_NAME@": "llvm_mt", + }, + template = "cmake/modules/llvm-driver-template.cpp.in", +) + cc_binary( name = "llvm-mt", srcs = glob([ "tools/llvm-mt/*.cpp", "tools/llvm-mt/*.h", - ]), + ]) + ["llvm-mt-driver.cpp"], copts = llvm_copts, stamp = 0, deps = [ @@ -3419,12 +3446,21 @@ td_srcs = ["include/llvm/Option/OptParser.td"], ) +expand_template( + name = "nm_main", + out = "llvm-nm-driver.cpp", + substitutions = { + "@TOOL_NAME@": "llvm_nm", + }, + template = "cmake/modules/llvm-driver-template.cpp.in", +) + cc_binary( name = "llvm-nm", srcs = glob([ "tools/llvm-nm/*.cpp", "tools/llvm-nm/*.h", - ]), + ]) + ["llvm-nm-driver.cpp"], copts = llvm_copts, stamp = 0, deps = [ @@ -3657,12 +3693,21 @@ ], ) +expand_template( + name = "profdata_main", + out = "llvm-profdata-driver.cpp", + substitutions = { + "@TOOL_NAME@": "llvm_profdata", + }, + template = "cmake/modules/llvm-driver-template.cpp.in", +) + cc_binary( name = "llvm-profdata", srcs = glob([ "tools/llvm-profdata/*.cpp", "tools/llvm-profdata/*.h", - ]), + ]) + ["llvm-profdata-driver.cpp"], copts = llvm_copts, stamp = 0, deps = [ @@ -3717,12 +3762,21 @@ textual_hdrs = glob(["tools/llvm-rc/*.def"]), ) +expand_template( + name = "rc_main", + out = "llvm-rc-driver.cpp", + substitutions = { + "@TOOL_NAME@": "llvm_rc", + }, + template = "cmake/modules/llvm-driver-template.cpp.in", +) + cc_binary( name = "llvm-rc", srcs = glob([ "tools/llvm-rc/*.cpp", "tools/llvm-rc/*.h", - ]), + ]) + ["llvm-rc-driver.cpp"], copts = llvm_copts, stamp = 0, deps = [ @@ -3752,12 +3806,21 @@ td_srcs = ["include/llvm/Option/OptParser.td"], ) +expand_template( + name = "readobj_main", + out = "llvm-readobj-driver.cpp", + substitutions = { + "@TOOL_NAME@": "llvm_readobj", + }, + template = "cmake/modules/llvm-driver-template.cpp.in", +) + cc_binary( name = "llvm-readobj", srcs = glob([ "tools/llvm-readobj/*.cpp", "tools/llvm-readobj/*.h", - ]), + ]) + ["llvm-readobj-driver.cpp"], copts = llvm_copts, stamp = 0, deps = [ @@ -3848,12 +3911,21 @@ td_srcs = ["include/llvm/Option/OptParser.td"], ) +expand_template( + name = "size_main", + out = "llvm-size-driver.cpp", + substitutions = { + "@TOOL_NAME@": "llvm_size", + }, + template = "cmake/modules/llvm-driver-template.cpp.in", +) + cc_binary( name = "llvm-size", srcs = glob([ "tools/llvm-size/*.cpp", "tools/llvm-size/*.h", - ]), + ]) + ["llvm-size-driver.cpp"], copts = llvm_copts, stamp = 0, deps = [