This patch adds documentation for flto-toplevel-asm-heuristics
and mentions it in Remarks in Basic Asm.

gcc/ChangeLog:

        * common.opt.urls: Regenerate.
        * doc/extend.texi: Mention flto-toplevel-asm-heuristics.
        * doc/invoke.texi: Add flto-toplevel-asm-heuristics.
---
 gcc/common.opt.urls |  3 +++
 gcc/doc/extend.texi |  5 +++++
 gcc/doc/invoke.texi | 22 +++++++++++++++++++++-
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/gcc/common.opt.urls b/gcc/common.opt.urls
index 6c094776187..93e730f2f5d 100644
--- a/gcc/common.opt.urls
+++ b/gcc/common.opt.urls
@@ -1044,6 +1044,9 @@ 
UrlSuffix(gcc/Optimize-Options.html#index-flto-incremental-cache-size)
 flto-partition=
 UrlSuffix(gcc/Optimize-Options.html#index-flto-partition)
 
+flto-toplevel-asm-heuristics
+UrlSuffix(gcc/Optimize-Options.html#index-flto-toplevel-asm-heuristics)
+
 flto-compression-level=
 UrlSuffix(gcc/Optimize-Options.html#index-flto-compression-level)
 
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index ac86a2e1484..5e481126069 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -11507,6 +11507,11 @@ with extended @code{asm}.  See
 from basic asm to extended asm} for information about how to perform this
 conversion.
 
+LTO typically requires rewriting top-level basic @code{asm} statements to
+extended @code{asm}.  Otherwise you will likely encounter missing symbol
+errors by linker.  Alternatively you may use
+@option{-flto-toplevel-asm-heuristics}.
+
 The compiler copies the assembler instructions in a basic @code{asm} 
 verbatim to the assembly language output file, without 
 processing dialects or any of the @samp{%} operators that are available with
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index d690305a890..6ea59a2ea57 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -646,7 +646,8 @@ Objective-C and Objective-C++ Dialects}.
 -floop-unroll-and-jam  -floop-nest-optimize
 -floop-parallelize-all  -flra-remat  -flto  -flto-compression-level
 -flto-partition=@var{alg} -flto-incremental=@var{path}
--flto-incremental-cache-size=@var{n} -fmalloc-dce -fmerge-all-constants
+-flto-incremental-cache-size=@var{n} -flto-toplevel-asm-heuristics
+-fmalloc-dce -fmerge-all-constants
 -fmerge-constants  -fmodulo-sched  -fmodulo-sched-allow-regmoves
 -fmove-loop-invariants  -fmove-loop-stores  -fno-branch-count-reg
 -fno-defer-pop  -fno-function-cse
@@ -15811,6 +15812,25 @@ Multiple GCC instances can use the same cache in 
parallel.
 Specifies number of cache entries in incremental LTO after which to prune
 old entries. This is a soft limit, temporarily there may be more entries.
 
+@opindex flto-toplevel-asm-heuristics
+@item -flto-toplevel-asm-heuristics
+Enables heuristics to find symbols used in top-level basic @code{asm}.
+This will restrict link-time optimizations that could cause renaming
+or deletion of such symbols which would result in missing symbol errors by
+linker.
+
+This flag is intended for projects that have not converted to using top-level
+extended @code{asm} (@pxref{Extended Asm}), which specify the usage directly
+without any false positives.
+
+The heuristics are simple and do not parse the assembly.
+The heuristics scan through top-level assembly for all possible identifiers;
+if an identifier is found among declared symbols, the symbol will be marked to
+restrict link-time optimizations.  Static symbols disable more optimizations.
+Identifiers followed by ':' disable more optimizations as well, because they
+might be a locally defined symbol in assembly, even when the declaration
+is marked 'extern'.
+
 @opindex flto-compression-level
 @item -flto-compression-level=@var{n}
 This option specifies the level of compression used for intermediate
-- 
2.52.0

Reply via email to