From 162db19554b0ba1ebe4b469dbb0b7a76d8eb8fb5 Mon Sep 17 00:00:00 2001 From: Corentin Kerisit Date: Tue, 17 Mar 2026 12:53:49 +0100 Subject: [PATCH] Fix mingw ERROR macro collision Rename the InputSection action enum value ERROR to ACT_ERROR. When building with mingw-based Windows toolchains, Windows headers may be pulled in through transitive includes (via tbb for instance). In that case wingdi.h defines ERROR as a macro, which collides with the enum value in input-sections.cc and breaks the build. Rename the enum value to avoid the macro conflict. --- src/input-sections.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/input-sections.cc b/src/input-sections.cc index d3e9d214ad..6ab20325f5 100644 --- a/src/input-sections.cc +++ b/src/input-sections.cc @@ -121,7 +121,8 @@ void InputSection::copy_contents_to(Context &ctx, u8 *buf, i64 sz) { } } -typedef enum : u8 { NONE, ERROR, COPYREL, PLT, CPLT } Action; +// ERROR renamed to ACT_ERROR because mingw Windows headers already #define ERROR. +typedef enum : u8 { NONE, ACT_ERROR, COPYREL, PLT, CPLT } Action; template static void do_action(Context &ctx, Action action, InputSection &isec, @@ -129,7 +130,7 @@ static void do_action(Context &ctx, Action action, InputSection &isec, switch (action) { case NONE: break; - case ERROR: + case ACT_ERROR: Error(ctx) << isec << ": " << rel << " relocation at offset 0x" << std::hex << rel.r_offset << " against symbol `" << sym << "' can not be used; recompile with -fPIC"; @@ -176,9 +177,9 @@ void InputSection::scan_pcrel(Context &ctx, Symbol &sym, // linker generally does not support PC-relative relocations. static Action table[][4] = { // Absolute Local Imported data Imported code - { ERROR, NONE, ERROR, PLT }, // Shared object - { ERROR, NONE, COPYREL, CPLT }, // Position-independent exec - { NONE, NONE, COPYREL, CPLT }, // Position-dependent exec + { ACT_ERROR, NONE, ACT_ERROR, PLT }, // Shared object + { ACT_ERROR, NONE, COPYREL, CPLT }, // Position-independent exec + { NONE, NONE, COPYREL, CPLT }, // Position-dependent exec }; Action action = table[get_output_type(ctx)][get_sym_type(sym)]; @@ -195,9 +196,9 @@ void InputSection::scan_absrel(Context &ctx, Symbol &sym, // resolved at link-time. static Action table[][4] = { // Absolute Local Imported data Imported code - { NONE, ERROR, ERROR, ERROR }, // Shared object - { NONE, ERROR, ERROR, ERROR }, // Position-independent exec - { NONE, NONE, COPYREL, CPLT }, // Position-dependent exec + { NONE, ACT_ERROR, ACT_ERROR, ACT_ERROR }, // Shared object + { NONE, ACT_ERROR, ACT_ERROR, ACT_ERROR }, // Position-independent exec + { NONE, NONE, COPYREL, CPLT }, // Position-dependent exec }; Action action = table[get_output_type(ctx)][get_sym_type(sym)];