Why gcc uses jmp to call a function in an optimized version

When I parsed my program, I saw that gcc used jmp for the second call to pthread_wait_barrier when compiling with -O3. Why is this so?

What advantage is achieved using jmp instead of calling . What tricks does the compiler play here? I assume that its execution of tail call optimization is here.

By the way, I am using a static link here.

__attribute__ ((noinline)) void my_pthread_barrier_wait( 
    volatile int tid, pthread_barrier_t *pbar ) 
{
    pthread_barrier_wait( pbar );
    if ( tid == 0 )
    {
        if ( !rollbacked )
        {
            take_checkpoint_or_rollback( ++iter == 4 );
        }
    }
    //getcontext( &context[tid] );
    SETJMP( tid );
    asm("addr2jmp:"); 
    pthread_barrier_wait( pbar );
    // My suspicion was right, gcc was performing tail call optimization, 
    // which was messing up with my SETJMP/LONGJMP implementation, so here I
    // put a dummy function to avoid that.
    dummy_var = dummy_func();
}
+5
source share
5 answers

, : , ,

return func2(...)

(void).

"" "" , "", "" .

+12

, . GCC , .

? extern, , GCC ABI ( , ).

, jmp.

(.. PLT )

+6

jmp , . jmp ,

+2

, , unmodified, ( , void) . call.

call . -, . . ret .

, . , , , GCC , , . , , .

+2

, "" ( , ).

Inlining , , , L1 .

JMP - . , JMP ( )! 1-2 , - , , . , , , .
, .

-1

All Articles