os-wrappers-test: Make syscall intercepts work with sanitizers
authorFergus Dall <sidereal@google.com>
Fri, 9 Jul 2021 14:13:35 +0000 (00:13 +1000)
committerDaniel Stone <daniels@collabora.com>
Thu, 22 Jul 2021 22:27:45 +0000 (22:27 +0000)
commit91d98b622f2942221dfe0d7897801a2b0824b825
tree0a89e18e29ace4ae2ab6c0ae016f104e36542a9f
parente5c3ac9bcd84df0f6bfd8fa1a1f549cab34eb439
os-wrappers-test: Make syscall intercepts work with sanitizers

Sanitizers need to intercept syscalls in the compiler run-time library, as
do these tests. We try to make this work by using dlsym(RTLD_NEXT) to find
the next definition in the chain, but here this approach won't work because
the compiler run-time library is linked into the same elf object as the test
interceptors are.

The sanitizer library supports this by giving the intercept functions a
prefix and making them only weakly alias the real names, so our interceptors
can call the sanitizers interceptors explicitly, which will then use dlsym
to call the real function.

By making our declarations of the sanitizer interceptor function weak we can
handle any combination of intercepts (including none, if there is no
sanitizer). If our declaration is resolves to a NULL pointer, we just use
dlsym.

Signed-off-by: Fergus Dall <sidereal@google.com>
tests/os-wrappers-test.c