How to get invariant thread-stack address for GCC compiled executable?

40 views Asked by At

My question is based on this tiny stkaddr.cpp program:

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("&argc = %p\n", &argc);
}

Using Visual Studio 2019, I know that I can use linker option /DYNAMICBASE:NO to have invariant(constant) local variable address across each run. May be we call it "no ASLR".

VC2019 no ASLR compile and run

With /DYNAMICBASE:NO, each run of the exe we see the same address for &argc.

Then I'd like to ask how can I achieve this for a gcc compiled Linux program.

On Ubuntu Linux 20.04, with gcc 9.4.0, I tried -no-pie, but no effect.

GCC variant local var address.

0

There are 0 answers