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


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

>From 27d713bf84b450fa04e5855d9e8d6ecb99d9ccd9 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..ee937418678707c 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 from Windows headers.
+#define NOMINMAX
 #include <zlib.h>
 #endif
 #if LLVM_ENABLE_ZSTD



More information about the llvm-commits mailing list