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

Yaxun Liu via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 12:11:09 PDT 2023


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

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.

>From 62d09cbcdff1c59b6a43897ecf760737d9276e42 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" <yaxun.liu at amd.com>
Date: Thu, 26 Oct 2023 14:32:46 -0400
Subject: [PATCH] Fix build failure of lld/ELF/OutputSections.cpp

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.
---
 lld/ELF/OutputSections.cpp | 5 +++++
 1 file changed, 5 insertions(+)

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>



More information about the llvm-commits mailing list