1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00
llvm-mirror/tools
Patrick Holland 81da9f4819 [MCA] llvm-mca MCTargetStreamer segfault fix
In order to create the code regions for llvm-mca to analyze, llvm-mca creates an
AsmCodeRegionGenerator and calls AsmCodeRegionGenerator::parseCodeRegions().
Within this function, both an MCAsmParser and MCTargetAsmParser are created so
that MCAsmParser::Run() can be used to create the code regions for us.

These parser classes were created for llvm-mc so they are designed to emit code
with an MCStreamer and MCTargetStreamer that are expected to be setup and passed
into the MCAsmParser constructor. Because llvm-mca doesn’t want to emit any
code, an MCStreamerWrapper class gets created instead and passed into the
MCAsmParser constructor. This wrapper inherits from MCStreamer and overrides
many of the emit methods to just do nothing. The exception is the
emitInstruction() method which calls Regions.addInstruction(Inst).

This works well and allows llvm-mca to utilize llvm-mc’s MCAsmParser to build
our code regions, however there are a few directives which rely on the
MCTargetStreamer. llvm-mc assumes that the MCStreamer that gets passed into the
MCAsmParser’s constructor has a valid pointer to an MCTargetStreamer. Because
llvm-mca doesn’t setup an MCTargetStreamer, when the parser encounters one of
those directives, a segfault will occur.

In x86, each one of these 7 directives will cause this segfault if they exist in
the input assembly to llvm-mca:

.cv_fpo_proc
.cv_fpo_setframe
.cv_fpo_pushreg
.cv_fpo_stackalloc
.cv_fpo_stackalign
.cv_fpo_endprologue
.cv_fpo_endproc
I haven’t looked at other targets, but I wouldn’t be surprised if some of the
other ones also have certain directives which could result in this same
segfault.

My proposed solution is to simply initialize an MCTargetStreamer after we
initialize the MCStreamerWrapper. The MCTargetStreamer requires an ostream
object, but we don’t actually want any of these directives to be emitted
anywhere, so I use an ostream created with the nulls() function. Since this
needs to happen after the MCStreamerWrapper has been initialized, it needs to
happen within the AsmCodeRegionGenerator::parseCodeRegions() function. The
MCTargetStreamer also needs an MCInstPrinter which is easiest to initialize
within the main() function of llvm-mca. So this MCInstPrinter gets constructed
within main() then passed into the parseCodeRegions() function as a parameter.
(If you feel like it would be appropriate and possible to create the
MCInstPrinter within the parseCodeRegions() function, then feel free to modify
my solution. That would stop us from having to pass it into the function and
would limit its scope / lifetime.)

My solution stops the segfault from happening and still passes all of the
current (expected) llvm-mca tests. I also added a new test for x86 that checks
for this segfault on an input that includes one of the .cv_fpo directives (this
test fails without my solution, but passes with it).

As far as I can tell, all of the functions that I modified are only called from
within llvm-mca so there shouldn’t be any worries about breaking other tools.

Differential Revision: https://reviews.llvm.org/D102709
2021-05-19 18:36:10 +01:00
..
bugpoint Avoid shuffle self-assignment in EXPENSIVE_CHECKS builds 2021-03-10 11:17:34 +00:00
bugpoint-passes Reverted the remainings of c1c9819ef91aab51b5a23fb3027adac5a2f551cc 2020-02-11 16:20:06 -08:00
dsymutil [dsymutil] Add flag to force a static variable to keep its enclosing function 2021-04-28 11:33:04 -07:00
gold [gold] Match lld WPD behavior for shared library symbols and add test 2021-02-17 15:28:49 -08:00
llc Recommit "[VP,Integer,#2] ExpandVectorPredication pass" 2021-05-04 11:47:52 +02:00
lli [lli] Honor the --entry-function flag in orc and orc-lazy modes. 2021-04-13 11:33:24 -07:00
llvm-ar [NFC] Reordering parameters in getFile and getFileOrSTDIN 2021-03-25 09:47:49 -04:00
llvm-as llvmbuildectomy - replace llvm-build by plain cmake 2020-11-13 10:35:24 +01:00
llvm-as-fuzzer Fix several places that were calling verifyFunction or verifyModule without checking the return value. 2020-05-18 13:28:46 -07:00
llvm-bcanalyzer llvmbuildectomy - replace llvm-build by plain cmake 2020-11-13 10:35:24 +01:00
llvm-c-test LLVM-C: Allow LLVM{Get/Set}Alignment on an atomicrmw/cmpxchg instruction. 2021-02-12 18:31:18 -05:00
llvm-cat [tools] Use llvm::append_range (NFC) 2021-01-05 21:15:56 -08:00
llvm-cfi-verify [MC] Untangle MCContext and MCObjectFileInfo 2021-05-05 10:03:02 -07:00
llvm-config [MinGW] Use lib prefix for libraries 2020-09-12 22:01:29 +03:00
llvm-cov [Coverage] Support overriding compilation directory 2021-05-11 15:26:45 -07:00
llvm-cvtres [llvm-cvtres] Reduce the set of dependencies of llvm-cvtres. NFC. 2021-04-21 11:50:10 +03:00
llvm-cxxdump llvmbuildectomy - replace llvm-build by plain cmake 2020-11-13 10:35:24 +01:00
llvm-cxxfilt [demangler] Initial support for the new Rust mangling scheme 2021-05-03 16:44:30 -07:00
llvm-cxxmap [Support] Don't include VirtualFileSystem.h in CommandLine.h 2021-04-21 10:19:01 -04:00
llvm-diff Switch from llvm::is_trivially_copyable to std::is_trivially_copyable 2020-12-02 22:02:48 -08:00
llvm-dis Allow llvm-dis to disassemble multiple files 2021-05-06 11:08:55 -07:00
llvm-dwarfdump [NFC][llvm-dwarfdump] Avoid passing std::string by value in collectStatsForDie() 2021-05-12 01:29:37 -07:00
llvm-dwp [MC] Untangle MCContext and MCObjectFileInfo 2021-05-05 10:03:02 -07:00
llvm-elfabi [llvm-elfabi] Add flag to preserve timestamp when output is the same 2020-12-29 20:27:06 -08:00
llvm-exegesis [MC] Untangle MCContext and MCObjectFileInfo 2021-05-05 10:03:02 -07:00
llvm-extract llvmbuildectomy - replace llvm-build by plain cmake 2020-11-13 10:35:24 +01:00
llvm-go Reinstate llvm-go to test the go bindings. 2020-02-13 17:24:55 -08:00
llvm-gsymutil [tools] Use llvm::append_range (NFC) 2021-01-05 21:15:56 -08:00
llvm-ifs [SystemZ][z/OS] Add IsText Argument to GetFile and GetFileOrSTDIN 2021-04-16 10:08:36 -04:00
llvm-isel-fuzzer [AIX] Turn -fdata-sections on by default in Clang 2020-10-14 15:58:31 +00:00
llvm-itanium-demangle-fuzzer Fix file header issues in fuzzers. NFC 2019-02-21 07:57:14 +00:00
llvm-jitlink [llvm-jitlink] Link libnetwork on Haiku in llvm-jitlink 2021-05-14 20:49:03 -07:00
llvm-jitlistener [MCJIT] Profile the code generated by MCJIT engine using Intel VTune profiler 2020-11-16 19:28:14 +11:00
llvm-libtool-darwin [Support] Don't include VirtualFileSystem.h in CommandLine.h 2021-04-21 10:19:01 -04:00
llvm-link NFC: Run clang-format over llvm-link. 2021-04-28 14:33:00 -07:00
llvm-lipo [TextAPI] move source code files out of subdirectory, NFC 2021-04-05 10:24:42 -07:00
llvm-lto Recommit "[LTO] Use lto::backend for code generation." 2021-02-15 10:05:42 +00:00
llvm-lto2 Don't use $ as suffix for symbol names in ThinLTOBitcodeWriter and other places 2021-03-29 13:03:52 +02:00
llvm-mc [MC] Untangle MCContext and MCObjectFileInfo 2021-05-05 10:03:02 -07:00
llvm-mc-assemble-fuzzer [MC] Untangle MCContext and MCObjectFileInfo 2021-05-05 10:03:02 -07:00
llvm-mc-disassemble-fuzzer Add missing include Host.h in llvm-mc-* fuzzers. NFC. 2020-05-18 02:21:22 +07:00
llvm-mca [MCA] llvm-mca MCTargetStreamer segfault fix 2021-05-19 18:36:10 +01:00
llvm-microsoft-demangle-fuzzer Give microsoftDemangle() an outparam for how many input bytes were consumed. 2020-05-20 16:17:31 -04:00
llvm-ml [MC] Untangle MCContext and MCObjectFileInfo 2021-05-05 10:03:02 -07:00
llvm-modextract llvmbuildectomy - replace llvm-build by plain cmake 2020-11-13 10:35:24 +01:00
llvm-mt llvmbuildectomy - replace llvm-build by plain cmake 2020-11-13 10:35:24 +01:00
llvm-nm [llvm-nm] Support the -V option, print that the tool is compatible with GNU nm 2021-05-13 22:36:25 +03:00
llvm-objcopy [llvm-objcopy] Add support for '--' for delimiting options from input/output files 2021-05-19 01:56:46 -07:00
llvm-objdump Fix lld macho standalone build by including llvm/Config/llvm-config.h instead of llvm/Config/config.h 2021-05-19 11:15:07 -04:00
llvm-opt-fuzzer [NewPM] Hide pass manager debug logging behind -debug-pass-manager-verbose 2021-05-07 21:51:47 -07:00
llvm-opt-report [SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag instead of OF_Text 2021-04-06 07:23:31 -04:00
llvm-pdbutil Removed redundant code. 2021-04-07 05:37:46 +04:00
llvm-profdata [CSSPGO][llvm-profdata] Support trimming cold context when merging profiles 2021-04-22 00:42:37 -07:00
llvm-profgen [MC] Untangle MCContext and MCObjectFileInfo 2021-05-05 10:03:02 -07:00
llvm-rc [llvm-rc] Add a GNU windres-like frontend to llvm-rc 2021-04-26 22:04:29 +03:00
llvm-readobj [AMDGPU] Add gfx1034 target 2021-05-13 14:25:18 -04:00
llvm-reduce [llvm-reduce] Don't unset dso_local on implicitly dso_local GVs 2021-04-30 11:57:22 -07:00
llvm-rtdyld [MC] Untangle MCContext and MCObjectFileInfo 2021-05-05 10:03:02 -07:00
llvm-rust-demangle-fuzzer Add fuzzer for Rust demangler 2021-05-05 12:50:50 -07:00
llvm-shlib [CMake][ELF] Link libLLVM.so and libclang-cpp.so with -Bsymbolic-functions 2021-05-13 13:44:57 -07:00
llvm-size [llvm-cov] Use is_contained (NFC) 2020-12-27 09:57:25 -08:00
llvm-special-case-list-fuzzer Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
llvm-split [LTO] Update splitCodeGen to take a reference to the module. (NFC) 2021-01-29 11:53:11 +00:00
llvm-stress Avoid shuffle self-assignment in EXPENSIVE_CHECKS builds 2021-03-10 11:17:34 +00:00
llvm-strings llvmbuildectomy - replace llvm-build by plain cmake 2020-11-13 10:35:24 +01:00
llvm-symbolizer [llvm-symbolizer] Place Mach-O options into the Mach-O option group. 2021-05-12 12:04:54 +01:00
llvm-undname llvmbuildectomy - replace llvm-build by plain cmake 2020-11-13 10:35:24 +01:00
llvm-xray [SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag instead of OF_Text 2021-04-06 07:23:31 -04:00
llvm-yaml-numeric-parser-fuzzer [llvm] NFC: Cleanup llvm-yaml-numeric-parser-fuzzer 2021-02-15 14:52:53 +01:00
llvm-yaml-parser-fuzzer [llvm] Use llvm::erase_value and llvm::erase_if (NFC) 2021-01-02 09:24:15 -08:00
lto [LTO][Legacy] Decouple option parsing from LTOCodeGenerator 2021-03-31 16:43:26 +00:00
msbuild vs integration: bump version nbr 2019-06-19 07:39:53 +00:00
obj2yaml Reland: "[lld][WebAssembly] Initial support merging string data" 2021-05-10 16:03:38 -07:00
opt [NewPM] Add options to PrintPassInstrumentation 2021-05-18 20:59:35 -07:00
opt-viewer Convert old python3 cgi method into the new html one 2020-03-25 22:38:55 +01:00
remarks-shlib [tools][remarks-shlib] Don't build libRemarks.so without PIC 2020-09-20 12:40:21 +02:00
sancov [MC] Untangle MCContext and MCObjectFileInfo 2021-05-05 10:03:02 -07:00
sanstats [NFC] Reordering parameters in getFile and getFileOrSTDIN 2021-03-25 09:47:49 -04:00
split-file [Support] Don't include VirtualFileSystem.h in CommandLine.h 2021-04-21 10:19:01 -04:00
verify-uselistorder [SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag instead of OF_Text 2021-04-06 07:23:31 -04:00
vfabi-demangle-fuzzer [llvm][VectorUtils] Tweak VFShape for scalable vector functions. 2020-01-30 05:53:56 +00:00
xcode-toolchain
yaml2obj [llvm] Make obj2yaml and yaml2obj LLVM utilities instead of tools 2020-10-19 10:21:21 -07:00
CMakeLists.txt [Flang] add flang as a new subproject in cmake 2020-04-09 16:13:18 +01:00