This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] More dead code removal
ClosedPublic

Authored by cryptoad on Apr 19 2018, 2:55 PM.

Details

Summary

The following functions are only used in tests: SetEnv,
SanitizerSetThreadName, SanitizerGetThreadName. I don't think they are
going to be used in the future, and I propose to get rid of them, and associated
tests and include.

Diff Detail

Event Timeline

cryptoad created this revision.Apr 19 2018, 2:55 PM
Herald added subscribers: Restricted Project, delcypher, kubamracek. · View Herald TranscriptApr 19 2018, 2:55 PM
vitalybuka added inline comments.
lib/sanitizer_common/sanitizer_common.h
272

this one is used by external code, check __sanitizer::SetEnv google3

cryptoad updated this revision to Diff 143171.Apr 19 2018, 3:08 PM

Readding SetEnv.

cryptoad marked an inline comment as done.Apr 19 2018, 3:09 PM
vitalybuka accepted this revision.Apr 19 2018, 4:08 PM
This revision is now accepted and ready to land.Apr 19 2018, 4:08 PM

I am not following. Isn't it a test for prctl interceptor? Why are we removing useful tests?
Perhaps it's not the most critical functionality. And perhaps SanitizerSetThreadName needs to be moved to the test itself. But still it's a test.

I am not following. Isn't it a test for prctl interceptor? Why are we removing useful tests?
Perhaps it's not the most critical functionality. And perhaps SanitizerSetThreadName needs to be moved to the test itself. But still it's a test.

Here is my understanding, please let me know if I am wrong:

  • Unless mistaken, sanitizer_common_test.cc doesn't involve interceptors, just the tests for the common functions.
  • Sanitizer{S,G}etThreadName use prctl and not internal_prctl which might cause problems if they were to be used with interceptors.
  • The test removed only tests that actual prctl PR_{G,S}ET_NAME behaves somewhat appropriately, which is probably not that useful.

I tried to verify all this and ran the test manually with a breakpoint on libc's prctl:

[ RUN      ] SanitizerCommon.SanitizerSetThreadName

Breakpoint 1, 0x00007ffff6c592c0 in prctl () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ffff6c592c0 in prctl () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x000000000054fbd7 in __sanitizer::SanitizerSetThreadName(char const*) () at sanitizer_linux_libcdep.cc:167
#2  0x0000000000495db4 in TestBody () at sanitizer_common_test.cc:100

I think TryToSetThreadName in asan_test.cc leverages an intercepted prctl for this purpose.

Tests are not linked with interceptors?

Tests are not linked with interceptors?

I didn't find anything that suggested that this particular one was, but someone else can probably chime in on that.
sanitizer::SanitizerSetThreadName is present in other binaries (Asan-x86-64-calls-Tests for example) and calls interceptor_prctl there, but is not called by anything.

Tests are not linked with interceptors?

I didn't find anything that suggested that this particular one was, but someone else can probably chime in on that.
sanitizer::SanitizerSetThreadName is present in other binaries (Asan-x86-64-calls-Tests for example) and calls interceptor_prctl there, but is not called by anything.

Humm... should this test go into Asan-x86-64-calls-Tests then?

asan_test.cc leverages an intercepted prctl with the ThreadedTestFunc test which calls:

static bool TryToSetThreadName(const char *name) {
#if defined(__linux__) && defined(PR_SET_NAME)
  return 0 == prctl(PR_SET_NAME, (unsigned long)name, 0, 0, 0);
#else
  return false;
#endif
}

and checks the names to be right in the death message.

Then I don't understand what happens here anymore. Go and drop it.

This revision was automatically updated to reflect the committed changes.