[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 17:14:15 PDT 2023


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

>From e99c4afe9a9e6db6c94cab0b26c643613d10ace0 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
Windows headers which defines max as a macro. Since OutputSections.cpp
uses std::max with template argument, this causes compilation
error.

Define NOMINMAX before include zlib header to avoid introducing
max as a macro.
---
 lld/ELF/OutputSections.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 2dc425927109403..05ebbaa8d72ac09 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -22,6 +22,8 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/TimeProfiler.h"
 #if LLVM_ENABLE_ZLIB
+// Avoid introducing max as a macro fron Windows headers.
+#define NOMINMAX
 #include <zlib.h>
 #endif
 #if LLVM_ENABLE_ZSTD



More information about the llvm-commits mailing list