ubsan: Allow programs to use setenv to configure ubsan_standalone.
authorPeter Collingbourne <peter@pcc.me.uk>
Thu, 9 Nov 2017 02:22:07 +0000 (02:22 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Thu, 9 Nov 2017 02:22:07 +0000 (02:22 +0000)
commitc6721f580df11bb0bd00217a45430d163770a278
treedb4d0feddd152b302ad4079c6049f5820728ab10
parente1d121d71579b2c855d80057833ceb74849b3053
ubsan: Allow programs to use setenv to configure ubsan_standalone.

Previously ubsan_standalone used the GetEnv function to read the
environment variables UBSAN_OPTIONS and UBSAN_SYMBOLIZER_PATH. The
problem with GetEnv is that it does not respect changes to the
environment variables made using the libc setenv function, which
prevents clients from setting environment variables to configure
ubsan before loading ubsan-instrumented libraries.

The reason why we have GetEnv is that some runtimes need to read
environment variables while they initialize using .preinit_array,
and getenv does not work while .preinit_array functions are being
called. However, it is unnecessary for ubsan_standalone to initialize
that early. So this change switches ubsan_standalone to using getenv
and removes the .preinit_array entry. The static version of the runtime
still ends up being initialized using a C++ constructor that exists
to support the shared runtime.

Differential Revision: https://reviews.llvm.org/D39827

llvm-svn: 317757
compiler-rt/lib/ubsan/CMakeLists.txt
compiler-rt/lib/ubsan/ubsan_flags.cc
compiler-rt/lib/ubsan/ubsan_init_standalone_preinit.cc [deleted file]