Created MCTargetOptions structure which affects instrumentation of inline assembly. Currently MCTargetOptions contains only type of assembly instrumentation (address for now) and is exposed to target asm parsers.
Diff Detail
Event Timeline
Unfortunately "-fsanitize=*" flag is not exposed to MCTargetAsmParser. Currently investigating how to do that...
Blacklist needs to live somewhere with a longer lifetime.
Also, we need a "more global" place anyway to pass down -fsanitize=(address|memory|thread) setting for top-level assembly.
I suggest looking at EmitAssemblyHelper::CreateTargetMachine() in clang.
We could add a field (or several fields) to llvm::TargetOptions to pass through the sanitizer to run (if any) and, potentially, all the information that is currently passes through *SanitizerPass constructor arguments, like blacklist pass, MSanTrackOrigins, etc.
MCCodeGenInfo also looks like a good place for blacklist to live in.
/// CodeGenInfo - Low level target information such as relocation model. /// Non-const to allow resetting optimization level per-function.
lib/Target/X86/AsmParser/X86AsmInstrumentation.cpp | ||
---|---|---|
34 | This would enable not yet well tested asm instrumentation by default. I think it's better to keep the flag name positive, and off by default (for now). | |
lib/Target/X86/AsmParser/X86AsmParser.cpp | ||
723 | This would read and parse the blacklist anew for every machine function. The whole AsmParser is created from scratch for every inline asm instruction, so it's not a good owner for the blacklist. |
- Updating D3106: MachineFunction is exposed to X86AsmParser. #
- Enter a brief description of the changes included in this update.
- The first line is used as subject, next lines as comment. #
- If you intended to create a new revision, use:
- $ arc diff --create
Fixes.
- Updating D3106: MachineFunction is exposed to X86AsmParser. #
- Enter a brief description of the changes included in this update.
- The first line is used as subject, next lines as comment. #
- If you intended to create a new revision, use:
- $ arc diff --create
Added const attribute to STI.
- Updating D3106: MachineFunction is exposed to X86AsmParser. #
- Enter a brief description of the changes included in this update.
- The first line is used as subject, next lines as comment. #
- If you intended to create a new revision, use:
- $ arc diff --create
s/blacklist/blacklisted/
include/llvm/MC/MCTargetOptions.h | ||
---|---|---|
18 | SanitizeAddress I still think that bitfields work better here, even though there may be incompatible instrumentation modes. | |
24 | s/sed/set/ | |
31 | Where is the definition of this constructor? What happens to MCTargetOptions without the corresponding clang patch. They should default to no instrumentation. | |
include/llvm/Target/TargetMachine.h | ||
111 | Why? Options is a public member. |
Investigating why compilation of llvm-c-test fails.
include/llvm/MC/MCTargetOptions.h | ||
---|---|---|
18 | Done. | |
24 | Done. | |
31 | Sorry, I forget to upload a source file. Fixed. | |
include/llvm/Target/TargetMachine.h | ||
111 | Done. | |
lib/Target/X86/AsmParser/X86AsmInstrumentation.h | ||
32 | Deleted, thanks. This class don't have an internal state now, so it's ok to omit void copy ctor and copy operator. |
lib/MC/MCContext.cpp | ||
---|---|---|
13 ↗ | (On Diff #8310) | Please move it back. |
386 ↗ | (On Diff #8310) | Looks like we need a setter method to support -fsanitize-backlist= in clang. |
So, this change now does 2 things:
- adds SanitizeAddress flag to TargetOptions (wrapped in MCTargetOptions)
- passes current MachineFunction to X86AsmInstrumentation
This effectively lets us take into account sanitize_address function attribute when instrumenting inline asm.
This also lets us apply blacklist when instrumenting .s files by runnning SpecialCaseList in cc1as and setting the bit in TargetOptions. That would be done in a future patch.
This patch looks OK to me.
Does anyone have any objections to the TargetOptions/MCTargetAsmParser changes?
include/llvm/MC/MCTargetAsmParser.h | ||
---|---|---|
102 | Can this go on the asm streamer? | |
include/llvm/MC/MCTargetOptions.h | ||
16 | Do you expect this class to grow? Why have a class with only one field? | |
lib/MC/MCTargetOptions.cpp | ||
21 ↗ | (On Diff #8574) | We normally don't want to have command line options showing up in a binary just because it it links with MC. Can this be added to just llc and llvm-mc? Maybe add the option to CommandFlags.h or create another similar file for MC? |
Rafael, Eugene, could you please take another look?
include/llvm/MC/MCTargetOptions.h | ||
---|---|---|
16 | Yes, we're expecting that this class will grow. For instance, for memory sanitizer there will be additional bit about whether we need to track origins or not. Another reason is that in tools like llvm-mc this class is initialized independently from other TargetOptions's options. | |
lib/MC/MCTargetOptions.cpp | ||
21 ↗ | (On Diff #8574) | Done, I've created a separate header with flag and function for initialization from command line. |
include/llvm/MC/MCTargetAsmParser.h | ||
---|---|---|
102 | The class small and would be easy to copy. The existence of the onMCTargetOptionSet also suggests value semantics, don't you want to store just a "MCTargetOptions MCOptions"? | |
122 | This can be private. Even better, can't you also just remove setMCTargetOptions method completely and add an argument to createMCAsmParser? |
The phabricator login doesn't seem to be working, so I will just put
the comments on the email.
setMCTargetOptions is now unused, please delete it.
onMCTargetOptionsSet is also unused, please delete it.
AsmPrinterInlineAsm.cpp:147 is now just a white space change now.
/// Current MCTargetOptions.
MCTargetOptions MCOptions;
Without a set method the comment is out of date.
Nit: maybe even better than a copy would be a const reference if that
is possible.
LGTM with that.
Can this go on the asm streamer?