The following compiler flags seems to produce desired result: -fPIE -pie -Wl,-pie
-fPIE -pie -Wl,-pie
https://compiler-explorer.com/z/xvenTGG7c
Thanks to all commenters for giving me hints on how to approach this.