This is an archive of the discontinued LLVM Phabricator instance.

[ASan] Only include rpc headers if they are available.
ClosedPublic

Authored by ygribov on Mar 30 2015, 2:29 AM.

Details

Reviewers
kcc
samsonov
Summary

Diff Detail

Repository
rL LLVM

Event Timeline

ygribov updated this revision to Diff 22870.Mar 30 2015, 2:29 AM
ygribov retitled this revision from to [ASan] Only include rpc headers if they are available..
ygribov updated this object.
ygribov edited the test plan for this revision. (Show Details)
ygribov added reviewers: kcc, samsonov.
ygribov set the repository for this revision to rL LLVM.
ygribov added a subscriber: Unknown Object (MLST).
kcc added inline comments.Mar 30 2015, 11:14 AM
CMakeLists.txt
183 ↗(On Diff #22870)

Can you do it w/o cmake checks?
asan rt is built by many build systems, some of which you don't have access to,
and some of which I don't have access to.
All such checks should be done in the sources code.

ygribov added inline comments.Mar 31 2015, 12:58 PM
CMakeLists.txt
183 ↗(On Diff #22870)

Can you do it w/o cmake checks?

I don't think so, Glibc headers do not have any marker to identify whether xdr.h is available or not.

asan rt is built by many build systems, some of which you don't have access to

I'll do the Autoconf part in GCC myself. As for other build systems I think we can safely assume that checking
for existence of header should be well supported.

kcc added inline comments.Mar 31 2015, 1:10 PM
CMakeLists.txt
183 ↗(On Diff #22870)

Can't you rely on the glibc version?
Anyway, at the very least, the code should build on a modern glibc w/o needing extra compile flags.

I.e. provide default values for these macros in a header file (sanitizer_platform_limits_posix.h?)
Then, If you don't need the cmake part here, just drop it.

ygribov added inline comments.Mar 31 2015, 1:51 PM
CMakeLists.txt
183 ↗(On Diff #22870)

Can't you rely on the glibc version?

No, Glibc is not guaranteed to include xdr.h regardless of version. If boils down to distribution maintainer deciding whether he wants to build his glibc with --enable-obsolete-rpc or not.

Anyway, at the very least, the code should build on a modern glibc w/o needing extra compile flags.
I.e. provide default values for these macros
in a header file (sanitizer_platform_limits_posix.h?)

You mean throw in safe ifndefs? Makes sense. While at it, is the rest of the patch fine?

All such checks should be done in the sources code.

But don't we already have tons of configury done in buildscripts? Like ASAN_LOW_MEMORY=1, etc.

samsonov added inline comments.Mar 31 2015, 2:01 PM
CMakeLists.txt
183 ↗(On Diff #22870)

What Kostya says. I'm OK with optional inclusion of headers, as long as they are #included by default, and we use specific build systems (CMake, autoconf, etc.) to optionally disable them.

184 ↗(On Diff #22870)

check_include_file just sets the value of CMake variable HAVE_TIRPC_XDR_H, it will not be turned into compiler definition on its own. You will have to either use generate compiler-rt-config.h (meh), or use this variable to add compiler definitions in CMake (better).

ygribov updated this revision to Diff 23171.Apr 2 2015, 11:06 AM

Updated based on Kostya's suggestions. Also performed more rigorous testing:

  • rpc/xdr.h + tirpc/rpc/xdr.h - works
  • only rpc/xdr.h - works
  • only tirpc/rpc/xdr.h - works
  • none - works
samsonov added inline comments.Apr 3 2015, 3:04 PM
lib/sanitizer_common/CMakeLists.txt
120

Does HAVE_TIRPC_XDR_H get the value "1" in this macro? Consider moving this logic (check_include_file + adjusting the variable value) to some common macro.

lib/sanitizer_common/sanitizer_platform.h
134

I'd prefer the logic like this:

#if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_XDR_H)
# define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
# define HAVE_TIRPC_XDR_H 0
#endif
lib/sanitizer_common/sanitizer_platform_limits_posix.cc
1166

Looks like you can use just use

#if (HAVE_RPC_XDR_H || HAVE_TIRPC_XDR_H)

here

ygribov updated this revision to Diff 23348.Apr 7 2015, 10:19 AM

Updated after review. The append_have_file_definition macro is ugly ugly (just as CMake itself with it's crazy language idiosyncrasies is).

samsonov accepted this revision.Apr 8 2015, 9:04 AM
samsonov edited edge metadata.

LGTM

This revision is now accepted and ready to land.Apr 8 2015, 9:04 AM
ygribov closed this revision.Apr 9 2015, 1:12 AM