[lld] Fix build failure of lld/ELF/OutputSections.cpp (PR #70368)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 12:12:14 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld

Author: Yaxun (Sam) Liu (yxsamliu)

<details>
<summary>Changes</summary>

On Windows when zlib is enabled, zlib header introduced some C headers which defines max as a macro. Since OutputSections.cpp uses std::max with template argument, this causes compilation error.

Undefine max to workaround this issue.

---
Full diff: https://github.com/llvm/llvm-project/pull/70368.diff


1 Files Affected:

- (modified) lld/ELF/OutputSections.cpp (+5) 


``````````diff
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 2dc425927109403..df78075fee6972e 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -23,6 +23,11 @@
 #include "llvm/Support/TimeProfiler.h"
 #if LLVM_ENABLE_ZLIB
 #include <zlib.h>
+// zlib 1.2.13 causes max to be defined as a macro on Windows.
+// undefine it to use std::max.
+#ifdef max
+#undef max
+#endif
 #endif
 #if LLVM_ENABLE_ZSTD
 #include <zstd.h>

``````````

</details>


https://github.com/llvm/llvm-project/pull/70368


More information about the llvm-commits mailing list