Commit Message

Hi!
The Linux kernel started (recently?) using -mfentry -p on x86_64/i686?
for some instrumentation, I believe they normally overwrite the -mfentry
prologues with nops and only when some function needs to be instrumented,
overwrite it with some call or jump.
The problem in this PR is that var-tracking notes that are meant to
live on the very first insn in the function (info about fn arguments and the
like) no longer do so, they all start after the profile prologue, so when
*gdb/systemtap or similar debug info consumer inspects debug info at the
beginning of the function, it thinks the arguments are optimized away.
This patch attempts to extend those ranges over the profiler snippet before
prologue on some targets. I'm not doing it everywhere, because some targets
emit some assembly in their targetm.asm_out.function_prologue hook
even for HAVE_prologue, and it is likely the profiler hook isn't prepared
to handle it (think about e.g. ia64 or a few other targets).
Also, sometimes the profiler code might e.g. use push/pop in it and
invalidate potential sp based locations, either we could stop doing this
if cfun->returns_struct or cfun->static_chain_decl, but Alex argued
that it isn't any different from inline asm which uses push/pop inside of
it. The debug info there is also correct only on the first insn in the
inline asm and right after the inline asm, not necessary inside of it,
and similarly with this patch it isn't necessarily right inside of the
profiler snippet (the kernel won't care, as it overwrites the snippet
with nops or call/jmp).
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2013-01-31 Jakub Jelinek <jakub@redhat.com>
PR debug/54793
* final.c (need_profile_function): New variable.
(final_start_function): Drop ATTRIBUTE_UNUSED from first argument.
If first of NOTE_INSN_BASIC_BLOCK or NOTE_INSN_FUNCTION_BEG
is only preceeded by NOTE_INSN_VAR_LOCATION or NOTE_INSN_DELETED
notes, targetm.asm_out.function_prologue doesn't emit anything,
HAVE_prologue and profiler should be emitted before prologue,
set need_profile_function instead of emitting it.
(final_scan_insn): If need_profile_function, emit
profile_function on the first NOTE_INSN_BASIC_BLOCK or
NOTE_INSN_FUNCTION_BEG note.
Jakub