Page MenuHomePhabricator

[Driver] Support for disabling sanitizer runtime linking
ClosedPublic

Authored by phosek on Jul 19 2019, 4:37 PM.

Details

Summary

This change introduces a pair of -fsanitize-link-runtime and
-fno-sanitize-link-runtime flags which can be used to control linking of
sanitizer runtimes. This is useful in certain environments like kernels
where existing runtime libraries cannot be used.

Diff Detail

Repository
rL LLVM

Event Timeline

phosek created this revision.Jul 19 2019, 4:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2019, 4:37 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.Jul 19 2019, 4:59 PM

There is an existing option -fsanitize-minimal-runtime, will -fsanitize-no-runtime be a name providing more consistency?

pcc added subscribers: filcab, pcc.Jul 19 2019, 9:49 PM

It's also worth asking whether -nodefaultlibs would work for this use case as @filcab suggested on D64547.

In D65029#1594437, @pcc wrote:

It's also worth asking whether -nodefaultlibs would work for this use case as @filcab suggested on D64547.

It wouldn't, -nodefaultlibs (same as -nostdlib) disables linking of runtime dependencies, but not the runtime itself, e.g. -fsanitize=address -nodefaultlibs disables linking of -lpthread -lrt -lm -ldl which are all dependencies of ASan, but doesn't disable linking of libclang_rt.asan.a which is what we care about.

There is an existing option -fsanitize-minimal-runtime, will -fsanitize-no-runtime be a name providing more consistency?

That's fine with me, I used -f[no-]sanitize-link-deps for consistency with XRay, but -fsanitize-no-runtime would work as well.

phosek updated this revision to Diff 213170.Fri, Aug 2, 7:53 PM
phosek edited the summary of this revision. (Show Details)

I've updated the change and renamed the flag to -fsanitize-no-runtime although I'm not sure if it's necessarily better. I was thinking that ideal interface might be -fsanitize-runtime=(none|minimal|shared|static) which could also replace -fshared-libsan and -fstatic-libsan, but it'd be a breaking change so we might have to keep the existing flag and maybe print a deprecation warning. WDYT?

I've updated the change and renamed the flag to -fsanitize-no-runtime although I'm not sure if it's necessarily better. I was thinking that ideal interface might be -fsanitize-runtime=(none|minimal|shared|static) which could also replace -fshared-libsan and -fstatic-libsan, but it'd be a breaking change so we might have to keep the existing flag and maybe print a deprecation warning. WDYT?

+1 for -fsanitize-runtime=

phosek updated this revision to Diff 213233.Sun, Aug 4, 1:06 AM

I've decided to go with the original -f[no-]sanitize-link-deps: -fsanitize-minimal-runtime is also a cc1 flag which affects codegen, -fshared-libsan and -fstatic-libsan are orthogonal, e.g. it's possible to have minimal shared or static runtime, so these really need to be different flags.

phosek updated this revision to Diff 213235.Sun, Aug 4, 1:36 AM

One more change, I went with -fsanitize-runtime and -fno-sanitize-runtime in the end which seems like the best fit.

phosek updated this revision to Diff 213237.Sun, Aug 4, 2:25 AM
phosek edited the summary of this revision. (Show Details)
MaskRay accepted this revision.Sun, Aug 4, 3:13 AM
phosek updated this revision to Diff 213267.Sun, Aug 4, 1:58 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSun, Aug 4, 3:28 PM