rules.mak: Fix DSO build by pulling in archive symbols

This fixes an issue with module build system. block/iscsi.so is
currently broken:

    $ ~/build/last/qemu-img
    Failed to open module: /home/fam/build/master/block-iscsi.so:
    undefined symbol: qmp_query_uuid
    qemu-img: Not enough arguments
    Try 'qemu-img --help' for more information

To fix this, we should (at least) let qemu-img link qmp_query_uuid from
libqemustub.a. (There are a few other symbols missing, as well.)

This patch changes the linking rules to:

1) Build ".mo" with "ld -r -o $@ $^" for each ".so", and later build .so
   with it.

2) Always build all the .mo before linking the executables. This is
   achieved by adding those .mo files to the executables' "-y"
   variables.

3) When linking an executable, those .mo files in its "-y" variables are
   filtered out, and replaced by one or more -Wl,-u,$symbol flags. This
   is done in the added macro "process-archive-undefs".

   These "-Wl,-u,$symbol" flags will force ld to pull in the function
   definition from the archives when linking.

   Note that the .mo objects, that are actually meant to be linked in
   the executables, are already expanded in unnest-vars, before the
   linking command. So we are safe to simply filter out .mo for the
   purpose of pulling undefined symbols.

   process-archive-undefs works as this: For each ".mo", find all the
   undefined symbols in it, filter ones that are defined in the
   archives. For each of these symbols, generate a "-Wl,-u,$symbol" in
   the link command, and put them before archive names in the command
   line.

Suggested-by: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 file changed
tree: 181d3cb60edf8feba7ec792e2fcbfd2335999774
  1. audio/
  2. backends/
  3. block/
  4. bsd-user/
  5. default-configs/
  6. disas/
  7. docs/
  8. fpu/
  9. fsdev/
  10. gdb-xml/
  11. hw/
  12. include/
  13. libcacard/
  14. libdecnumber/
  15. linux-headers/
  16. linux-user/
  17. net/
  18. pc-bios/
  19. po/
  20. qapi/
  21. qga/
  22. qobject/
  23. qom/
  24. roms/
  25. scripts/
  26. slirp/
  27. stubs/
  28. sysconfigs/
  29. target-alpha/
  30. target-arm/
  31. target-cris/
  32. target-i386/
  33. target-lm32/
  34. target-m68k/
  35. target-microblaze/
  36. target-mips/
  37. target-moxie/
  38. target-openrisc/
  39. target-ppc/
  40. target-s390x/
  41. target-sh4/
  42. target-sparc/
  43. target-tricore/
  44. target-unicore32/
  45. target-xtensa/
  46. tcg/
  47. tests/
  48. trace/
  49. ui/
  50. util/
  51. .exrc
  52. .gitignore
  53. .gitmodules
  54. .mailmap
  55. .travis.yml
  56. aio-posix.c
  57. aio-win32.c
  58. arch_init.c
  59. async.c
  60. balloon.c
  61. block-migration.c
  62. block.c
  63. blockdev-nbd.c
  64. blockdev.c
  65. blockjob.c
  66. bt-host.c
  67. bt-vhci.c
  68. Changelog
  69. CODING_STYLE
  70. configure
  71. COPYING
  72. COPYING.LIB
  73. coroutine-gthread.c
  74. coroutine-sigaltstack.c
  75. coroutine-ucontext.c
  76. coroutine-win32.c
  77. cpu-exec.c
  78. cpus.c
  79. cputlb.c
  80. device-hotplug.c
  81. device_tree.c
  82. disas.c
  83. dma-helpers.c
  84. dump.c
  85. exec.c
  86. gdbstub.c
  87. HACKING
  88. hmp-commands.hx
  89. hmp.c
  90. hmp.h
  91. iohandler.c
  92. ioport.c
  93. iothread.c
  94. kvm-all.c
  95. kvm-stub.c
  96. LICENSE
  97. main-loop.c
  98. MAINTAINERS
  99. Makefile
  100. Makefile.objs
  101. Makefile.target
  102. memory.c
  103. memory_mapping.c
  104. migration-exec.c
  105. migration-fd.c
  106. migration-rdma.c
  107. migration-tcp.c
  108. migration-unix.c
  109. migration.c
  110. module-common.c
  111. monitor.c
  112. nbd.c
  113. numa.c
  114. os-posix.c
  115. os-win32.c
  116. page_cache.c
  117. qapi-schema.json
  118. qdev-monitor.c
  119. qdict-test-data.txt
  120. qemu-bridge-helper.c
  121. qemu-char.c
  122. qemu-coroutine-io.c
  123. qemu-coroutine-lock.c
  124. qemu-coroutine-sleep.c
  125. qemu-coroutine.c
  126. qemu-doc.texi
  127. qemu-file.c
  128. qemu-img-cmds.hx
  129. qemu-img.c
  130. qemu-img.texi
  131. qemu-io-cmds.c
  132. qemu-io.c
  133. qemu-log.c
  134. qemu-nbd.c
  135. qemu-nbd.texi
  136. qemu-options-wrapper.h
  137. qemu-options.h
  138. qemu-options.hx
  139. qemu-seccomp.c
  140. qemu-tech.texi
  141. qemu-timer.c
  142. qemu.nsi
  143. qemu.sasl
  144. qmp-commands.hx
  145. qmp.c
  146. qtest.c
  147. README
  148. rules.mak
  149. savevm.c
  150. softmmu_template.h
  151. spice-qemu-char.c
  152. tcg-runtime.c
  153. tci.c
  154. thread-pool.c
  155. thunk.c
  156. tpm.c
  157. trace-events
  158. translate-all.c
  159. translate-all.h
  160. user-exec.c
  161. VERSION
  162. version.rc
  163. vl.c
  164. vmstate.c
  165. xbzrle.c
  166. xen-common-stub.c
  167. xen-common.c
  168. xen-hvm-stub.c
  169. xen-hvm.c
  170. xen-mapcache.c