All of lore.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, mingo@kernel.org,
	fengguang.wu@intel.com, torvalds@linux-foundation.org,
	tglx@linutronix.de, peterz@infradead.org,
	linux-tip-commits@vger.kernel.org
Subject: Re: [tip:x86/asm] objtool: Handle GCC stack pointer adjustment bug
Date: Wed, 30 Aug 2017 16:39:42 -0700	[thread overview]
Message-ID: <04d4f019-44a6-e01c-128d-aa31df9dd5dc@zytor.com> (raw)
In-Reply-To: <20170830201413.gx4in2wnz5yypzrc@treble>

On 08/30/17 13:14, Josh Poimboeuf wrote:
> On Wed, Aug 30, 2017 at 12:23:24PM -0700, H. Peter Anvin wrote:
>> On 08/30/17 02:43, tip-bot for Josh Poimboeuf wrote:
>>>
>>> Those warnings are caused by an unusual GCC non-optimization where it
>>> uses an intermediate register to adjust the stack pointer.  It does:
>>>
>>>   lea    0x8(%rsp), %rcx
>>>   ...
>>>   mov    %rcx, %rsp
>>>
>>> Instead of the obvious:
>>>
>>>   add    $0x8, %rsp
>>>
>>> It makes no sense to use an intermediate register, so I opened a GCC bug
>>> to track it:
>>>
>>>   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81813
>>>
>>> But it's not exactly a high-priority bug and it looks like we'll be
>>> stuck with this issue for a while.  So for now we have to track register
>>> values when they're loaded with stack pointer offsets.
>>>
>>
>> This seems like a good reason to try to extract this information from
>> the DWARF data *if available*?
> 
> Well, I haven't ruled that out for the future, but in this case,
> integrating DWARF would be a lot more work than this relatively simple
> patch.
> 
> If we did go that route, it could be tricky deciding when to trust
> DWARF vs. when to trust objtool's reverse engineering.
> 
> Another (vague) idea I'm thinking about is to write a GCC plugin which
> annotates the object files in a way that would help objtool become more
> GCC-ignorant.  If it worked, this approach would be more powerful and
> less error-prone than relying on DWARF.
> 
> Depending on how much work we can offload to the plugin, it might also
> help make it easier to port objtool to other arches and compilers (e.g.,
> clang).
> 
> I'm not 100% sold on that idea either, because it still requires objtool
> to trust the compiler to some extent.  But I think it would be worth it
> because it would make the objtool code simpler, more portable, more
> robust, and easier to maintain (so I don't always have to stay on top of
> all of GCC's latest optimizations).
> 
> In the meantime, objtool's current design is working fine (for now).  I
> haven't found any issues it can't handle (yet).
> 

Reverse engineering this way is at least NP-complete, and quite possibly
undecidable.  A gcc plugin would tie the kernel *way* harder to gcc than
it is now, and it seems incredibly unlikely that you would come up with
something simpler and more reliable than a DWARF parser.  What you *can*
do, of course, is cross-correlate the two, and *way* more importantly,
you cover assembly.

	-hpa

  reply	other threads:[~2017-08-30 23:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-29 17:51 [PATCH] objtool: Handle GCC stack pointer adjustment bug Josh Poimboeuf
2017-08-30  9:43 ` [tip:x86/asm] " tip-bot for Josh Poimboeuf
     [not found]   ` <e6eb6a11-ad65-dccb-2c79-485e58e316a2@zytor.com>
2017-08-30 20:14     ` Josh Poimboeuf
2017-08-30 23:39       ` H. Peter Anvin [this message]
2017-08-31  4:42         ` Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=04d4f019-44a6-e01c-128d-aa31df9dd5dc@zytor.com \
    --to=hpa@zytor.com \
    --cc=arnd@arndb.de \
    --cc=fengguang.wu@intel.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.