All of lore.kernel.org
 help / color / mirror / Atom feed
* objtool warning in cfg80211_edmg_chandef_valid() with ThinLTO
@ 2021-08-24 20:08 Nathan Chancellor
  2021-08-24 21:05 ` Peter Zijlstra
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Chancellor @ 2021-08-24 20:08 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra
  Cc: Nick Desaulniers, Sami Tolvanen, Kees Cook, clang-built-linux,
	llvm, linux-kernel

Hi Josh and Peter,

An in-review LLVM patch [1] introduces an optimization around switch 
cases, marking the default case unreachable when all known values are 
covered. This ended up introducing a boot regression when building a 
kernel with ThinLTO, which Sami reported initially [2] and I reported it 
upstream, generating some discussion starting from [3].

There is an objtool warning about the function that the author of the 
patch tracked down to be problematic:

vmlinux.o: warning: objtool: cfg80211_edmg_chandef_valid()+0x169: can't 
find jump dest instruction at .text.cfg80211_edmg_chandef_valid+0x17b

The LLVM developers are under the impression that this is an issue with 
objtool; specifically quoting Eli Friedman:

"The backend can, in general, create basic blocks that don't contain any 
instructions, and don't fall through to another block. A jump table 
entry can refer to such a block. I guess certain tools could be confused 
by this.

If that's the issue, it should be possible to work around it using 
'-mllvm -trap-unreachable'."

I can confirm that adding '-mllvm -trap-unreachable' to 
KBUILD_{C,LD}FLAGS does resolve the issue but I am curious if that is an 
adequate solution (as Nick has frowned upon the presence of '-mllvm' 
flags) or if there is something that could be done on the objtool side. 
I do have a small reproducer on Phabricator [4] and I can provide any 
binary files that would be helpful for seeing what is going on here.

[1] https://reviews.llvm.org/D106056
[2] https://github.com/ClangBuiltLinux/linux/issues/1440
[3] https://reviews.llvm.org/D106056#2953104
[4] https://reviews.llvm.org/D106056#2961136

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: objtool warning in cfg80211_edmg_chandef_valid() with ThinLTO
  2021-08-24 20:08 objtool warning in cfg80211_edmg_chandef_valid() with ThinLTO Nathan Chancellor
@ 2021-08-24 21:05 ` Peter Zijlstra
  2021-08-24 21:19   ` Nathan Chancellor
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2021-08-24 21:05 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Josh Poimboeuf, Nick Desaulniers, Sami Tolvanen, Kees Cook,
	clang-built-linux, llvm, linux-kernel

On Tue, Aug 24, 2021 at 01:08:58PM -0700, Nathan Chancellor wrote:

> The LLVM developers are under the impression that this is an issue with
> objtool; specifically quoting Eli Friedman:
> 
> "The backend can, in general, create basic blocks that don't contain any
> instructions, and don't fall through to another block. A jump table entry
> can refer to such a block. I guess certain tools could be confused by this.
> 
> If that's the issue, it should be possible to work around it using '-mllvm
> -trap-unreachable'."

So jump-tables are a weak point; ARM64 was having worse problems than
x86 there, they can't even locate them.

As to having a jump-table entry to an empty block and not falling
through; how are we supposed to know? Emitting them is a waste of space,
so I'd say it's a compiler bug :-))

It's been brought up before; but perhaps we should look at an 'informal'
ABI for jump-tables ?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: objtool warning in cfg80211_edmg_chandef_valid() with ThinLTO
  2021-08-24 21:05 ` Peter Zijlstra
@ 2021-08-24 21:19   ` Nathan Chancellor
  2021-08-25  5:30     ` Josh Poimboeuf
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Chancellor @ 2021-08-24 21:19 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Josh Poimboeuf, Nick Desaulniers, Sami Tolvanen, Kees Cook,
	clang-built-linux, llvm, linux-kernel

On 8/24/2021 2:05 PM, Peter Zijlstra wrote:
> On Tue, Aug 24, 2021 at 01:08:58PM -0700, Nathan Chancellor wrote:
> 
>> The LLVM developers are under the impression that this is an issue with
>> objtool; specifically quoting Eli Friedman:
>>
>> "The backend can, in general, create basic blocks that don't contain any
>> instructions, and don't fall through to another block. A jump table entry
>> can refer to such a block. I guess certain tools could be confused by this.
>>
>> If that's the issue, it should be possible to work around it using '-mllvm
>> -trap-unreachable'."
> 
> So jump-tables are a weak point; ARM64 was having worse problems than
> x86 there, they can't even locate them.
> 
> As to having a jump-table entry to an empty block and not falling
> through; how are we supposed to know?

Fair enough. It does make me wonder why LLVM does that.

> Emitting them is a waste of space, so I'd say it's a compiler bug :-))

Isn't it always? :)

Turns out Nick brought up an issue very similar to this (unreachable 
conditions with switches) on LLVM's issue tracker 
(https://bugs.llvm.org/show_bug.cgi?id=50080) with the same workaround 
suggestion ('-mllvm -trap-unreachable') and there was no follow up after 
that so maybe that is one thing to look into once Nick is back online.

> It's been brought up before; but perhaps we should look at an 'informal'
> ABI for jump-tables ?
Not a bad idea, especially if this has come up before.

Cheers,
Nathan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: objtool warning in cfg80211_edmg_chandef_valid() with ThinLTO
  2021-08-24 21:19   ` Nathan Chancellor
@ 2021-08-25  5:30     ` Josh Poimboeuf
  0 siblings, 0 replies; 4+ messages in thread
From: Josh Poimboeuf @ 2021-08-25  5:30 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Peter Zijlstra, Nick Desaulniers, Sami Tolvanen, Kees Cook,
	clang-built-linux, llvm, linux-kernel

On Tue, Aug 24, 2021 at 02:19:07PM -0700, Nathan Chancellor wrote:
> On 8/24/2021 2:05 PM, Peter Zijlstra wrote:
> > On Tue, Aug 24, 2021 at 01:08:58PM -0700, Nathan Chancellor wrote:
> > 
> > > The LLVM developers are under the impression that this is an issue with
> > > objtool; specifically quoting Eli Friedman:
> > > 
> > > "The backend can, in general, create basic blocks that don't contain any
> > > instructions, and don't fall through to another block. A jump table entry
> > > can refer to such a block. I guess certain tools could be confused by this.
> > > 
> > > If that's the issue, it should be possible to work around it using '-mllvm
> > > -trap-unreachable'."
> > 
> > So jump-tables are a weak point; ARM64 was having worse problems than
> > x86 there, they can't even locate them.
> > 
> > As to having a jump-table entry to an empty block and not falling
> > through; how are we supposed to know?
> 
> Fair enough. It does make me wonder why LLVM does that.
> 
> > Emitting them is a waste of space, so I'd say it's a compiler bug :-))
> 
> Isn't it always? :)
> 
> Turns out Nick brought up an issue very similar to this (unreachable
> conditions with switches) on LLVM's issue tracker
> (https://bugs.llvm.org/show_bug.cgi?id=50080) with the same workaround
> suggestion ('-mllvm -trap-unreachable') and there was no follow up after
> that so maybe that is one thing to look into once Nick is back online.
> 
> > It's been brought up before; but perhaps we should look at an 'informal'
> > ABI for jump-tables ?
> Not a bad idea, especially if this has come up before.

This is definitely needed.  Jump tables have always been a major thorn
in objtool's side.  I think I volunteered to write up a proposal for the
linux-toolchains list but I've just been waaay too busy.

-- 
Josh


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-25  5:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24 20:08 objtool warning in cfg80211_edmg_chandef_valid() with ThinLTO Nathan Chancellor
2021-08-24 21:05 ` Peter Zijlstra
2021-08-24 21:19   ` Nathan Chancellor
2021-08-25  5:30     ` Josh Poimboeuf

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.