Thread (18 messages) 18 messages, 7 authors, 2020-11-20

Re: violating function pointer signature

From: Segher Boessenkool <hidden>
Date: 2020-11-18 19:20:35
Also in: bpf, linux-toolchains, lkml

Possibly related (same subject, not in this thread)

On Wed, Nov 18, 2020 at 01:58:23PM -0500, Steven Rostedt wrote:
I wonder if we should define on all architectures a void void_stub(void),
in assembly, that just does a return, an not worry about gcc messing up the
creation of the stub function.

On x86_64:

GLOBAL(void_stub)
	retq


And so on.
I don't see how you imagine a compiler to mess this up?

void void_stub(void) { }

will do fine?

        .globl  void_stub
        .type   void_stub, @function
void_stub:
.LFB0:
        .cfi_startproc
        ret
        .cfi_endproc
.LFE0:
        .size   void_stub, .-void_stub


Calling this via a different declared function type is undefined
behaviour, but that is independent of how the function is *defined*.
Your program can make ducks appear from your nose even if that function
is never called, if you do that.  Just don't do UB, not even once!


Segher
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help