-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add annotation support #572
Comments
From [email protected] on September 21, 2011 14:07:05 We talked briefly about seeing if there was some way to use DWARF to create annotations, but I think that generally in the compiler backend debug info is considered "nice to have" and is easily thrown away with optimizations. Therefore, I'd be worried about the effectiveness of any metadata or DWARF based annotation solution. An alternative is the gcc labels-as-values extension which is kind of interesting: http://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html This allows you to get the actual runtime address of the label as a value in the code, so you can say "goto *my_labels_array[i]" and it will emit an indirect jump within the function. Linux has this interesting BUG() macro that uses the address of the label to do a lookup of the current PC, and then print the source line number. That was originally introduced to save space in the kernel image by not creating so many concatenated func:line strings. The reason I mention it is that getting labels-as-values right is a correctness issue for the compiler, and so therefore it is more likely to be lowered properly than debug information annotations. Unfortunately, I can't think of a way to get the label value out of the function using a macro that compiles down to nothing at runtime. Furthermore, just introducing a label and taking its address may affect the optimizers in unanticipated ways, even if there is no indirect goto in the function. Finally, this doesn't work for Visual Studio, which is a big deal for us. I think any reasonable solution will have to introduce some kind of code that gets executed at runtime, because otherwise the optimizers have no notion of a "program point" and they will want to schedule loads and stores across the annotation. We need some kind of barrier (function call or inline asm) to prevent that. I think a call to a function passing the annotation parameters as args is probably the cleanest, most portable, and most likely to work over time as compilers change. If we want to have binary compatibility, we can insert the magic Valgrind asm in those functions. |
From [email protected] on December 06, 2011 12:10:53 pasting in my notes about dead code. the most promising is the conditional branch idea which while it has a memref at least it's to the same location across all annotations. ** TODO issue #572: faster annotations: jmp over data there are several proposals for how to implement annotations, including if we only need source compatibility for issue #283 we are free to use our I'm leaning toward using dead code to minimize the perf impact to the at least one annotation, to flush code b/c it has changed, is relevant to whatever design is chosen it should be able to support at the source level not sure annotations are common enough to need optimizing, even if put full my idea: insert into app a jmp over say 5 bytes: a 4-byte magic word and a
*** TODO optimized away as dead code
skip_writecr: goes away w/ /O2, and pragma must be outside function but don't want to if I put that inside its own function, I can't get it inlined w/o also docs for __writecr0 say "only avail in kernel mode": same with __writemsr: using rdtscp, though didn't try opt here, and rdtscp is not avail on VS2005: **** TODO inline asm is not optimized away one soln where have inline asm: create jmp w/ raw bytes. most likely no gcc even at -O3 leaves asm dead code alone: tool has to remember next target when sees jmp, since easier to evaluate **** TODO conditional branch works this stays in cl64 /O2 but has mem ref and conditional branch:
skip_writecr: but, for the vassert usage, why would anyone bother w/ this when can impl a **** TODO could use syzygy to change to direct jmp if design them right so annotation interface won't change could do inline but what about cross-tool-compatible annotations? if that's only important where are params? can do push idea if wrap malloc: but wrapping malloc *** TODO how get parameters easier to get params w/ jmp-dead-code if execute the dead code: else have might there in fact be branches if have ?: operator or sthg? the inline asm puts the params into registers, and then the DR extension can use locals: yes will cost extra stack slots but that's not a big deal. any chance executing the dead code will mess up app stack? *** TODO alternate idea: store address into global array have global array of ignore-if-leaked *** TODO alternate idea: extra push or sthg to malloc call if annotation macro for leak wraps malloc call, could have it change call |
From [email protected] on June 17, 2014 11:22:41 should we add "configure_DynamoRIO_annotations(target)"? |
From [email protected] on August 29, 2011 16:08:53
there are several proposals for how to implement annotations, including empty function calls (as done in tsan) and special instr sequences (as in valgrind).
if we only need source compatibility for issue #283 we are free to use our own implementation.
I'm leaning toward using dead code to minimize the perf impact to the application: essentially "jmp foo; annotation code; foo:".
I have a bunch of design notes on aspects of this and complications w/ lack of inline asm in cl64 but alternatives involving intrinsics and tricks to avoid dead code removal.
at least one annotation, to flush code b/c it has changed, is relevant to DR: so perhaps DR (or an Extension) should provide an annotation infrastructure and expose it as an event-driven API.
whatever design is chosen it should be able to support at the source level the annotations of other tools ( issue #283 ) which isn't too much of a constraint but does rule out certain implementations I was considering
Original issue: http://code.google.com/p/drmemory/issues/detail?id=572
The text was updated successfully, but these errors were encountered: