This was previously present in
https://github.com/bazelbuild/continuous-integration, but the Bazel team
asked us to move it to our repo. It will be helpful if we need to change
the build configuration, eg to add new platforms.
The issue was caused by config.h header being included from both
header files and implementation files.
Proposed solution is to have regular header guard in the generated
config.h. Benefit of this solution is that it's least intrusive.
Downside is that it only solves issue for CMake build system, and
autoconf one is not fixed since header template is automatically
generated by autoheader who does not add header guard.
Glog was missing colored output when running in terminal
who is set to konsole* TERM, even though the terminal
itself supports colored output.
Add extra terminfo to the check function, so now output
from Glog is properly colored.
* added dbghelp symbolizer support for mingw and cygwin
* fixed compiler errors in case <stdint.h> is not available
* cmake: check whether SymFromAddr actually works
This allows to avoid conflicts between third party gflags find modules floating
around. If a package provide a local version of gflags find module, clients
which locate glog will incorrectly use it. Another problem is a CMake error message
"cmake_policy PUSH without matching POP" in nested find_package calls. In summary,
we need to ensure to use the original gflags package config.
This means that gflags no longer leaks config.h, so I had to fix a bug
in glog.bzl where config.h is generated at the wrong path.
I also switched to the best-practice for depending on git repositories,
ie using http_archive with a mirror.
This commit addresses a few issues:
1. No longer leak config.h in a way similar to
https://github.com/gflags/gflags/issues/233
The solution of prefixing the path by 'glog_internal' is modified from
https://github.com/gflags/gflags/issues/234
2. No longer expose internal headers.
3. Replace PACKAGE_NAME with native.package_name()
4. Uers can choose namespaces via the newly added 'namespace' keyword.
5. Replace glob with explicitly listing of files.
6. Make the genrules more compact using pythonic list construction.
We previously had logic to compute the base address from program
headers as part of symbolization. The problem is that we need a correct
base address earlier in order to adjust a PC into the image's address
space, as these addresses can appear in unsymbolized output.
There was previously an assumption that only the mapping that
was lowest in the address space did not need to be adjusted. This
assumption is not guaranteed (for example, the kernel may choose to
map an ET_DYN lowest) and in fact turned out to be wrong in binaries
linked with lld because the first mapping is read-only.
The solution is to move the program header reading logic into the
code that reads /proc/self/maps.
There is a change in semantics for clients that install a callback
using the InstallSymbolizeOpenObjectFileCallback function. Any such
clients will need to return a correct base address from the callback
by reading program headers using code similar to that in the function
OpenObjectFileContainingPcAndGetStartAddress.
Summary:
Issue #80 points out several places in glog where TSAN discovers
false positives. One of these places is in the `LOG_EVERY_N` macros.
These macros are implemented by maintaining a static unprotected
integer counter, and TSAN will report data races on these counters.
Here is a minimum example to reproduce the data race:
```
void logging() {
for (int i = 0; i < 300; ++i) {
LOG_EVERY_N(INFO, 2) << "foo";
}
}
int main() {
auto t1 = std::thread(logging);
auto t2 = std::thread(logging);
t1.join();
t2.join();
return 0;
}
```
And here is the TSAN report:
```
WARNING: ThreadSanitizer: data race (pid=776850)
Write of size 4 at 0x558de483f684 by thread T2:
#0 logging()
#1 void std::_Bind_simple<void (*())()>::_M_invoke<>(std::_Index_tuple<>)
#2 std::_Bind_simple<void (*())()>::operator()()
#3 std:🧵:_Impl<std::_Bind_simple<void (*())()> >::_M_run()
#4 execute_native_thread_routine
Previous write of size 4 at 0x558de483f684 by thread T1:
#0 logging()
#1 void std::_Bind_simple<void (*())()>::_M_invoke<>(std::_Index_tuple<>)
#2 std::_Bind_simple<void (*())()>::operator()()
#3 std:🧵:_Impl<std::_Bind_simple<void (*())()> >::_M_run()
#4 execute_native_thread_routine
Location is global '<null>' at 0x000000000000 (main+0x00000011c684)
Thread T2 (tid=776857, running) created by main thread at:
#0 pthread_create
#1 __gthread_create
#2 std:🧵:_M_start_thread(std::shared_ptr<std:🧵:_Impl_base>, void (*)())
#3 main
Thread T1 (tid=776856, running) created by main thread at:
#0 pthread_create
#1 __gthread_create
#2 std:🧵:_M_start_thread(std::shared_ptr<std:🧵:_Impl_base>, void (*)())
#3 main
SUMMARY: ThreadSanitizer: data race in logging()
```
To avoid noisy TSAN reports and also avoid adding a performance hit, this
change will mark these counters as benign races so that TSAN will not report
them. This change will only have an effect if we are compiling with TSAN;
there are no changes if we are not building with TSAN.
With this change, the above example no longer reports a data race when built
and run with TSAN.