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

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: #llvm-bolt

Subscribers: ayermolo, phabricatorlinter

Differential Revision: https://phabricator.intern.facebook.com/D35317341

Tasks: T92898286
This commit is contained in:
Amir Ayupov 2021-06-01 11:37:41 -07:00 committed by spupyrev
parent c8a28ae214
commit f921985a29
9 changed files with 81 additions and 1 deletions

View File

@ -4001,6 +4001,10 @@ def pg : Flag<["-"], "pg">, HelpText<"Enable mcount instrumentation">, Flags<[CC
MarshallingInfoFlag<CodeGenOpts<"InstrumentForProfiling">>;
def pipe : Flag<["-", "--"], "pipe">,
HelpText<"Use pipes between commands, when possible">;
// Facebook T92898286
def post_link_optimize : Flag<["--"], "post-link-optimize">,
HelpText<"Apply post-link optimizations using BOLT">;
// End Facebook T92898286
def prebind__all__twolevel__modules : Flag<["-"], "prebind_all_twolevel_modules">;
def prebind : Flag<["-"], "prebind">;
def preload : Flag<["-"], "preload">;

View File

@ -684,12 +684,41 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
}
// Facebook T92898286
if (Args.hasArg(options::OPT_post_link_optimize))
CmdArgs.push_back("-q");
// End Facebook T92898286
Args.AddAllArgs(CmdArgs, options::OPT_T);
const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
C.addCommand(std::make_unique<Command>(JA, *this,
ResponseFileSupport::AtFileCurCP(),
Exec, CmdArgs, Inputs, Output));
// Facebook T92898286
if (!Args.hasArg(options::OPT_post_link_optimize) || !Output.isFilename())
return;
const char *MvExec = Args.MakeArgString(ToolChain.GetProgramPath("mv"));
ArgStringList MoveCmdArgs;
MoveCmdArgs.push_back(Output.getFilename());
const char *PreBoltBin =
Args.MakeArgString(Twine(Output.getFilename()) + ".pre-bolt");
MoveCmdArgs.push_back(PreBoltBin);
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
MvExec, MoveCmdArgs, None));
ArgStringList BoltCmdArgs;
const char *BoltExec =
Args.MakeArgString(ToolChain.GetProgramPath("llvm-bolt"));
BoltCmdArgs.push_back(PreBoltBin);
BoltCmdArgs.push_back("-reorder-blocks=reverse");
BoltCmdArgs.push_back("-update-debug-sections");
BoltCmdArgs.push_back("-o");
BoltCmdArgs.push_back(Output.getFilename());
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
BoltExec, BoltCmdArgs, None));
// End Facebook T92898286
}
void tools::gnutools::Assembler::ConstructJob(Compilation &C,

View File

@ -74,7 +74,13 @@ if is_msvc:
# use_clang() and use_lld() respectively, so set them to "", if needed.
if not hasattr(config, 'clang_src_dir'):
config.clang_src_dir = ""
llvm_config.use_clang(required=('clang' in config.llvm_enabled_projects))
# Facebook T92898286
should_test_bolt = get_required_attr(config, "llvm_test_bolt")
if should_test_bolt:
llvm_config.use_clang(required=('clang' in config.llvm_enabled_projects), additional_flags=['--post-link-optimize'])
else:
llvm_config.use_clang(required=('clang' in config.llvm_enabled_projects))
# End Facebook T92898286
if not hasattr(config, 'lld_src_dir'):
config.lld_src_dir = ""
@ -256,3 +262,9 @@ llvm_config.feature_config(
# Allow 'REQUIRES: XXX-registered-target' in tests.
for arch in config.targets_to_build:
config.available_features.add(arch.lower() + '-registered-target')
# Facebook T92898286
# Ensure the user's PYTHONPATH is included.
if 'PYTHONPATH' in os.environ:
config.environment['PYTHONPATH'] = os.environ['PYTHONPATH']
# End Facebook T92898286

View File

@ -21,6 +21,10 @@ config.mlir_src_root = "@MLIR_SOURCE_DIR@"
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
# Facebook T92898286
config.llvm_test_bolt = lit.util.pythonize_bool("@LLVM_TEST_BOLT@")
# End Facebook T92898286
import lit.llvm
lit.llvm.initialize(lit_config, config)

View File

@ -207,6 +207,11 @@ if is_configured('lldb_libs_dir'):
if is_configured('lldb_framework_dir'):
dotest_cmd += ['--framework', config.lldb_framework_dir]
# Facebook T92898286
if is_configured("llvm_test_bolt"):
dotest_cmd += ['-E', '"--post-link-optimize"']
# End Facebook T92898286
if 'lldb-repro-capture' in config.available_features or \
'lldb-repro-replay' in config.available_features:
dotest_cmd += ['--skip-category=lldb-vscode', '--skip-category=std-module']

View File

@ -1,5 +1,9 @@
@LIT_SITE_CFG_IN_HEADER@
#Facebook T92898286
import lit.util
#End Facebook T92898286
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
@ -33,6 +37,10 @@ config.dsymutil = lit_config.substitute('@LLDB_TEST_DSYMUTIL@')
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-api")
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-api")
# Facebook T92898286
config.llvm_test_bolt = lit.util.pythonize_bool("@LLVM_TEST_BOLT@")
# End Facebook T92898286
# Plugins
lldb_build_intel_pt = '@LLDB_BUILD_INTEL_PT@'
if lldb_build_intel_pt == '1':

View File

@ -138,6 +138,11 @@ def use_support_substitutions(config):
# The clang module cache is used for building inferiors.
host_flags += ['-fmodules-cache-path={}'.format(config.clang_module_cache)]
# Facebook T92898286
if config.llvm_test_bolt:
host_flags += ['--post-link-optimize']
# End Facebook T92898286
host_flags = ' '.join(host_flags)
config.substitutions.append(('%clang_host', '%clang ' + host_flags))
config.substitutions.append(('%clangxx_host', '%clangxx ' + host_flags))

View File

@ -1,5 +1,10 @@
@LIT_SITE_CFG_IN_HEADER@
#Facebook T92898286
import lit.util
#End Facebook T92898286
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
config.llvm_obj_root = "@LLVM_BINARY_DIR@"
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
@ -27,6 +32,10 @@ config.lldb_system_debugserver = @LLDB_USE_SYSTEM_DEBUGSERVER@
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-shell")
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-shell")
# Facebook T92898286
config.llvm_test_bolt = lit.util.pythonize_bool("@LLVM_TEST_BOLT@")
# End Facebook T92898286
import lit.llvm
lit.llvm.initialize(lit_config, config)

View File

@ -577,6 +577,10 @@ set(LLVM_LIB_FUZZING_ENGINE "" CACHE PATH
option(LLVM_USE_SPLIT_DWARF
"Use -gsplit-dwarf when compiling llvm and --gdb-index when linking." OFF)
# Facebook T92898286
option(LLVM_TEST_BOLT "Enable BOLT testing in non-BOLT tests that use clang" OFF)
# End Facebook T92898286
# Define an option controlling whether we should build for 32-bit on 64-bit
# platforms, where supported.
if( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "AIX"))