Skip to contentSkip to conversation

exec: Build page-vary-common.c with -fno-lto

PATCH In review Philippe Mathieu-Daudé 3 participants 6 messages Mar 22, 2021 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v2 cover exec: Build page-vary-common.c with -fno-lto

Hi,

While reviewing Richard's original patch, I split it in 3 to make it more digestible to my review taste. I then simply filled the patch descriptions. Feel free to keep Richard's v1 if this isn't worth it.

What is still missing is adding the new files to a MAINTAINERS section.

Regards,

Phil.

Supersedes: <[email protected]>

Richard Henderson (3):
exec: Rename exec-vary.c as page-vary.c
exec: Extract 'page-vary.h' header
exec: Build page-vary-common.c with -fno-lto

 configure                |  19 -------
 meson.build              |  18 ++++++-
 include/exec/cpu-all.h   |  15 ++----
 include/exec/page-vary.h |  34 ++++++++++++
 exec-vary.c              | 108 ---------------------------------------
 page-vary-common.c       |  54 ++++++++++++++++++++
 page-vary.c              |  41 +++++++++++++++
 7 files changed, 150 insertions(+), 139 deletions(-)
 create mode 100644 include/exec/page-vary.h
 delete mode 100644 exec-vary.c
 create mode 100644 page-vary-common.c
 create mode 100644 page-vary.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/3 exec: Rename exec-vary.c as page-vary.c

From: Richard Henderson <[email protected]>

exec-vary.c is about variable page size handling, rename it page-vary.c. Currently this file is target specific (built once for each target), comment this.

---
 meson.build                | 3 ++-
 exec-vary.c => page-vary.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
 rename exec-vary.c => page-vary.c (98%)
meson.build +2 -1
index 5c85a15364d..f0dd8aa0898 100644
@@ -1933,7 +1933,6 @@
 
 common_ss.add(capstone)
 specific_ss.add(files('cpu.c', 'disas.c', 'gdbstub.c'), capstone)
-specific_ss.add(files('exec-vary.c'))
 specific_ss.add(when: 'CONFIG_TCG', if_true: files(
   'fpu/softfloat.c',
   'tcg/optimize.c',
@@ -1945,6 +1944,8 @@
 ))
 specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('tcg/tci.c'))
 
+specific_ss.add(files('page-vary.c'))
+
 subdir('backends')
 subdir('disas')
 subdir('migration')
page-vary.c renamed from exec-vary.c +1 -1
similarity index 98%
rename from exec-vary.c
rename to page-vary.c
index a603b1b4336..344f9fcf76a 100644
@@ -1,5 +1,5 @@
 /*
- * Variable page size handling
+ * Variable page size handling -- target specific part.
  *
  *  Copyright (c) 2003 Fabrice Bellard
  *
Signature · 1 line
2.26.2
#2 lore raw

PATCH v2 2/3 exec: Extract 'page-vary.h' header

In reply to Philippe Mathieu-Daudé

From: Richard Henderson <[email protected]>

In the next commit we will extract the generic code out of page-vary.c, only keeping the target specific code. Both files will use the same TargetPageBits structure, so make its declaration in a shared header.

As the common header can not use target specific types, use a uint64_t to hold the page mask value, and add a cast back to target_long in the TARGET_PAGE_MASK definitions.

---
 include/exec/cpu-all.h   | 11 ++++-------
 include/exec/page-vary.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 7 deletions(-)
 create mode 100644 include/exec/page-vary.h
include/exec/cpu-all.h +4 -7
index 76443eb11d5..b0a422c7b62 100644
@@ -215,11 +215,7 @@ static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val
 /* page related stuff */
 
 #ifdef TARGET_PAGE_BITS_VARY
-typedef struct {
-    bool decided;
-    int bits;
-    target_long mask;
-} TargetPageBits;
+# include "exec/page-vary.h"
 #if defined(CONFIG_ATTRIBUTE_ALIAS) || !defined(IN_EXEC_VARY)
 extern const TargetPageBits target_page;
 #else
@@ -227,10 +223,11 @@ extern TargetPageBits target_page;
 #endif
 #ifdef CONFIG_DEBUG_TCG
 #define TARGET_PAGE_BITS   ({ assert(target_page.decided); target_page.bits; })
-#define TARGET_PAGE_MASK   ({ assert(target_page.decided); target_page.mask; })
+#define TARGET_PAGE_MASK   ({ assert(target_page.decided); \
+                              (target_long)target_page.mask; })
 #else
 #define TARGET_PAGE_BITS   target_page.bits
-#define TARGET_PAGE_MASK   target_page.mask
+#define TARGET_PAGE_MASK   ((target_long)target_page.mask)
 #endif
 #define TARGET_PAGE_SIZE   (-(int)TARGET_PAGE_MASK)
 #else
include/exec/page-vary.h new file +29 -0
new file mode 100644
index 00000000000..799d6310d6c
@@ -0,0 +1,29 @@
+/*
+ * Definitions for cpus with variable page sizes.
+ *
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EXEC_PAGE_VARY_H
+#define EXEC_PAGE_VARY_H
+
+typedef struct {
+    bool decided;
+    int bits;
+    uint64_t mask;
+} TargetPageBits;
+
+#endif /* EXEC_PAGE_VARY_H */
Signature · 1 line
2.26.2
#3 lore raw

PATCH v2 3/3 exec: Build page-vary-common.c with -fno-lto

In reply to Philippe Mathieu-Daudé

From: Richard Henderson <[email protected]>

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 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 exec-page.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.

Message-Id: <[email protected]>

[PMD: Fix typo in subject, split original patch in 3]
---
 configure                | 19 ----------
 meson.build              | 15 ++++++++
 include/exec/cpu-all.h   |  4 --
 include/exec/page-vary.h |  5 +++
 page-vary-common.c       | 54 +++++++++++++++++++++++++++
 page-vary.c              | 79 +++-------------------------------------
 6 files changed, 80 insertions(+), 96 deletions(-)
 create mode 100644 page-vary-common.c
configure +0 -19
index 847bc4d0957..dbb873e09cb 100755
@@ -4889,21 +4889,6 @@ if  test "$plugins" = "yes" &&
       "for this purpose. You can't build with --static."
 fi
 
-########################################
-# See if __attribute__((alias)) is supported.
-# This false for Xcode 9, but has been remedied for Xcode 10.
-# Unfortunately, travis uses Xcode 9 by default.
-
-attralias=no
-cat > $TMPC << EOF
-int x = 1;
-extern const int y __attribute__((alias("x")));
-int main(void) { return 0; }
-EOF
-if compile_prog "" "" ; then
-    attralias=yes
-fi
-
 ########################################
 # check if getauxval is available.
 
@@ -5935,10 +5920,6 @@ if test "$atomic64" = "yes" ; then
   echo "CONFIG_ATOMIC64=y" >> $config_host_mak
 fi
 
-if test "$attralias" = "yes" ; then
-  echo "CONFIG_ATTRIBUTE_ALIAS=y" >> $config_host_mak
-fi
-
 if test "$getauxval" = "yes" ; then
   echo "CONFIG_GETAUXVAL=y" >> $config_host_mak
 fi
meson.build +15 -0
index f0dd8aa0898..24e8897ba2c 100644
@@ -1944,6 +1944,21 @@
 ))
 specific_ss.add(when: 'CONFIG_TCG_INTERPRETER', if_true: files('tcg/tci.c'))
 
+# Work around a gcc bug/misfeature wherein constant propagation looks
+# through an alias:
+#   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99696
+# to guess that a const variable is always zero.  Without lto, this is
+# impossible, as the alias is restricted to page-vary-common.c.  Indeed,
+# without lto, not even the alias is required -- we simply use different
+# declarations in different compilation units.
+pagevary = files('page-vary-common.c')
+if get_option('b_lto')
+  pagevary = static_library('page-vary-common',
+                            sources: pagevary,
+                            c_args: ['-fno-lto'])
+  pagevary = declare_dependency(link_with: pagevary)
+endif
+common_ss.add(pagevary)
 specific_ss.add(files('page-vary.c'))
 
 subdir('backends')
include/exec/cpu-all.h +0 -4
index b0a422c7b62..d76b0b9e02d 100644
@@ -216,11 +216,7 @@ static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val
 
 #ifdef TARGET_PAGE_BITS_VARY
 # include "exec/page-vary.h"
-#if defined(CONFIG_ATTRIBUTE_ALIAS) || !defined(IN_EXEC_VARY)
 extern const TargetPageBits target_page;
-#else
-extern TargetPageBits target_page;
-#endif
 #ifdef CONFIG_DEBUG_TCG
 #define TARGET_PAGE_BITS   ({ assert(target_page.decided); target_page.bits; })
 #define TARGET_PAGE_MASK   ({ assert(target_page.decided); \
include/exec/page-vary.h +5 -0
index 799d6310d6c..c22a7a742e7 100644
@@ -26,4 +26,9 @@ typedef struct {
     uint64_t mask;
 } TargetPageBits;
 
+#ifdef IN_PAGE_VARY
+extern bool set_preferred_target_page_bits_common(int bits);
+extern void finalize_target_page_bits_common(int min);
+#endif
+
 #endif /* EXEC_PAGE_VARY_H */
page-vary-common.c new file +54 -0

54 lines not on this page · raw message

page-vary.c +6 -73

98 lines not on this page · raw message

Signature · 1 line
2.26.2
#4 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Hi,

While reviewing Richard's original patch, I split it in 3 to make it more digestible to my review taste. I then simply filled the patch descriptions. Feel free to keep Richard's v1 if this isn't worth it.

What is still missing is adding the new files to a MAINTAINERS section.

Both versions look good, thanks (the split is indeed more digestible)! Richard, are you going to queue one of them?

Paolo

Quoted 24 lines

Regards,

Phil.

Supersedes: <[email protected]>

Richard Henderson (3):
exec: Rename exec-vary.c as page-vary.c
exec: Extract 'page-vary.h' header
exec: Build page-vary-common.c with -fno-lto

  configure                |  19 -------
  meson.build              |  18 ++++++-
  include/exec/cpu-all.h   |  15 ++----
  include/exec/page-vary.h |  34 ++++++++++++
  exec-vary.c              | 108 ---------------------------------------
  page-vary-common.c       |  54 ++++++++++++++++++++
  page-vary.c              |  41 +++++++++++++++
  7 files changed, 150 insertions(+), 139 deletions(-)

create mode 100644 include/exec/page-vary.h
delete mode 100644 exec-vary.c
create mode 100644 page-vary-common.c
create mode 100644 page-vary.c

#5 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Philippe Mathieu-Daudé

Hi,

While reviewing Richard's original patch, I split it in 3 to make it more digestible to my review taste. I then simply filled the patch descriptions. Feel free to keep Richard's v1 if this isn't worth it.

Quoted 4 lines
Quoted 2 lines

What is still missing is adding the new files to a MAINTAINERS section.

Both versions look good, thanks (the split is indeed more digestible)! Richard, are you going to queue one of them?

Yes, I'll take Phil's split, move the new files into softmmu/, and update MAINTAINERS.

r~