On Thu, Jun 14, 2018 at 1:19 PM Alexander Monakov <[email protected]> wrote:
>
> Hello,
>
> We have a somewhat long-recognized problem with LTO vs. symbols referenced
> in inline asm statements. For extended asms, the solution is easy: just
> mention the symbol in constraints. For toplevel asms, this is trickier, as
> they cannot have constraints.
>
> I think a good solution for toplevel asms would be to give users a way to
> add '__attribute__((used))' to symbols referenced in toplevel asms, e.g.:
>
> #include <foo.h>
>
> __attribute__((used))
> __typeof(foo) foo;
>
> asm("foo");
>
>
> If 'foo' has a definition in this translation unit, this already works.
> Let's make this work in LTO if 'foo' is defined in some other TU.
>
> The only problem seems to be that the 'force_output' decl flag is reset
> prior to LTO streaming just because pre-WPA that node is external. I'm
> not sure it's actually necessary.
>
> Does the following patch look reasonable? Bootstrapped/regrested on x86-64.
Can you make sure to add a testcase?
> Thanks.
> Alexander
>
> * ipa-visibility.c (function_and_variable_visibility): Do not reset
> node->force_output.
>
> diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c
> index a82852b3ce4..caa9d420c82 100644
> --- a/gcc/ipa-visibility.c
> +++ b/gcc/ipa-visibility.c
> @@ -672,10 +672,7 @@ function_and_variable_visibility (bool whole_program)
> is finished. We may end up marking as node external nodes
> where this flag is meaningless strip it. */
> if (DECL_EXTERNAL (node->decl) || !node->definition)
> - {
> - node->force_output = 0;
> - node->forced_by_abi = 0;
> - }
> + node->forced_by_abi = 0;
>
> /* C++ FE on lack of COMDAT support create local COMDAT functions
> (that ought to be shared but can not due to object format