summaryrefslogtreecommitdiffstats
path: root/page-vary.c
diff options
context:
space:
mode:
authorRichard Henderson2021-03-22 12:24:26 +0100
committerRichard Henderson2021-03-24 02:36:47 +0100
commit44b99a6d5f24afcd8476d0d2701e1ca4ab9b35c1 (patch)
tree254f97b63224e9d81bfa6736dc014afa2aede944 /page-vary.c
parentexec: Extract 'page-vary.h' header (diff)
downloadqemu-44b99a6d5f24afcd8476d0d2701e1ca4ab9b35c1.tar.gz
qemu-44b99a6d5f24afcd8476d0d2701e1ca4ab9b35c1.tar.xz
qemu-44b99a6d5f24afcd8476d0d2701e1ca4ab9b35c1.zip
exec: Build page-vary-common.c with -fno-lto
In bbc17caf81f, we used an alias attribute to allow target_page to be declared const, and yet be initialized late. This fails when using LTO with several versions of gcc. The compiler looks through the alias and decides that the const variable is statically initialized to zero, then propagates that zero to many uses of the variable. This can be avoided by compiling one object file with -fno-lto. In this way, any initializer cannot be seen, and the constant propagation does not occur. Since we are certain to have this separate compilation unit, we can drop the alias attribute as well. We simply have differing declarations for target_page in different compilation units. Drop the use of init_target_page, and drop the configure detection for CONFIG_ATTRIBUTE_ALIAS. In order to change the compilation flags for a file with meson, we must use a static_library. This runs into specific_ss, where we would need to create many static_library instances. Fix this by splitting page-vary.c: the page-vary-common.c part is compiled once as a static_library, while the page-vary.c part is left in specific_ss in order to handle the target-specific value of TARGET_PAGE_BITS_MIN. Reported-by: Gavin Shan <gshan@redhat.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20210321211534.2101231-1-richard.henderson@linaro.org> [PMD: Fix typo in subject, split original patch in 3] Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Tested-by: Gavin Shan <gshan@redhat.com> Message-Id: <20210322112427.4045204-4-f4bug@amsat.org> [rth: Update MAINTAINERS] Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'page-vary.c')
-rw-r--r--page-vary.c79
1 files changed, 6 insertions, 73 deletions
diff --git a/page-vary.c b/page-vary.c
index 344f9fcf76..057c7f1815 100644
--- a/page-vary.c
+++ b/page-vary.c
@@ -17,92 +17,25 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
+#define IN_PAGE_VARY 1
+
#include "qemu/osdep.h"
#include "qemu-common.h"
-
-#define IN_EXEC_VARY 1
-
#include "exec/exec-all.h"
-#ifdef TARGET_PAGE_BITS_VARY
-# ifdef CONFIG_ATTRIBUTE_ALIAS
-/*
- * We want to declare the "target_page" variable as const, which tells
- * the compiler that it can cache any value that it reads across calls.
- * This avoids multiple assertions and multiple reads within any one user.
- *
- * This works because we finish initializing the data before we ever read
- * from the "target_page" symbol.
- *
- * This also requires that we have a non-constant symbol by which we can
- * perform the actual initialization, and which forces the data to be
- * allocated within writable memory. Thus "init_target_page", and we use
- * that symbol exclusively in the two functions that initialize this value.
- *
- * The "target_page" symbol is created as an alias of "init_target_page".
- */
-static TargetPageBits init_target_page;
-
-/*
- * Note that this is *not* a redundant decl, this is the definition of
- * the "target_page" symbol. The syntax for this definition requires
- * the use of the extern keyword. This seems to be a GCC bug in
- * either the syntax for the alias attribute or in -Wredundant-decls.
- *
- * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91765
- */
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wredundant-decls"
-
-extern const TargetPageBits target_page
- __attribute__((alias("init_target_page")));
-
-# pragma GCC diagnostic pop
-# else
-/*
- * When aliases are not supported then we force two different declarations,
- * by way of suppressing the header declaration with IN_EXEC_VARY.
- * We assume that on such an old compiler, LTO cannot be used, and so the
- * compiler cannot not detect the mismatched declarations, and all is well.
- */
-TargetPageBits target_page;
-# define init_target_page target_page
-# endif
-#endif
-
bool set_preferred_target_page_bits(int bits)
{
- /*
- * The target page size is the lowest common denominator for all
- * the CPUs in the system, so we can only make it smaller, never
- * larger. And we can't make it smaller once we've committed to
- * a particular size.
- */
#ifdef TARGET_PAGE_BITS_VARY
assert(bits >= TARGET_PAGE_BITS_MIN);
- if (init_target_page.bits == 0 || init_target_page.bits > bits) {
- if (init_target_page.decided) {
- return false;
- }
- init_target_page.bits = bits;
- }
-#endif
+ return set_preferred_target_page_bits_common(bits);
+#else
return true;
+#endif
}
void finalize_target_page_bits(void)
{
#ifdef TARGET_PAGE_BITS_VARY
- if (init_target_page.bits == 0) {
- init_target_page.bits = TARGET_PAGE_BITS_MIN;
- }
- init_target_page.mask = (target_long)-1 << init_target_page.bits;
- init_target_page.decided = true;
-
- /*
- * For the benefit of an -flto build, prevent the compiler from
- * hoisting a read from target_page before we finish initializing.
- */
- barrier();
+ finalize_target_page_bits_common(TARGET_PAGE_BITS_MIN);
#endif
}