Skip to contentSkip to conversation

single-binary: compile some top level files once

PATCH Superseded Pierrick Bouvier 2 participants 9 messages Jul 25, 2025 – Jul 26, 2025 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover single-binary: compile some top level files once

We still have some files left on top files that are compiled per target. Start with the ones included in this series.

Pierrick Bouvier (3):
cpu-target: build compilation unit once for user/system include/exec/target_page.h: move page-target.c to header system/main.c: compile only once

 meson.build                | 10 +++++-----
 include/exec/target_page.h | 11 ++++++++++-
 cpu-target.c               |  5 -----
 page-target.c              | 10 ----------
 target-info-stub.c         |  4 ++++
 system/meson.build         |  1 +
 6 files changed, 20 insertions(+), 21 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/3 cpu-target: build compilation unit once for user/system

---
 meson.build        | 3 ++-
 cpu-target.c       | 5 -----
 target-info-stub.c | 4 ++++
 3 files changed, 6 insertions(+), 6 deletions(-)
meson.build +2 -1
index 6a471a27dee..d0ae602c2ee 100644
@@ -3887,7 +3887,8 @@ endif
 
 common_ss.add(files('cpu-common.c'))
 common_ss.add(files('sanitizer.c'))
-specific_ss.add(files('cpu-target.c'))
+user_ss.add(files('cpu-target.c'))
+system_ss.add(files('cpu-target.c'))
 
 subdir('system')
 
cpu-target.c +0 -5
index 772e35495b8..f030e2c642e 100644
@@ -18,7 +18,6 @@
  */
 
 #include "qemu/osdep.h"
-#include "cpu.h"
 #include "accel/accel-cpu-ops.h"
 #include "system/cpus.h"
 #include "exec/cpu-common.h"
@@ -27,10 +26,6 @@
 #include "hw/core/cpu.h"
 #include "trace/trace-root.h"
 
-/* Validate correct placement of CPUArchState. */
-QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
-QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
-
 /* enable or disable single step mode. EXCP_DEBUG is returned by the
    CPU loop after each instruction */
 void cpu_single_step(CPUState *cpu, int enabled)
target-info-stub.c +4 -0
index ca0caa3686c..d96d8249c1d 100644
@@ -12,6 +12,10 @@
 #include "hw/boards.h"
 #include "cpu.h"
 
+/* Validate correct placement of CPUArchState. */
+QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
+QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
+
 static const TargetInfo target_info_stub = {
     .target_name = TARGET_NAME,
     .target_arch = SYS_EMU_TARGET__MAX,
Signature · 1 line
2.47.2
#3 lore raw

PATCH 2/3 include/exec/target_page.h: move page-target.c to header

In reply to Pierrick Bouvier
---
 meson.build                |  2 +-
 include/exec/target_page.h | 11 ++++++++++-
 page-target.c              | 10 ----------
 3 files changed, 11 insertions(+), 12 deletions(-)
meson.build +1 -1
index d0ae602c2ee..71c253ba135 100644
@@ -3910,7 +3910,7 @@ if get_option('b_lto')
   pagevary = declare_dependency(link_with: pagevary)
 endif
 common_ss.add(pagevary)
-specific_ss.add(files('page-target.c', 'page-vary-target.c'))
+specific_ss.add(files('page-vary-target.c'))
 
 common_ss.add(files('target-info.c'))
 specific_ss.add(files('target-info-stub.c'))
include/exec/target_page.h +10 -1
index ca0ebbc8bbd..813591c9b51 100644
@@ -62,6 +62,15 @@ static inline int qemu_target_page_bits(void)
     return TARGET_PAGE_BITS;
 }
 
-size_t qemu_target_pages_to_MiB(size_t pages);
+/* Convert target pages to MiB (2**20). */
+static inline size_t qemu_target_pages_to_MiB(size_t pages)
+{
+    int page_bits = TARGET_PAGE_BITS;
+
+    /* So far, the largest (non-huge) page size is 64k, i.e. 16 bits. */
+    g_assert(page_bits < 20);
+
+    return pages >> (20 - page_bits);
+}
 
 #endif
page-target.c +0 -10
index 8fcd5443b52..66f03c61cd4 100644
@@ -9,13 +9,3 @@
 #include "qemu/osdep.h"
 #include "exec/target_page.h"
 
-/* Convert target pages to MiB (2**20). */
-size_t qemu_target_pages_to_MiB(size_t pages)
-{
-    int page_bits = TARGET_PAGE_BITS;
-
-    /* So far, the largest (non-huge) page size is 64k, i.e. 16 bits. */
-    g_assert(page_bits < 20);
-
-    return pages >> (20 - page_bits);
-}
Signature · 1 line
2.47.2
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] include/exec/target_page.h: move page-target.c to header

Quoted 15 lines · Pierrick Bouvier
---
  meson.build                |  2 +-
  include/exec/target_page.h | 11 ++++++++++-
  page-target.c              | 10 ----------
  3 files changed, 11 insertions(+), 12 deletions(-)
page-target.c +0 -0
index 8fcd5443b52..66f03c61cd4 100644
@@ -9,13 +9,3 @@
  #include "qemu/osdep.h"
  #include "exec/target_page.h"
 

page-target.c line 21

Quoted 10 lines
page-target.c +0 -10
-/* Convert target pages to MiB (2**20). */
-size_t qemu_target_pages_to_MiB(size_t pages)
-{
-    int page_bits = TARGET_PAGE_BITS;
-
-    /* So far, the largest (non-huge) page size is 64k, i.e. 16 bits. */
-    g_assert(page_bits < 20);
-
-    return pages >> (20 - page_bits);
-}

You didn't completely remove the file, though you clearly intended to do so.

Otherwise,

r~

#5 lore raw

Re: [PATCH 2/3] include/exec/target_page.h: move page-target.c to header

Quoted 16 lines · Richard Henderson
Quoted 15 lines · Pierrick Bouvier
---
   meson.build                |  2 +-
   include/exec/target_page.h | 11 ++++++++++-
   page-target.c              | 10 ----------
   3 files changed, 11 insertions(+), 12 deletions(-)
page-target.c +0 -0
index 8fcd5443b52..66f03c61cd4 100644
@@ -9,13 +9,3 @@
   #include "qemu/osdep.h"
   #include "exec/target_page.h"
 
Quoted 13 lines

page-target.c line 21

Quoted 10 lines
page-target.c +0 -10
-/* Convert target pages to MiB (2**20). */
-size_t qemu_target_pages_to_MiB(size_t pages)
-{
-    int page_bits = TARGET_PAGE_BITS;
-
-    /* So far, the largest (non-huge) page size is 64k, i.e. 16 bits. */
-    g_assert(page_bits < 20);
-
-    return pages >> (20 - page_bits);
-}

You didn't completely remove the file, though you clearly intended to do so.

Right, thanks.

Quoted 5 lines

Otherwise,

r~

#6 lore raw

PATCH 3/3 system/main.c: compile only once

In reply to Pierrick Bouvier
---
 meson.build        | 5 ++---
 system/meson.build | 1 +
 2 files changed, 3 insertions(+), 3 deletions(-)
meson.build +2 -3
index 71c253ba135..7718983951e 100644
@@ -4437,14 +4437,14 @@ foreach target : target_dirs
     execs = [{
       'name': 'qemu-system-' + target_name,
       'win_subsystem': 'console',
-      'sources': files('system/main.c'),
+      'sources': [],
       'dependencies': [sdl]
     }]
     if host_os == 'windows' and (sdl.found() or gtk.found())
       execs += [{
         'name': 'qemu-system-' + target_name + 'w',
         'win_subsystem': 'windows',
-        'sources': files('system/main.c'),
+        'sources': [],
         'dependencies': [sdl]
       }]
     endif
@@ -4519,7 +4519,6 @@ foreach lib: single_binary_libs
   single_binary_objects += lib.extract_all_objects(recursive: true)
 endforeach
 executable('qemu-system',
-            sources: files('system/main.c'),
             objects: single_binary_objects,
             dependencies: single_binary_deps,
             link_depends: [block_syms, qemu_syms],
system/meson.build +1 -0
index 6d21ff9faa7..f358c2c446d 100644
@@ -18,6 +18,7 @@ system_ss.add(files(
   'globals.c',
   'ioport.c',
   'ram-block-attributes.c',
+  'main.c',
   'memory_mapping.c',
   'memory.c',
   'physmem.c',
Signature · 1 line
2.47.2
Reviewed-by on v1 3/3
#7 lore raw

Re: [PATCH 3/3] system/main.c: compile only once

Quoted 28 lines · Pierrick Bouvier
---
  meson.build        | 5 ++---
  system/meson.build | 1 +
  2 files changed, 3 insertions(+), 3 deletions(-)
meson.build +2 -2
index 71c253ba135..7718983951e 100644
@@ -4437,14 +4437,14 @@ foreach target : target_dirs
      execs = [{
        'name': 'qemu-system-' + target_name,
        'win_subsystem': 'console',
-      'sources': files('system/main.c'),
+      'sources': [],
        'dependencies': [sdl]
      }]
      if host_os == 'windows' and (sdl.found() or gtk.found())
        execs += [{
          'name': 'qemu-system-' + target_name + 'w',
          'win_subsystem': 'windows',
-        'sources': files('system/main.c'),
+        'sources': [],
          'dependencies': [sdl]
        }]
      endif

meson.build foreach lib: single_binary_libs · line 4524

Quoted 7 lines
meson.build +0 -1
@@ -4519,7 +4519,6 @@ foreach lib: single_binary_libs
    single_binary_objects += lib.extract_all_objects(recursive: true)
  endforeach
  executable('qemu-system',
-            sources: files('system/main.c'),
              objects: single_binary_objects,
              dependencies: single_binary_deps,
              link_depends: [block_syms, qemu_syms],

This series depends on stuff not upstream. But anyway,

r~

#8 lore raw

Re: [PATCH 3/3] system/main.c: compile only once

Quoted 39 lines · Richard Henderson
Quoted 28 lines · Pierrick Bouvier
---
   meson.build        | 5 ++---
   system/meson.build | 1 +
   2 files changed, 3 insertions(+), 3 deletions(-)
meson.build +2 -2
index 71c253ba135..7718983951e 100644
@@ -4437,14 +4437,14 @@ foreach target : target_dirs
       execs = [{
         'name': 'qemu-system-' + target_name,
         'win_subsystem': 'console',
-      'sources': files('system/main.c'),
+      'sources': [],
         'dependencies': [sdl]
       }]
       if host_os == 'windows' and (sdl.found() or gtk.found())
         execs += [{
           'name': 'qemu-system-' + target_name + 'w',
           'win_subsystem': 'windows',
-        'sources': files('system/main.c'),
+        'sources': [],
           'dependencies': [sdl]
         }]
       endif

meson.build foreach lib: single_binary_libs · line 4524

Quoted 7 lines
meson.build +0 -1
@@ -4519,7 +4519,6 @@ foreach lib: single_binary_libs
     single_binary_objects += lib.extract_all_objects(recursive: true)
   endforeach
   executable('qemu-system',
-            sources: files('system/main.c'),
               objects: single_binary_objects,
               dependencies: single_binary_deps,
               link_depends: [block_syms, qemu_syms],

This series depends on stuff not upstream. But anyway,

Quoted 3 lines

r~

Oh right, sorry. Depends on the patch adding the single-binary, which we didn't upstream yet. I'll hold this one a bit longer.