Skip to content

Commit 7754aff

Browse files
committed
build: remove duplicate C++ standard flags from LIEF
LIEF's lief.gyp explicitly sets -std=gnu++17 in cflags_cc and xcode_settings, while common.gypi already sets -std=gnu++20 project-wide. This results in both flags being passed to the compiler (-std=gnu++20 -std=gnu++17). Since the last flag wins, LIEF was silently compiling as C++17 instead of the intended project-wide C++20. Remove the explicit -std=gnu++17 flags from cflags_cc and xcode_settings.OTHER_CPLUSPLUSFLAGS, and the msvs_settings LanguageStandard override (stdcpp17), so LIEF uses the project-wide C++20 standard. Additionally, fix LIEF compilation with C++20 by explicitly qualifying fmt::format and fmt::join in Section.cpp, and converting joined views into std::string values prior to passing them into final formatting calls. This prevents conflicts between fmt::join_view and std::format when compiling under C++20. Fixes: #62129
1 parent 9f0a3e6 commit 7754aff

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

deps/LIEF/lief.gyp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,7 @@
454454
'cflags': [
455455
'-fPIC'
456456
],
457-
# We need c++17 to compile without std::format and avoid conflicts with spdlog.
458-
'msvs_settings': {
459-
'VCCLCompilerTool': {
460-
'LanguageStandard': 'stdcpp17',
461-
},
462-
},
463457
'cflags_cc': [
464-
'-std=gnu++17',
465458
'-fPIC',
466459
'-fvisibility=hidden',
467460
'-fvisibility-inlines-hidden',
@@ -474,7 +467,6 @@
474467
],
475468
'xcode_settings': {
476469
'OTHER_CPLUSPLUSFLAGS': [
477-
'-std=gnu++17',
478470
'-fPIC',
479471
'-fvisibility=hidden',
480472
'-fvisibility-inlines-hidden',

deps/LIEF/src/PE/Section.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ void Section::clear(uint8_t c) {
126126
}
127127

128128
std::ostream& operator<<(std::ostream& os, const Section& section) {
129-
using namespace fmt;
130129
static constexpr auto WIDTH = 24;
131130
const auto& list = section.characteristics_list();
132131
std::vector<std::string> list_str;
@@ -138,29 +137,34 @@ std::ostream& operator<<(std::ostream& os, const Section& section) {
138137
fullname_hex.reserve(section.name().size());
139138
std::transform(section.fullname().begin(), section.fullname().end(),
140139
std::back_inserter(fullname_hex),
141-
[] (const char c) { return format("{:02x}", c); });
140+
[] (const char c) { return fmt::format("{:02x}", c); });
141+
142+
const std::string fullname_hex_joined =
143+
fmt::format("{}", fmt::join(fullname_hex, " "));
144+
const std::string characteristics_joined =
145+
fmt::format("{}", fmt::join(list_str, ", "));
142146

143147
if (const COFF::String* coff_str = section.coff_string()) {
144-
os << format("{:{}} {} ({}, {})\n", "Name:", WIDTH, section.name(),
145-
join(fullname_hex, " "), coff_str->str());
148+
os << fmt::format("{:{}} {} ({}, {})\n", "Name:", WIDTH, section.name(),
149+
fullname_hex_joined, coff_str->str());
146150
} else {
147-
os << format("{:{}} {} ({})\n", "Name:", WIDTH, section.name(),
148-
join(fullname_hex, " "));
151+
os << fmt::format("{:{}} {} ({})\n", "Name:", WIDTH, section.name(),
152+
fullname_hex_joined);
149153
}
150154

151-
os << format("{:{}} 0x{:x}\n", "Virtual Size", WIDTH, section.virtual_size())
152-
<< format("{:{}} 0x{:x}\n", "Virtual Address", WIDTH, section.virtual_address())
153-
<< format("{:{}} [0x{:08x}, 0x{:08x}]\n", "Range", WIDTH,
155+
os << fmt::format("{:{}} 0x{:x}\n", "Virtual Size", WIDTH, section.virtual_size())
156+
<< fmt::format("{:{}} 0x{:x}\n", "Virtual Address", WIDTH, section.virtual_address())
157+
<< fmt::format("{:{}} [0x{:08x}, 0x{:08x}]\n", "Range", WIDTH,
154158
section.virtual_address(), section.virtual_address() + section.virtual_size())
155-
<< format("{:{}} 0x{:x}\n", "Size of raw data", WIDTH, section.sizeof_raw_data())
156-
<< format("{:{}} 0x{:x}\n", "Pointer to raw data", WIDTH, section.pointerto_raw_data())
157-
<< format("{:{}} [0x{:08x}, 0x{:08x}]\n", "Range", WIDTH,
159+
<< fmt::format("{:{}} 0x{:x}\n", "Size of raw data", WIDTH, section.sizeof_raw_data())
160+
<< fmt::format("{:{}} 0x{:x}\n", "Pointer to raw data", WIDTH, section.pointerto_raw_data())
161+
<< fmt::format("{:{}} [0x{:08x}, 0x{:08x}]\n", "Range", WIDTH,
158162
section.pointerto_raw_data(), section.pointerto_raw_data() + section.sizeof_raw_data())
159-
<< format("{:{}} 0x{:x}\n", "Pointer to relocations", WIDTH, section.pointerto_relocation())
160-
<< format("{:{}} 0x{:x}\n", "Pointer to line numbers", WIDTH, section.pointerto_line_numbers())
161-
<< format("{:{}} 0x{:x}\n", "Number of relocations", WIDTH, section.numberof_relocations())
162-
<< format("{:{}} 0x{:x}\n", "Number of lines", WIDTH, section.numberof_line_numbers())
163-
<< format("{:{}} {}", "Characteristics", WIDTH, join(list_str, ", "));
163+
<< fmt::format("{:{}} 0x{:x}\n", "Pointer to relocations", WIDTH, section.pointerto_relocation())
164+
<< fmt::format("{:{}} 0x{:x}\n", "Pointer to line numbers", WIDTH, section.pointerto_line_numbers())
165+
<< fmt::format("{:{}} 0x{:x}\n", "Number of relocations", WIDTH, section.numberof_relocations())
166+
<< fmt::format("{:{}} 0x{:x}\n", "Number of lines", WIDTH, section.numberof_line_numbers())
167+
<< fmt::format("{:{}} {}", "Characteristics", WIDTH, characteristics_joined);
164168
return os;
165169
}
166170

0 commit comments

Comments
 (0)