If XFLAT can share global variables between modules then how standard shared variables like errno, stderr, optarg, etc. handled by XFLAT?
As described above and elsewhere, the global variables cannot be shared between your program code and shared libraries. Instead, the xflat-gcc tool inserts calls to data accessor functions to manage access to global variables across such module boundaries: When you reference such a global variable, you don’t actually reference the variable, you actually call a function that returns a pointer to the variable that gets dereferenced to access the variable. See the discussion below for more detail.