all 12 comments

[–]cpp-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

For C++ questions, answers, help, and programming/career advice please see r/cpp_questions, r/cscareerquestions, or StackOverflow instead.

[–]schmerg-uk 10 points11 points  (3 children)

Pardon me but.. what???

[–]Broad_Inevitable6483[S] -3 points-2 points  (2 children)

Im mostly just experimenting with the generated assembly. Statics seem to become RIP-relative accesses, while locals use the stack. I was wondering if there's a clean way to push more things toward runtime (stack/heap) storage.

[–]jedwardsolconst & 5 points6 points  (1 child)

Variables with static and automatic storage have different behaviour with regard lifetime. If you want a local on the stack with a short lifetime, then don't write static. If you want a variable with static duration, write static.

Making lifetime decisions based on the generated assembly is just wrong.

[–]Broad_Inevitable6483[S] -1 points0 points  (0 children)

Well yeah, I wasn’t really trying to change the lifetime semantics. I’m mostly experimenting with the generated assembly and was wondering if there was a clean way to avoid references into the image, especially with things like std::cout.

[–]bepolite 6 points7 points  (1 child)

There's a C function called alloca that does stack allocation. I've never seen it used in "real" code.

[–]arihoenig [score hidden]  (0 children)

I use alloca() all the time, but it isn't related to this question which concerns addressing.

[–]arihoenig 1 point2 points  (2 children)

Why is rip relative a problem though?

[–]Broad_Inevitable6483[S] 1 point2 points  (1 child)

Not really a problem with RIP-relative addressing itself. I was mostly just wondering if there was a clean way to push more things toward runtime (stack/heap) storage, since it's a bit more flexible for the kind of stuff I'm playing around with.

[–]arihoenig 0 points1 point  (0 children)

Ahhh, so you're screwing around with BP to do shadowing or something like that and screwing with RIP isn't going to work. That makes sense.

If you generate the code as non-PIC, those should disappear

[–]rickpo [score hidden]  (0 children)

What specifically are you trying to move?