This is an archive of the discontinued LLVM Phabricator instance.

[profile] Make atexit hook a no-op on Fuchsia
ClosedPublic

Authored by phosek on Mar 21 2020, 4:43 PM.

Details

Summary

On Fuchsia, we always use the continuous mode with runtime counter
relocation, so there's no need for atexit hook or support for dumping
the profile manually.

Diff Detail

Event Timeline

phosek created this revision.Mar 21 2020, 4:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2020, 4:43 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
phosek marked an inline comment as done.Mar 21 2020, 4:51 PM
phosek added inline comments.
compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
194–195

To remove this function altogether, we would need to wrap its invocation in https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/profile/InstrProfilingRuntime.cpp#L24 in #if !defined(__Fuchsia__), I'm not sure if that's better than defining an empty function?

mcgrathr added inline comments.Mar 21 2020, 4:58 PM
compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
194–195

Some other runtimes (e.g. hwasan) have an OS-specific InstallAtExitHandler() called by the common initialization function, so we can define that as a no-op.

phosek updated this revision to Diff 251872.Mar 21 2020, 5:47 PM
phosek updated this revision to Diff 251873.
phosek marked an inline comment as done.
mcgrathr added inline comments.Mar 23 2020, 1:25 PM
compiler-rt/lib/profile/InstrProfilingFile.c
39

Can we make this a function defined in File.c to return a static variable kept there and in Fuchsia.c to return constant 1?
Then at least in an LTO future it will fold away for Fuchsia, and not add a data word.

compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
103

This function is responsible for initializing before return and the link-time initializer in BiasVar.c is -1 so this will always be true at startup.

phosek updated this revision to Diff 252448.Mar 24 2020, 3:53 PM
phosek marked an inline comment as done.
phosek added inline comments.
compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
103

It's defined as -1 in https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/profile/InstrProfilingBiasVar.c#L15 which is a weak definition, but compiler will generate a strong definition with the default value 0 when runtime counter relocation is enabled (default on Fuchsia), so this should only kick in when someone accidentally disables runtime counter relocation on Fuchsia? I'm happy to omit this check if you think it's unnecessary.

mcgrathr accepted this revision.Mar 24 2020, 6:27 PM

lgtm with comment and nits

compiler-rt/lib/profile/InstrProfilingInternal.h
188 ↗(On Diff #252448)

C functions need (void).

compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c
37–40

C functions need (void).

103

I see. That makes sense but there should be a comment here explaining the compiler's semantics for this symbol.

This revision is now accepted and ready to land.Mar 24 2020, 6:27 PM
phosek updated this revision to Diff 252471.Mar 24 2020, 6:44 PM
phosek marked 5 inline comments as done.
This revision was automatically updated to reflect the committed changes.