Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4437)

Issue 4867059: AddressSanitizer/LLVM first patch

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 8 months ago by kcc2
Modified:
8 years, 7 months ago
Reviewers:
nlewycky1
Base URL:
http://llvm.org/svn/llvm-project/llvm/trunk/
Visibility:
Public.

Patch Set 1 #

Patch Set 2 : added a test #

Patch Set 3 : added test/Instrumentation/AddressSanitizer/dg.exp #

Total comments: 18

Patch Set 4 : style changes #

Total comments: 18

Patch Set 5 : style changes #

Patch Set 6 : drop the custom assembly, rewrite the loop in handleFunction #

Patch Set 7 : typo #

Patch Set 8 : address comments from eli.friedman and echristo #

Patch Set 9 : simplified code around llvm.global_ctors #

Patch Set 10 : indentaion, hidden non-user-visible flags #

Patch Set 11 : comment change #

Patch Set 12 : added noreturn to __asan_report_error #

Unified diffs Side-by-side diffs Delta from patch set Stats (+554 lines, -0 lines) Patch
M include/llvm/InitializePasses.h View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
M include/llvm/Transforms/Instrumentation.h View 1 2 3 4 5 1 chunk +3 lines, -0 lines 0 comments Download
A lib/Transforms/Instrumentation/AddressSanitizer.cpp View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +531 lines, -0 lines 0 comments Download
M lib/Transforms/Instrumentation/CMakeLists.txt View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
M lib/Transforms/Instrumentation/Instrumentation.cpp View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
A test/Instrumentation/AddressSanitizer/dg.exp View 1 2 1 chunk +3 lines, -0 lines 0 comments Download
A test/Instrumentation/AddressSanitizer/test64.ll View 1 2 3 1 chunk +14 lines, -0 lines 0 comments Download

Messages

Total messages: 5
nlewycky1
Haven't yet reviewed AddressSanitizer.cpp http://codereview.appspot.com/4867059/diff/5001/test/Instrumentation/AddressSanitizer/test64.ll File test/Instrumentation/AddressSanitizer/test64.ll (right): http://codereview.appspot.com/4867059/diff/5001/test/Instrumentation/AddressSanitizer/test64.ll#newcode1 test/Instrumentation/AddressSanitizer/test64.ll:1: ; RUN: opt < %s ...
12 years, 8 months ago (2011-08-18 22:07:22 UTC) #1
nlewycky1
Overall, this looks fine. It won't break anything to land this in google3. http://codereview.appspot.com/4867059/diff/5001/lib/Transforms/Instrumentation/AddressSanitizer.cpp File ...
12 years, 8 months ago (2011-08-18 22:37:10 UTC) #2
kcc2
> > http://codereview.appspot.com/4867059/diff/5001/lib/Transforms/Instrumentation/AddressSanitizer.cpp#newcode486 > lib/Transforms/Instrumentation/AddressSanitizer.cpp:486: MappingOffsetLog = > LongSize == 32 > How about testing ...
12 years, 8 months ago (2011-08-18 23:01:09 UTC) #3
nlewycky1
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentation/AddressSanitizer.cpp File lib/Transforms/Instrumentation/AddressSanitizer.cpp (right): http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentation/AddressSanitizer.cpp#newcode70 lib/Transforms/Instrumentation/AddressSanitizer.cpp:70: #include <stdint.h> Please use #include "llvm/Support/DataTypes.h" instead. http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentation/AddressSanitizer.cpp#newcode71 lib/Transforms/Instrumentation/AddressSanitizer.cpp:71: ...
12 years, 8 months ago (2011-08-22 23:12:11 UTC) #4
kcc2
12 years, 8 months ago (2011-08-23 00:12:19 UTC) #5
On 2011/08/22 23:12:11, nlewycky1 wrote:
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> File lib/Transforms/Instrumentation/AddressSanitizer.cpp (right):
> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:70: #include <stdint.h>
> Please use #include "llvm/Support/DataTypes.h" instead.

done

> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:71: #include <stdio.h>
> Why? What are you using out of this?

removed

> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:128: static const char
> *kAsanModuleCtorName = "asan.module_ctor";
> Being static, this doesn't need to be inside the anonymous namespace.

done


> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:264: if (LoadInst *ld =
> dyn_cast<LoadInst>(inst)) {
> LLVM's common naming would make this:
>   if (LoadInst *LI = dyn_cast<LoadInst>(I)) {

done

> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:303: std::string
> FunctionName = "__asan_report_error_" + itostr(TelltaleValue);
> Why isn't the TelltaleValue just a ConstantInt parameter to a single
> __asan_report_error function?

to save code size a bit. Added a comment.


> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:306: CallInst *call =
> IRB.CreateCall(AsanReportWarning, Addr);
> __asan_report_error always terminates, right? 

Yes, although this may not be true in the future. 

> Then you can add
> "call->setDoesNotReturn();". That should help out codegen a bit.

I tried that with the ud2 code and codegen crashed on one of the CPU2006
benchmarks. 
I'd prefer not to use setDoesNotReturn for now, but will likely want to try it
later (it does save some code size).


> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:358: unsigned
> log_of_size_in_bytes = __builtin_ctz(TypeSize / 8);
> Not all compilers that build LLVM support __builtin_ctz. Please use
> CountTrailingZeros_32 (or _64) from ADT/MathExtras.h.

done


> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:425: index < n; ++index) {
> LLVM always uses "index != n" for loops like this.

done


> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:440: CurrentCtors.size());
> This should line up with the "(R"

done

> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:463: LongTy =
> Type::getIntNTy(*C, LongSize);
> This is intptr_t, right? How about IntPtrTy? It's a little confusing to see
> references to LongTy in pointer casts everywhere.

done

> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:483: assert(LongSize == 32
> || LongSize == 64);
> How about we just "return false;" in this case?


done

> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:496:
> "__asan_mapping_offset");
> What if I hand you a module where this value already exists? Currently, it
will
> create "__asan_mapping_offset2". 

Ouch

> Make sure that your code also doesn't crash if
> you're asked to run on a Module that *has* __asan_mapping_offset, but it has
the
> wrong type. Same with the other __asan_... variables and functions.

Something bad will happen. 
Can we just assert that it won't happen? 
Names with __ prefix are not allowed in user code anyway (afaict)


> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:515: return res;
> The return value should control whether or not a change to the module was
made.
> Of course, this pass always changes the module.
> 
> I have an idea: the per-Function part is entirely parallelizable, so turn this
> from a ModulePass into a FunctionPass, and turn handleFunction into
> runOnFunction. Move F->isDeclaration() into runOnFunction.


I tried making it a FunctionPass and it did not work (sadly, I don't remember
why). 
Can this change go as a separate improvement if really needed? 
In the original file I also insert redzones between globals and this can not be
done by a FunctionPass, right? 

> 
> These other parts which add __asan_... (don't forget __asan_report_error_*)
and
> modify llvm.global_ctors should move into doInitialization(Module &).
> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:529: if
(isa<CallInst>(BI))
> {
> This test is redundant, you just need the dyn_cast below.

done

> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:540: static bool
> blockOrItsSuccHasException(BasicBlock &bb) {
> bb -> BB


done

> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:561: for
(Function::iterator
> FI = F.begin(), FE = F.end();
> I think you can fuse these two loops and remove the InstructionsToInstrument
> set.
> 
> Create "SmallVector<BasicBlock *, 16> Worklist" to use as a queue and only put
> F.getEntryBlock() in it, then enter a "while (!Worklist.empty())" loop which
> inserts the successor BBs into the Worklist before instrumenting all the
> load/store/memintrin instructions. The instrumentation may add new BBs that
you
> don't want to visit, and because you didn't add those BBs to your worklist,
you
> won't.

These two loops are deliberate choice, although it is not evident from the code
and comments. 
I added a comment: 
  // At this point InstructionsToInstrument contains a set of instructions      
                                                                                
                                  
  // that need to be instrumented. However, instrumenting some of them          
                                                                                
                                  
  // might be proved redundant. In future we may add more analysis              
                                                                                
                                  
  // to avoid redundant instrumentation. See                                    
                                                                                
                                  
  // http://code.google.com/p/address-sanitizer/wiki/CompileTimeOptimizations   
             


> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:603: NumInstrumented++;
> I don't think this logic is quite right; this will fire even when no changes
are
> made, causing runOnModule to return true on an unmodified module. Also, why
> isn't it a bool?

NumInstrumented counts how many insns have been instrumented. 
It also enables me to bisect a particular insn that causes a problem if
instrumented (ClDebugMin/Max). 
Btw, does LLVM has a debug API for bisecting? 
W/o the debug flags NumInstrumented is incremented only if something was
instrumented. 


> 
>
http://codereview.appspot.com/4867059/diff/6002/lib/Transforms/Instrumentatio...
> lib/Transforms/Instrumentation/AddressSanitizer.cpp:611: errs() << F;
> There's a dbgs() method you can use, which returns wither a void sync, or
> errs(). It's controlled by whether -debug-pass=asan is enabled (see the
> DEBUG_TYPE macro you set at the top). For that matter, please feel free to
> sprinkle dbgs() << ... around your pass.

done.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b