This is an archive of the discontinued LLVM Phabricator instance.

[asan] Ensure we export all the interface when considering the static library.
ClosedPublic

Authored by mpividori on Jan 31 2017, 10:00 AM.

Details

Summary

In Windows, when the sanitizer is implemented as a static library and is included in the main executable, we use auxiliary static library dll_thunk that will be linked to the dlls that have instrumentation, so they can refer to the runtime in the main executable. It uses interception to get a pointer the function in the main executable and override its function with that pointer.

To ensure that the main executable exports all the sanitizers' interface, all object files from the static library should be linked to the main executable, so we need to add the flag -wholearchive to clang driver, when including the static version of asan.

If we don't include -wholearchive , the linker could omit some object files when they don't resolve any symbol for the main executable.

But instrumented dlls will try to access to all the interface exposed by the main executable. If we omit part of it, the initialization in dll_thunk will fail.

Diff Detail

Repository
rL LLVM

Event Timeline

mpividori created this revision.Jan 31 2017, 10:00 AM
rnk accepted this revision.Jan 31 2017, 10:25 AM

lgtm

This revision is now accepted and ready to land.Jan 31 2017, 10:25 AM
This revision was automatically updated to reflect the committed changes.
kcc added a subscriber: kcc.Jan 31 2017, 11:25 AM

does this deserve a test?
What has changed, why did everything work before?

@kcc It worked before because:

  • We were including part of asan's interface in asan_win_dll_thunk.cc.
  • Object files including definition for that part of asan's interface were fortunately included by the linker because they resolve some symbols needed for the main executable.

This could change in the future, for example, suppose this case:

  • The dll includes instrumentation for "some_fun", so it needs to resolve some_fun.
  • some_fun is defined in somefile.cc.
  • somefile.cc.o is included in libasan.lib.
  • Suppose the main executable doesn't need to resolve some_fun(), because it was not included in its instrumentation, and suppose that the object file somefile.cc.o doesn't resolve any other dependency needed by the main executable.

So, in that situation, some_fun() is not included in the main executable, so it is not exported, so the instrumented dll can't find it.

When considering MT, asan is implemented as a static library linked to the main executable and the instrumented dlls need access to that library. So we need to ensure that we export all the sanitizer's interface.

This is checked with the test: interface_symbols_windows.c introduced in https://reviews.llvm.org/D29148

Thanks.