This is an archive of the discontinued LLVM Phabricator instance.

[Docs] Document -lto-whole-program-visibility
ClosedPublic

Authored by tejohnson on Mar 4 2020, 3:42 PM.

Details

Summary

Documents interaction of linker option added in D71913 with LTO
visibility.

Diff Detail

Event Timeline

tejohnson created this revision.Mar 4 2020, 3:42 PM
pcc added inline comments.Mar 5 2020, 10:46 AM
clang/docs/LTOVisibility.rst
40

Isn't it spelled whole-program-visibility?

45

I thought that the motivation was avoiding duplicate work in the case where you need varying LTO visibility? Otherwise you could just build with and without -fvisibility=hidden and it would be the same from an LTO visibility perspective.

tejohnson marked 3 inline comments as done.Mar 5 2020, 12:42 PM
tejohnson added a subscriber: evgeny777.
tejohnson added inline comments.
clang/docs/LTOVisibility.rst
40

good catch, yes

45

Yeah I started to write that out but it seemed too verbose (essentially we can't share a single bitcode object anymore without this, because it isn't safe for all dependent links, which to me is included in "situations where it is not safe to specify -fvisibility=hidden"). Also, on D71913, @evgeny777 mentioned he had a case were the symbol visibility constraints didn't allow for -fvisibility=hidden, but where LTO visibility for vtables can be hidden. I could add something more verbose about my case if you prefer.

tejohnson updated this revision to Diff 248582.Mar 5 2020, 12:42 PM
tejohnson marked an inline comment as done.

Fix gold plugin option

pcc added inline comments.Mar 12 2020, 10:05 AM
clang/docs/LTOVisibility.rst
45

@evgeny777 mentioned he had a case were the symbol visibility constraints didn't allow for -fvisibility=hidden, but where LTO visibility for vtables can be hidden.

That case seems somewhat questionable to me. If the symbols are being exported, it is presumably for the purpose of allowing the symbols to be used outside of the defining DSO. But LTO visibility based optimizations could make any such use of the symbols unsafe. For example with WPD it's unsafe to derive outside of the defining DSO and with dead virtual function elimination it's unsafe to call virtual functions outside of the defining DSO.

That makes me think that -lto-whole-program-visibility should imply that associated symbols are forced to hidden to prevent such use, unless we can clearly define what it means to export such a symbol.

@pcc

That case seems somewhat questionable to me. If the symbols are being exported, it is presumably for the purpose of allowing the symbols to be used outside of the defining DSO. But LTO visibility based optimizations could make any such use of the symbols unsafe. For example with WPD it's unsafe to derive outside of the defining DSO and with dead virtual function elimination it's unsafe to call virtual functions outside of the defining DSO.

True, but still direct (cross DSO) calls and globals accesses are possible and do not require explicitly setting visibility everywhere. That was my point.

@pcc

That case seems somewhat questionable to me. If the symbols are being exported, it is presumably for the purpose of allowing the symbols to be used outside of the defining DSO. But LTO visibility based optimizations could make any such use of the symbols unsafe. For example with WPD it's unsafe to derive outside of the defining DSO and with dead virtual function elimination it's unsafe to call virtual functions outside of the defining DSO.

True, but still direct (cross DSO) calls and globals accesses are possible and do not require explicitly setting visibility everywhere. That was my point.

Not sure if we have come to a resolution here. @evgeny777 it sounds like you want symbols that can be direct called not to be marked hidden while still allowing for hidden LTO visibility for virtual functions. Which my change will support, but it sounds like it could be dangerous if not used carefully (i.e. if you don't know for sure that virtual symbols are only called within their defining DSO). Is this a correct summary?

@pcc ping. I'd like to get something in for LLVM 11 if at all possible. How about for now I make the last sentence something like "This is useful in situations where it is not safe to specify`-fvisibility=hidden` at compile time, for example when bitcode objects will be consumed by different LTO links that don't all have whole program visibility." ?

MaskRay added inline comments.
clang/docs/LTOVisibility.rst
39

This is now

``--lto-whole-program-visibility``

(I am currently preparing some lld/ELF release notes for 11.0.0...)

pcc added a comment.Aug 25 2020, 4:20 PM

I think that the part of the description beginning "This can be used when..." is somewhat misleading since you could pretty much say the same thing about specifying -fvisibility=hidden -fwhole-program-vtables at compile time.

I think it would be better to focus on the specific capability that --lto-visibility-hidden gives you over just compiling with -fvisibility=hidden. Let's keep @evgeny777 's use case out of this because I still have concerns about it being dangerous. Can you simply say:

"This flag can be used to defer specifying whether classes have hidden LTO visibility until link time."

Then, in order to try to forbid inappropriate use of the symbols, you could add:

"Due to an implementation limitation, symbols associated with classes with hidden LTO visibility may still be exported from the binary when using this flag. It is unsafe to refer to these symbols, and their visibility may be relaxed to hidden in a future compiler release."

tejohnson marked an inline comment as done.Aug 25 2020, 5:33 PM
In D75655#2237474, @pcc wrote:

I think that the part of the description beginning "This can be used when..." is somewhat misleading since you could pretty much say the same thing about specifying -fvisibility=hidden -fwhole-program-vtables at compile time.

I think it would be better to focus on the specific capability that --lto-visibility-hidden gives you over just compiling with -fvisibility=hidden. Let's keep @evgeny777 's use case out of this because I still have concerns about it being dangerous. Can you simply say:

"This flag can be used to defer specifying whether classes have hidden LTO visibility until link time."

Then, in order to try to forbid inappropriate use of the symbols, you could add:

"Due to an implementation limitation, symbols associated with classes with hidden LTO visibility may still be exported from the binary when using this flag. It is unsafe to refer to these symbols, and their visibility may be relaxed to hidden in a future compiler release."

Added these, but added in my proposed wording about why you would want to defer (to allow bitcode sharing).

clang/docs/LTOVisibility.rst
39

Fixed here and in summary

tejohnson updated this revision to Diff 287808.Aug 25 2020, 5:33 PM
tejohnson marked an inline comment as done.

Address comments

pcc accepted this revision.Aug 25 2020, 6:03 PM

LGTM

Thanks and sorry for the delay.

This revision is now accepted and ready to land.Aug 25 2020, 6:03 PM
This revision was automatically updated to reflect the committed changes.