Page MenuHomePhabricator

[CodeGen] Emit a CoreFoundation link guard when @available is used

Authored by arphaman on Mar 15 2017, 5:12 AM.



After r297760, __isOSVersionAtLeast in compiler-rt loads the CoreFoundation symbols at runtime. This means that @available will always fail when used in a binary without a linked CoreFoundation.

This patch forces Clang to emit a reference to a CoreFoundation symbol when @available is used to ensure that linking will fail when CoreFoundation isn't linked with the build product.

Diff Detail


Event Timeline

arphaman created this revision.Mar 15 2017, 5:12 AM
rjmccall added inline comments.Mar 15 2017, 7:56 AM
3435 ↗(On Diff #91860)

Is this a public weak symbol? Make it hidden, please.

Did you consider just adding "-framework CoreFoundation" to the module link options?

arphaman added inline comments.Mar 15 2017, 11:23 AM
3435 ↗(On Diff #91860)

I'm not familiar with module link options, I'll look into them.

arphaman updated this revision to Diff 91977.Mar 16 2017, 1:33 AM
arphaman marked an inline comment as done.

The guard function is now hidden. I also adopted linker options as John suggested.

rjmccall added inline comments.Mar 16 2017, 9:48 AM
3423 ↗(On Diff #91977)

Reverse these checks, please; IsOSVersionAtLeastFn is much cheaper to check and will predominantly be null.

3428 ↗(On Diff #91977)

Can you explain why compiler-rt has to load the symbol at runtime? Is this just some compiler-rt testing thing? Because it seems like a shame to pay a code-size cost — even a negligible one — for something like that.

arphaman added inline comments.Mar 16 2017, 11:13 AM
3428 ↗(On Diff #91977)

Because compiler-rt is linked into some internal projects that use the -all_load flag, so the linker loads __isOSVersionAtLeast that references the CoreFoundation symbols even when it's not used in code.

arphaman updated this revision to Diff 92028.Mar 16 2017, 11:18 AM
arphaman marked an inline comment as done.

Reverse the early exit checks.

rjmccall accepted this revision.Mar 17 2017, 9:48 AM


3428 ↗(On Diff #91977)

Well, that is terrible.

This revision is now accepted and ready to land.Mar 17 2017, 9:48 AM
This revision was automatically updated to reflect the committed changes.