What is gcc doing here to run this code once per thread?

What is gcc doing here to run this code once per thread?

I just ran across this technique for running code once per thread. I don't know how it works at the lowest level though. Especially, what's fs pointing to? What does .zero 8 mean? Is there a reason the identifier is @tpoff?

I just ran across this technique for running code once per thread. I don't know how it works at the lowest level though. Especially, what's fs pointing to? What does .zero 8 mean? Is there a reason the identifier is @tpoff?

int foo();

void bar() { thread_local static auto _ = foo(); }

Output (with -O2):

bar():
        cmp     BYTE PTR fs:guard variable for bar()::@tpoff, 0
        je      .L8
        ret
.L8:
        sub     rsp, 8
        call    foo()
        mov     BYTE PTR fs:guard variable for bar()::@tpoff, 1
        add     rsp, 8
        ret
guard variable for bar()::_:
        .zero   8


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

Variable Introduction in C#[Bangla]

LIKE | COMMENT | SHARE | SUBSCRIBE A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a speci...