Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tst-tls-pie.so: use printf in the init functions
According to the GCC documentation (look at https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html) "the order in which constructors for C++ objects with static storage duration and functions decorated with attribute constructor are invoked is unspecified". This means that for example using std::cout in the function with a constructor attribute is dangerous as the std::cout (global object) may have not been initialized yet (see this bug report for better explanation - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94810). The test tst-tls.cc compiled as PIE includes assertions executed as part of the before_main() function which is annotated with a constructor attribute and gets called before the regular main. The before_main() calls report() function which uses std::cout to print assertion result. This happens to work fine when OSv exports all symbols including the stdc++ ones like std::cout which is initialized by then, but crashes miserably on Linux and OSv with most symbols and stdc++ hidden. This patch fixes the test to make it work correctly in all cases by changing report() function to use std::cout or printf() depending on where in the program lifecycle it is called. Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com> Message-Id: <20220109011732.903007-1-jwkozaczuk@gmail.com>
- Loading branch information