Skip to contentSkip to conversation

plugins: fix cross-build using LLVM for Windows targets

PATCH In review Mohamed Mediouni 2 participants 7 messages Feb 10 – Feb 12 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 plugins: fix cross-build using LLVM for Windows targets

llvm-dlltool assumes that it's by default targeting the host architecture it's running on. That assumption doesn't hold true when cross-compiling.

---
 plugins/meson.build | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
plugins/meson.build +8 -1
index 34643e2cea..9899f166ee 100644
@@ -41,9 +41,16 @@ if host_os == 'windows'
   # to find missing symbols in current program.
   win32_qemu_plugin_api_link_flags = ['-Lplugins', '-lqemu_plugin_api']
   if meson.get_compiler('c').get_id() == 'clang'
+    if host_machine.cpu() == 'x86_64'
+      dlltool_target = 'i386:x86-64'
+    elif host_machine.cpu() == 'aarch64'
+      dlltool_target = 'arm64'
+    else
+      error('Unknown machine')
+    endif
     # With LLVM/lld, delaylib is specified at link time (-delayload)
     dlltool = find_program('llvm-dlltool', required: true)
-    dlltool_cmd = [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
+    dlltool_cmd = [dlltool, '-m', dlltool_target,'-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
     win32_qemu_plugin_api_link_flags += ['-Wl,-delayload=qemu.exe']
   else
     # With gcc/ld, delay lib is built with a specific delay parameter.
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
Quoted 20 lines · Mohamed Mediouni

llvm-dlltool assumes that it's by default targeting the host architecture it's running on. That assumption doesn't hold true when cross-compiling.

---
  plugins/meson.build | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
plugins/meson.build +4 -0
index 34643e2cea..9899f166ee 100644
@@ -41,9 +41,16 @@ if host_os == 'windows'
    # to find missing symbols in current program.
    win32_qemu_plugin_api_link_flags = ['-Lplugins', '-lqemu_plugin_api']
    if meson.get_compiler('c').get_id() == 'clang'
+    if host_machine.cpu() == 'x86_64'
+      dlltool_target = 'i386:x86-64'
+    elif host_machine.cpu() == 'aarch64'
+      dlltool_target = 'arm64'

plugins/meson.build if host_os == 'windows' · line 56

Quoted 10 lines
plugins/meson.build +4 -1
+    else
+      error('Unknown machine')
+    endif
      # With LLVM/lld, delaylib is specified at link time (-delayload)
      dlltool = find_program('llvm-dlltool', required: true)
-    dlltool_cmd = [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
+    dlltool_cmd = [dlltool, '-m', dlltool_target,'-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
      win32_qemu_plugin_api_link_flags += ['-Wl,-delayload=qemu.exe']
    else
      # With gcc/ld, delay lib is built with a specific delay parameter.

Interesting, on which setup did you find this?

Regards,
Pierrick

#2 lore raw
Quoted 36 lines · Pierrick Bouvier
Quoted 18 lines · Mohamed Mediouni

llvm-dlltool assumes that it's by default targeting the host architecture it's running on. That assumption doesn't hold true when cross-compiling.

---
 plugins/meson.build | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
plugins/meson.build +4 -0
index 34643e2cea..9899f166ee 100644
@@ -41,9 +41,16 @@ if host_os == 'windows'
   # to find missing symbols in current program.
   win32_qemu_plugin_api_link_flags = ['-Lplugins', '-lqemu_plugin_api']
   if meson.get_compiler('c').get_id() == 'clang'
+    if host_machine.cpu() == 'x86_64'
+      dlltool_target = 'i386:x86-64'
+    elif host_machine.cpu() == 'aarch64'
+      dlltool_target = 'arm64'

plugins/meson.build if host_os == 'windows' · line 56

Quoted 10 lines
plugins/meson.build +4 -1
+    else
+      error('Unknown machine')
+    endif
     # With LLVM/lld, delaylib is specified at link time (-delayload)
     dlltool = find_program('llvm-dlltool', required: true)
-    dlltool_cmd = [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
+    dlltool_cmd = [dlltool, '-m', dlltool_target,'-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
     win32_qemu_plugin_api_link_flags += ['-Wl,-delayload=qemu.exe']
   else
     # With gcc/ld, delay lib is built with a specific delay parameter.

Interesting, on which setup did you find this?

Quoted 2 lines

Regards,
Pierrick

Hello,

Was found on my macOS arm64 laptop w/ using llvm-mingw and an MXE fork to build all the libs QEMU needed. Cross-compiled for arm64 Windows initially from there, and came across this when targeting x86_64 from that setup.

Reviewed-by Tested-by
#3 lore raw
Quoted 38 lines · Mohamed Mediouni
Quoted 38 lines · Pierrick Bouvier
Quoted 22 lines · Mohamed Mediouni

llvm-dlltool assumes that it's by default targeting the host architecture it's running on. That assumption doesn't hold true when cross-compiling.

---
 plugins/meson.build | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)
plugins/meson.build +0 -0
index 34643e2cea..9899f166ee 100644
@@ -41,9 +41,16 @@ if host_os == 'windows'
    # to find missing symbols in current program.

   win32_qemu_plugin_api_link_flags = ['-Lplugins', '-lqemu_plugin_api'] if meson.get_compiler('c').get_id() == 'clang'
+    if host_machine.cpu() == 'x86_64'
+      dlltool_target = 'i386:x86-64'
+    elif host_machine.cpu() == 'aarch64'
+      dlltool_target = 'arm64'
+    else
+      error('Unknown machine')
+    endif
     # With LLVM/lld, delaylib is specified at link time (-delayload)

Quoted 8 lines

     dlltool = find_program('llvm-dlltool', required: true)
-    dlltool_cmd = [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
+    dlltool_cmd = [dlltool, '-m', dlltool_target,'-d', '@INPUT@', '- l', '@OUTPUT@', '-D', 'qemu.exe'] win32_qemu_plugin_api_link_flags += ['-Wl,-delayload=qemu.exe'] else
     # With gcc/ld, delay lib is built with a specific delay parameter.

Interesting, on which setup did you find this?

Quoted 8 lines
Quoted 2 lines

Regards,
Pierrick

Hello,

Was found on my macOS arm64 laptop w/ using llvm-mingw and an MXE fork to build all the libs QEMU needed. Cross-compiled for arm64 Windows initially from there, and came across this when targeting x86_64 from that setup.

Ok thanks.
When I cross compiled windows-arm64 -> windows-x86_64, I don't remember having to set it. That said, it does not hurt anyway, and everything still builds fine natively with it.

Regards,
Pierrick

#5 lore raw
In reply to Mohamed Mediouni
Quoted 20 lines · Mohamed Mediouni

llvm-dlltool assumes that it's by default targeting the host architecture it's running on. That assumption doesn't hold true when cross-compiling.

---
  plugins/meson.build | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
plugins/meson.build +4 -0
index 34643e2cea..9899f166ee 100644
@@ -41,9 +41,16 @@ if host_os == 'windows'
    # to find missing symbols in current program.
    win32_qemu_plugin_api_link_flags = ['-Lplugins', '-lqemu_plugin_api']
    if meson.get_compiler('c').get_id() == 'clang'
+    if host_machine.cpu() == 'x86_64'
+      dlltool_target = 'i386:x86-64'
+    elif host_machine.cpu() == 'aarch64'
+      dlltool_target = 'arm64'

plugins/meson.build if host_os == 'windows' · line 56

Quoted 10 lines
plugins/meson.build +4 -1
+    else
+      error('Unknown machine')
+    endif
      # With LLVM/lld, delaylib is specified at link time (-delayload)
      dlltool = find_program('llvm-dlltool', required: true)
-    dlltool_cmd = [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
+    dlltool_cmd = [dlltool, '-m', dlltool_target,'-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
      win32_qemu_plugin_api_link_flags += ['-Wl,-delayload=qemu.exe']
    else
      # With gcc/ld, delay lib is built with a specific delay parameter.

This is a good candidate for qemu-stable.

Thanks,
Pierrick

#4 lore raw
In reply to Pierrick Bouvier
Quoted 39 lines · Pierrick Bouvier
Quoted 34 lines · Mohamed Mediouni
Quoted 34 lines · Pierrick Bouvier
Quoted 18 lines · Mohamed Mediouni

llvm-dlltool assumes that it's by default targeting the host architecture it's running on. That assumption doesn't hold true when cross-compiling.

---
 plugins/meson.build | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
plugins/meson.build +4 -0
index 34643e2cea..9899f166ee 100644
@@ -41,9 +41,16 @@ if host_os == 'windows'
   # to find missing symbols in current program.
   win32_qemu_plugin_api_link_flags = ['-Lplugins', '-lqemu_plugin_api']
   if meson.get_compiler('c').get_id() == 'clang'
+    if host_machine.cpu() == 'x86_64'
+      dlltool_target = 'i386:x86-64'
+    elif host_machine.cpu() == 'aarch64'
+      dlltool_target = 'arm64'

plugins/meson.build if host_os == 'windows' · line 56

Quoted 10 lines
plugins/meson.build +4 -1
+    else
+      error('Unknown machine')
+    endif
     # With LLVM/lld, delaylib is specified at link time (-delayload)
     dlltool = find_program('llvm-dlltool', required: true)
-    dlltool_cmd = [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
+    dlltool_cmd = [dlltool, '-m', dlltool_target,'-d', '@INPUT@', '- l', '@OUTPUT@', '-D', 'qemu.exe']
     win32_qemu_plugin_api_link_flags += ['-Wl,-delayload=qemu.exe']
   else
     # With gcc/ld, delay lib is built with a specific delay parameter.

Interesting, on which setup did you find this?

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Regards,
Pierrick

Hello,
Was found on my macOS arm64 laptop w/ using llvm-mingw and an MXE fork to build all the libs QEMU needed. Cross-compiled for arm64 Windows initially from there, and came across this when targeting x86_64 from that setup.

Ok thanks.
When I cross compiled windows-arm64 -> windows-x86_64, I don't remember having to set it. That said, it does not hurt anyway, and everything still builds fine natively with it.

Hi,

Looking at msys2, that uses a separate toolchain copy for each architecture (at /clangarm64 and others) configured to target a single arch. And with separate toolchain packages per architecture to correspond to that.

llvm-mingw (at https://github.com/mstorsjo/llvm-mingw) uses a single toolset copy for all the target architectures instead, with platform-specific headers and libraries in a per-arch triplet folder.

Quoted 6 lines

Regards,
Pierrick

#6 lore raw
In reply to Mohamed Mediouni
Quoted 20 lines · Mohamed Mediouni

llvm-dlltool assumes that it's by default targeting the host architecture it's running on. That assumption doesn't hold true when cross-compiling.

---
  plugins/meson.build | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
plugins/meson.build +4 -0
index 34643e2cea..9899f166ee 100644
@@ -41,9 +41,16 @@ if host_os == 'windows'
    # to find missing symbols in current program.
    win32_qemu_plugin_api_link_flags = ['-Lplugins', '-lqemu_plugin_api']
    if meson.get_compiler('c').get_id() == 'clang'
+    if host_machine.cpu() == 'x86_64'
+      dlltool_target = 'i386:x86-64'
+    elif host_machine.cpu() == 'aarch64'
+      dlltool_target = 'arm64'

plugins/meson.build if host_os == 'windows' · line 56

Quoted 10 lines
plugins/meson.build +4 -1
+    else
+      error('Unknown machine')
+    endif
      # With LLVM/lld, delaylib is specified at link time (-delayload)
      dlltool = find_program('llvm-dlltool', required: true)
-    dlltool_cmd = [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
+    dlltool_cmd = [dlltool, '-m', dlltool_target,'-d', '@INPUT@', '-l', '@OUTPUT@', '-D', 'qemu.exe']
      win32_qemu_plugin_api_link_flags += ['-Wl,-delayload=qemu.exe']
    else
      # With gcc/ld, delay lib is built with a specific delay parameter.

This was merged into master (c848bce26151c21d785bcd60acff6e746852060d). Thank you for your contribution!

Regards,
Pierrick