Skip to content

Commit d862bf2

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 d0fa608 commit d862bf2

File tree

6 files changed

+26
-30
lines changed

6 files changed

+26
-30
lines changed

deps/LIEF/lief.gyp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,7 @@
453453
'cflags': [
454454
'-fPIC'
455455
],
456-
# We need c++17 to compile without std::format and avoid conflicts with spdlog.
457-
'msvs_settings': {
458-
'VCCLCompilerTool': {
459-
'LanguageStandard': 'stdcpp17',
460-
},
461-
},
462456
'cflags_cc': [
463-
'-std=gnu++17',
464457
'-fPIC',
465458
'-fvisibility=hidden',
466459
'-fvisibility-inlines-hidden',
@@ -473,7 +466,6 @@
473466
],
474467
'xcode_settings': {
475468
'OTHER_CPLUSPLUSFLAGS': [
476-
'-std=gnu++17',
477469
'-fPIC',
478470
'-fvisibility=hidden',
479471
'-fvisibility-inlines-hidden',

deps/LIEF/src/COFF/Section.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ std::string Section::to_string() const {
122122
[] (const char c) { return format("{:02x}", c); });
123123

124124
os << format("{:{}} {} ({})\n", "Name:", WIDTH, name(),
125-
join(fullname_hex, " "));
125+
fmt::to_string(join(fullname_hex, " ")));
126126

127127
os << format("{:{}} 0x{:x}\n", "Virtual Size", WIDTH, virtual_size())
128128
<< format("{:{}} 0x{:x}\n", "Virtual Address", WIDTH, virtual_address())
@@ -134,7 +134,7 @@ std::string Section::to_string() const {
134134
<< format("{:{}} 0x{:x}\n", "Pointer to line numbers", WIDTH, pointerto_line_numbers())
135135
<< format("{:{}} 0x{:x}\n", "Number of relocations", WIDTH, numberof_relocations())
136136
<< format("{:{}} 0x{:x}\n", "Number of lines", WIDTH, numberof_line_numbers())
137-
<< format("{:{}} {}", "Characteristics", WIDTH, join(list_str, ", "));
137+
<< format("{:{}} {}", "Characteristics", WIDTH, fmt::to_string(join(list_str, ", ")));
138138

139139
return os.str();
140140

deps/LIEF/src/PE/LoadConfigurations/LoadConfiguration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ std::string LoadConfiguration::to_string() const {
917917

918918
if (auto val = guard_flags(); val && *val != 0) {
919919
oss << format("{:{}} {}\n", "Guard Flags:", WIDTH,
920-
fmt::join(guard_cf_flags_list(), ","));
920+
fmt::to_string(fmt::join(guard_cf_flags_list(), ",")));
921921
}
922922

923923
if (const CodeIntegrity* CI = code_integrity()) {

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

deps/LIEF/src/PE/debug/ExDllCharacteristics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ std::string ExDllCharacteristics::to_string() const {
5959
std::ostringstream os;
6060
using namespace fmt;
6161
os << Debug::to_string() << '\n'
62-
<< format(" Characteristics: {}", join(characteristics_list(), ", "));
62+
<< format(" Characteristics: {}", fmt::to_string(join(characteristics_list(), ", ")));
6363
return os.str();
6464
}
6565

deps/LIEF/src/PE/layout_check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class LayoutChecker {
106106

107107
template <typename... Args>
108108
bool error(const char *fmt, const Args &... args) {
109-
error_msg = fmt::format(fmt, args...);
109+
error_msg = fmt::format(fmt::runtime(fmt), args...);
110110
return false;
111111
}
112112

0 commit comments

Comments
 (0)