This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Fix warnings in interception code
ClosedPublic

Authored by etienneb on Jul 25 2016, 8:20 AM.

Details

Summary

This patch is re-introducing the code to fix the
dynamic hooking on windows and to fix a compiler
warning on Apple.

Related patches:

Both architecture are using different techniques to
hook on library functions (memchr, strcpy,...).

On Apple, the function is not dynamically hooked and
the symbol always points to a valid function
(i.e. can't be null). The REAL macro returns the
symbol.

On windows, the function is dynamically patch and the
REAL(...) function may or may not be null. It depend
on whether or not the function was hooked correctly.
Also, on windows memcpy and memmove are the same.

#if !defined(__APPLE__)
[...]
# define REAL(x) __interception::PTR_TO_REAL(x)
# define ASSIGN_REAL(dst, src) REAL(dst) = REAL(src)
[...]
#else  // __APPLE__
[...]
# define REAL(x) x
# define ASSIGN_REAL(x, y)
[...]
#endif  // __APPLE__

Diff Detail

Event Timeline

etienneb updated this revision to Diff 65347.Jul 25 2016, 8:20 AM
etienneb retitled this revision from to [compiler-rt] Fix warnings in interception code.
etienneb updated this object.
etienneb added a reviewer: rnk.
etienneb added subscribers: chrisha, bruno, llvm-commits.
hans added a subscriber: hans.Jul 25 2016, 9:20 AM

I tried this out on my mac, and the tests passed fine.

etienneb added a comment.EditedJul 25 2016, 9:22 AM

Tried on windows 32/64 (check-asan). Tests are fine too.

-- Testing: 532 tests, 16 threads --
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
Testing Time: 99.99s
  Expected Passes    : 366
  Passes With Retry  : 2
  Expected Failures  : 18
  Unsupported Tests  : 146
-- Testing: 534 tests, 16 threads --
Testing: 0 .. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
Testing Time: 94.54s
  Expected Passes    : 370
  Expected Failures  : 18
  Unsupported Tests  : 146

Tests are fine on linux too:

Testing Time: 84.96s
  Expected Passes    : 1369
  Expected Failures  : 12
  Unsupported Tests  : 415

Gonna test the patch now, get back to you soon!

The tests also pass fine here as well. I still see 3 warnings:

warning: address of function 'memchr' will always evaluate to 'true' [-Wpointer-bool-conversion]

But are you not intending to fix those in this patch, are you?

The tests also pass fine here as well. I still see 3 warnings:

warning: address of function 'memchr' will always evaluate to 'true' [-Wpointer-bool-conversion]

But are you not intending to fix those in this patch, are you?

Yes. It supposed to be fixed.

I think this is the mistake:

#ifdef SANITIZER_WINDOWS   -->  #if SANITIZER_WINDOWS
etienneb updated this revision to Diff 65394.Jul 25 2016, 11:48 AM

fix ifdef

WFM now!

Wouhou.
Thanks for testing.

kcc added a subscriber: kcc.Jul 25 2016, 7:29 PM

please remember to *NOT* use #ifdef if if() is an alternative.
If you can only use #ifdef, think again.

rnk edited edge metadata.Jul 26 2016, 5:21 PM
In D22758#495682, @kcc wrote:

please remember to *NOT* use #ifdef if if() is an alternative.
If you can only use #ifdef, think again.

We either have to use ifdef in this case or some other contortion to avoid a warning about the address of a function never being null.

In D22758#496945, @rnk wrote:
In D22758#495682, @kcc wrote:

please remember to *NOT* use #ifdef if if() is an alternative.
If you can only use #ifdef, think again.

We either have to use ifdef in this case or some other contortion to avoid a warning about the address of a function never being null.

On apple, that code is generating a warning:

if (REAL(memchr)) {

The condition is always true.

rnk accepted this revision.Jul 27 2016, 8:13 AM
rnk edited edge metadata.

lgtm

Oops, I tried to stamp it on my last comment, but it didn't happen...

This revision is now accepted and ready to land.Jul 27 2016, 8:13 AM
etienneb closed this revision.Jul 27 2016, 9:24 AM