This is an archive of the discontinued LLVM Phabricator instance.

[profile] Enable on Solaris
ClosedPublic

Authored by ro on Dec 7 2017, 1:11 AM.

Details

Summary

The test/asan/TestCases/asan_and_llvm_coverage_test.cc failed to link on Solaris
since libclang_rt.profile was missing. Instead of trying to document that requirement
in the test, I just tried to enable the library on Solaris instead.

Most changes are probably straightforward, but two bear explanation:

  • The getpid prototype in lib/profile/InstrProfilingFile.c conflicted with the system one (returning pid_t instead of instead), so I removed it.
  • While parts of the profile library prefer fcntl(F_SETLCKW) over flock(LOCK_EX) if available, others unconditionally use flock. flock just doesn't exist on Solaris, so I moved the locking to common code.

Diff Detail

Event Timeline

ro created this revision.Dec 7 2017, 1:11 AM
vsk added a reviewer: vsk.Dec 7 2017, 1:17 PM
vsk added a subscriber: vsk.
vsk added inline comments.
lib/profile/GCDAProfiling.c
33–34

Why not migrate O_BINARY to the common header as well?

lib/profile/InstrProfilingUtil.c
118

Is flock available on Windows? If not, please handle that case by reporting a warning, and document the limitation near the header declarations of lprof(Un)lockFd.

136

Please clang-format your changes.

ro marked an inline comment as done.Dec 8 2017, 2:16 AM
ro added inline comments.
lib/profile/GCDAProfiling.c
33–34

Looking closer, I see that both MAP_FILE and O_BINARY
are problematic: InstrProfilingPort.h and/or InstrProfiling.h
are included before system headers, but such fallback definitions
need to come after those had a chance to provide the real
definitions. To fix this, either the system header includes
need to be moved to the InstProfiling{Port,}.h files or those
need to be included after system headers. WDYT?

lib/profile/InstrProfilingUtil.c
118

I guess so: even before my patch, it was used unconditionally
in GCDAProfiling.c which is common code.

136

Will do: I missed this because formatting errors in may
sanitizer patches were pointed out during the build, so I assumed
this applied to all of compiler-rt (or even llvm).

vsk added inline comments.Dec 8 2017, 1:27 PM
lib/profile/GCDAProfiling.c
33–34

Moving the InstrProfiling*.h imports after the system header imports sgtm, but please add a short comment there explaining why we're relying on that sort of textual #include (it goes against typical llvm practice).

ro updated this revision to Diff 126534.Dec 12 2017, 4:58 AM
ro marked an inline comment as done.

I've moved the InstrProfiling*.h after the system headers now (without a comment
yet because it's unclear where best to put it), but there are reasons to also include them
early:

COMPILER_RT_HAS_UNAME was defined in InstrProfilingPort.h and used to control
whether or not to include <sys/utsname.h>. When InstrProfilingPort.h is included later,
this won't work, so I moved the check for <sys/utsname.h> to CMakeLists.txt.
Initially, this didn't work as expected: I tried check_include_file. Although checking for
a header could be a compile-only test, that function tries to link, which fails since
cmake/config-ix.cmake adds -nodefaultlibs to CMAKE_REQUIRED_FLAGS, so both
the startup files and libc are missing and the link fails.

Besides, I now print getpid() as long (which it can be on Solaris), avoiding a warning.

uname(2) is documented in POSIX.1-2008 to be non-negative on success (and
Solaris returns 1), while InstrProfilingUtil.c (lprofGetHostName) only expects the
0 return value found on Linux.

Last but not least, I found that I'd overlooked to enable the profile tests. With
a version of Solaris ld that supports the non-standard GNU ld extension of adding
start_SECNAME and stop_SECNAME labels to sections whose names are valid
as C identifiers and an LLVM companion patch to enable that (https://reviews.llvm.org/D41111),
all tests pass.

ro marked an inline comment as done.Dec 12 2017, 4:59 AM
vsk accepted this revision.Dec 12 2017, 10:37 AM

Thanks! LGTM with a nit -- please add the comment we discussed in InstrProfilingPort.h.

lib/profile/InstrProfilingPort.h
9

This is a good place to add a comment stating that this header must be textually #included before all others.

lib/profile/InstrProfilingUtil.c
90

Nice catch.

This revision is now accepted and ready to land.Dec 12 2017, 10:37 AM
ro marked an inline comment as done.Dec 14 2017, 7:57 AM
ro added inline comments.
lib/profile/InstrProfilingPort.h
9

Included after all the others, actually :-)

ro updated this revision to Diff 126964.Dec 14 2017, 7:59 AM
ro marked an inline comment as done.

Added comment.

Could someone please commit the patch for me? Thanks.

This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.