[PATCH] D112070: [llvm-mt] Fix link failure in unusual situations.

Simon Tatham via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 19 06:12:02 PDT 2021


simon_tatham created this revision.
simon_tatham added reviewers: MaskRay, thakis, mstorsjo.
Herald added a subscriber: mgorny.
simon_tatham requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Trying to build llvm-mt with libxml2 enabled, on a system where
libxml2 and zlib had to be provided as static libraries, I found that
linking llvm-mt failed, because cmake had set up the link line so that
zlib.a came before libxml2.a. But libxml2 refers to zlib, and Unix ld
semantics only search each library once, so it was too late for ld to
go back to zlib and satisfy the unresolved references from libxml2.

This is the smallest fix I could find: reorder llvm-mt's
LLVM_LINK_COMPONENTS so that WindowsManifest (which adds the libxml2
dependency) comes before Support (which adds the zlib one). That way,
they end up on the link line in the opposite order, and the link
works.

I'm not very happy with this as a means of making sure it _stays_
fixed, on the other hand! I'd prefer to write some kind of explicit
rule that says libxml2 must appear before zlib. But I don't know if
cmake has such a thing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112070

Files:
  llvm/tools/llvm-mt/CMakeLists.txt


Index: llvm/tools/llvm-mt/CMakeLists.txt
===================================================================
--- llvm/tools/llvm-mt/CMakeLists.txt
+++ llvm/tools/llvm-mt/CMakeLists.txt
@@ -1,7 +1,12 @@
 set(LLVM_LINK_COMPONENTS
+  # Put WindowsManifest before Support, so that their library
+  # dependencies will be usefully ordered. (Support will pull in zlib;
+  # WindowsManifest is likely to pull in libxml2, which will need
+  # symbols from zlib; to satisfy Unix search-once link semantics,
+  # we'd like libxml2 to already be on the list before zlib is added.)
+  WindowsManifest
   Option
   Support
-  WindowsManifest
   )
 
 set(LLVM_TARGET_DEFINITIONS Opts.td)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112070.380669.patch
Type: text/x-patch
Size: 674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211019/d072586f/attachment.bin>


More information about the llvm-commits mailing list