Skip to content

Commit 8824746

Browse files
aaupovsayhaan
authored andcommitted
Rebase: [Facebook] Add clang driver options to test debug info and BOLT
Summary: This is an essential piece of infrastructure for us to be continuously testing debug info with BOLT. We can't only make changes to a test repo because we need to change debuginfo tests to call BOLT, hence, this diff needs to sit in our opensource repo. But when upstreaming to LLVM, this should be kept BOLT-only outside of LLVM. When upstreaming, we need to git diff and check all folders that are being modified by our commits and discard this one (and leave as an internal diff). To test BOLT in debuginfo tests, configure it with -DLLVM_TEST_BOLT=ON. Then run check-lldb and check-debuginfo. Manual rebase conflict history: https://phabricator.intern.facebook.com/D29205224 https://phabricator.intern.facebook.com/D29564078 https://phabricator.intern.facebook.com/D33289118 https://phabricator.intern.facebook.com/D34957174 https://phabricator.intern.facebook.com/D35317341 Test Plan: tested locally Configured with: -DLLVM_ENABLE_PROJECTS="clang;lld;lldb;compiler-rt;bolt;debuginfo-tests" -DLLVM_TEST_BOLT=ON Ran test suite with: ninja check-debuginfo ninja check-lldb Reviewers: maks, #llvm-bolt Reviewed By: maks Subscribers: ayermolo, phabricatorlinter Differential Revision: https://phabricator.intern.facebook.com/D46256657 Tasks: T92898286
1 parent ef8de68 commit 8824746

File tree

9 files changed

+81
-1
lines changed

9 files changed

+81
-1
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5561,6 +5561,10 @@ def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">,
55615561
MarshallingInfoFlag<CodeGenOpts<"InstrumentForProfiling">>;
55625562
def pipe : Flag<["-", "--"], "pipe">,
55635563
HelpText<"Use pipes between commands, when possible">;
5564+
// Facebook T92898286
5565+
def post_link_optimize : Flag<["--"], "post-link-optimize">,
5566+
HelpText<"Apply post-link optimizations using BOLT">;
5567+
// End Facebook T92898286
55645568
def prebind__all__twolevel__modules : Flag<["-"], "prebind_all_twolevel_modules">;
55655569
def prebind : Flag<["-"], "prebind">;
55665570
def preload : Flag<["-"], "preload">;

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,41 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
672672
}
673673
}
674674

675+
// Facebook T92898286
676+
if (Args.hasArg(options::OPT_post_link_optimize))
677+
CmdArgs.push_back("-q");
678+
// End Facebook T92898286
679+
675680
Args.AddAllArgs(CmdArgs, options::OPT_T);
676681

677682
const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
678683
C.addCommand(std::make_unique<Command>(JA, *this,
679684
ResponseFileSupport::AtFileCurCP(),
680685
Exec, CmdArgs, Inputs, Output));
686+
// Facebook T92898286
687+
if (!Args.hasArg(options::OPT_post_link_optimize) || !Output.isFilename())
688+
return;
689+
690+
const char *MvExec = Args.MakeArgString(ToolChain.GetProgramPath("mv"));
691+
ArgStringList MoveCmdArgs;
692+
MoveCmdArgs.push_back(Output.getFilename());
693+
const char *PreBoltBin =
694+
Args.MakeArgString(Twine(Output.getFilename()) + ".pre-bolt");
695+
MoveCmdArgs.push_back(PreBoltBin);
696+
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
697+
MvExec, MoveCmdArgs, std::nullopt));
698+
699+
ArgStringList BoltCmdArgs;
700+
const char *BoltExec =
701+
Args.MakeArgString(ToolChain.GetProgramPath("llvm-bolt"));
702+
BoltCmdArgs.push_back(PreBoltBin);
703+
BoltCmdArgs.push_back("-reorder-blocks=reverse");
704+
BoltCmdArgs.push_back("-update-debug-sections");
705+
BoltCmdArgs.push_back("-o");
706+
BoltCmdArgs.push_back(Output.getFilename());
707+
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
708+
BoltExec, BoltCmdArgs, std::nullopt));
709+
// End Facebook T92898286
681710
}
682711

683712
void tools::gnutools::Assembler::ConstructJob(Compilation &C,

cross-project-tests/lit.cfg.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ def get_required_attr(config, attr_name):
8181
# use_clang() and use_lld() respectively, so set them to "", if needed.
8282
if not hasattr(config, "clang_src_dir"):
8383
config.clang_src_dir = ""
84-
llvm_config.use_clang(required=("clang" in config.llvm_enabled_projects))
84+
# Facebook T92898286
85+
should_test_bolt = get_required_attr(config, "llvm_test_bolt")
86+
if should_test_bolt:
87+
llvm_config.use_clang(required=("clang" in config.llvm_enabled_projects), additional_flags=["--post-link-optimize"])
88+
else:
89+
llvm_config.use_clang(required=("clang" in config.llvm_enabled_projects))
90+
# End Facebook T92898286
8591

8692
if not hasattr(config, "lld_src_dir"):
8793
config.lld_src_dir = ""
@@ -294,3 +300,9 @@ def get_clang_default_dwarf_version_string(triple):
294300
# Allow 'REQUIRES: XXX-registered-target' in tests.
295301
for arch in config.targets_to_build:
296302
config.available_features.add(arch.lower() + "-registered-target")
303+
304+
# Facebook T92898286
305+
# Ensure the user's PYTHONPATH is included.
306+
if "PYTHONPATH" in os.environ:
307+
config.environment["PYTHONPATH"] = os.environ["PYTHONPATH"]
308+
# End Facebook T92898286

cross-project-tests/lit.site.cfg.py.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ config.mlir_src_root = "@MLIR_SOURCE_DIR@"
2121

2222
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
2323

24+
# Facebook T92898286
25+
config.llvm_test_bolt = lit.util.pythonize_bool("@LLVM_TEST_BOLT@")
26+
# End Facebook T92898286
27+
2428
import lit.llvm
2529
lit.llvm.initialize(lit_config, config)
2630

lldb/test/API/lit.cfg.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ def delete_module_cache(path):
265265
if is_configured("lldb_framework_dir"):
266266
dotest_cmd += ["--framework", config.lldb_framework_dir]
267267

268+
# Facebook T92898286
269+
if is_configured("llvm_test_bolt"):
270+
dotest_cmd += ["-E", '"--post-link-optimize"']
271+
# End Facebook T92898286
272+
268273
if (
269274
"lldb-repro-capture" in config.available_features
270275
or "lldb-repro-replay" in config.available_features

lldb/test/API/lit.site.cfg.py.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
@LIT_SITE_CFG_IN_HEADER@
22

3+
#Facebook T92898286
4+
import lit.util
5+
#End Facebook T92898286
6+
37
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
48
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
59
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
@@ -39,6 +43,10 @@ config.libcxx_include_target_dir = "@LIBCXX_GENERATED_INCLUDE_TARGET_DIR@"
3943
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-api")
4044
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-api")
4145

46+
# Facebook T92898286
47+
config.llvm_test_bolt = lit.util.pythonize_bool("@LLVM_TEST_BOLT@")
48+
# End Facebook T92898286
49+
4250
# Plugins
4351
lldb_build_intel_pt = '@LLDB_BUILD_INTEL_PT@'
4452
if lldb_build_intel_pt == '1':

lldb/test/Shell/helper/toolchain.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ def use_support_substitutions(config):
165165
if config.cmake_sysroot:
166166
host_flags += ["--sysroot={}".format(config.cmake_sysroot)]
167167

168+
# Facebook T92898286
169+
if config.llvm_test_bolt:
170+
host_flags += ["--post-link-optimize"]
171+
# End Facebook T92898286
172+
168173
host_flags = " ".join(host_flags)
169174
config.substitutions.append(("%clang_host", "%clang " + host_flags))
170175
config.substitutions.append(("%clangxx_host", "%clangxx " + host_flags))

lldb/test/Shell/lit.site.cfg.py.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
@LIT_SITE_CFG_IN_HEADER@
22

3+
#Facebook T92898286
4+
import lit.util
5+
#End Facebook T92898286
6+
7+
38
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
49
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
510
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
@@ -31,6 +36,10 @@ config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
3136
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-shell")
3237
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-shell")
3338

39+
# Facebook T92898286
40+
config.llvm_test_bolt = lit.util.pythonize_bool("@LLVM_TEST_BOLT@")
41+
# End Facebook T92898286
42+
3443
import lit.llvm
3544
lit.llvm.initialize(lit_config, config)
3645

llvm/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,10 @@ set(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH
709709
option(LLVM_USE_SPLIT_DWARF
710710
"Use -gsplit-dwarf when compiling llvm and --gdb-index when linking." OFF)
711711

712+
# Facebook T92898286
713+
option(LLVM_TEST_BOLT "Enable BOLT testing in non-BOLT tests that use clang" OFF)
714+
# End Facebook T92898286
715+
712716
# Define an option controlling whether we should build for 32-bit on 64-bit
713717
# platforms, where supported.
714718
if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX"))

0 commit comments

Comments
 (0)