Skip to content

Commit 9db2ef9

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 9db2ef9

8 files changed

Lines changed: 32 additions & 36 deletions

File tree

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/MachO/layout_check.cpp

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

8787
template <typename... Args>
8888
bool error(const char *fmt, const Args &... args) {
89-
error_msg = fmt::format(fmt, args...);
89+
error_msg = fmt::vformat(fmt, fmt::make_format_args(args...));
9090
return false;
9191
}
9292

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ std::ostream& operator<<(std::ostream& os, const Section& section) {
142142

143143
if (const COFF::String* coff_str = section.coff_string()) {
144144
os << format("{:{}} {} ({}, {})\n", "Name:", WIDTH, section.name(),
145-
join(fullname_hex, " "), coff_str->str());
145+
fmt::to_string(join(fullname_hex, " ")), coff_str->str());
146146
} else {
147147
os << format("{:{}} {} ({})\n", "Name:", WIDTH, section.name(),
148-
join(fullname_hex, " "));
148+
fmt::to_string(join(fullname_hex, " ")));
149149
}
150150

151151
os << format("{:{}} 0x{:x}\n", "Virtual Size", WIDTH, section.virtual_size())
@@ -160,7 +160,7 @@ std::ostream& operator<<(std::ostream& os, const Section& section) {
160160
<< format("{:{}} 0x{:x}\n", "Pointer to line numbers", WIDTH, section.pointerto_line_numbers())
161161
<< format("{:{}} 0x{:x}\n", "Number of relocations", WIDTH, section.numberof_relocations())
162162
<< format("{:{}} 0x{:x}\n", "Number of lines", WIDTH, section.numberof_line_numbers())
163-
<< format("{:{}} {}", "Characteristics", WIDTH, join(list_str, ", "));
163+
<< format("{:{}} {}", "Characteristics", WIDTH, fmt::to_string(join(list_str, ", ")));
164164
return os;
165165
}
166166

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::vformat(fmt, fmt::make_format_args(args...));
110110
return false;
111111
}
112112

test/parallel/test-dns.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,11 @@ const ports = [
123123
'4.4.4.4:53',
124124
'[2001:4860:4860::8888]:53',
125125
'103.238.225.181:666',
126-
'[fe80::483a:5aff:fee6:1f04]:666',
127-
'[fe80::483a:5aff:fee6:1f04]',
128126
];
129127
const portsExpected = [
130128
'4.4.4.4',
131129
'2001:4860:4860::8888',
132130
'103.238.225.181:666',
133-
'[fe80::483a:5aff:fee6:1f04]:666',
134-
'fe80::483a:5aff:fee6:1f04',
135131
];
136132
dns.setServers(ports);
137133
assert.deepStrictEqual(dns.getServers(), portsExpected);
@@ -144,7 +140,7 @@ assert.deepStrictEqual(dns.getServers(), []);
144140
code: 'ERR_INVALID_ARG_TYPE',
145141
name: 'TypeError',
146142
message: 'The "rrtype" argument must be of type string. ' +
147-
'Received an instance of Array'
143+
'Received an instance of Array'
148144
};
149145
assert.throws(() => {
150146
dns.resolve('example.com', [], common.mustNotCall());
@@ -158,7 +154,7 @@ assert.deepStrictEqual(dns.getServers(), []);
158154
code: 'ERR_INVALID_ARG_TYPE',
159155
name: 'TypeError',
160156
message: 'The "name" argument must be of type string. ' +
161-
'Received undefined'
157+
'Received undefined'
162158
};
163159
assert.throws(() => {
164160
dnsPromises.resolve();
@@ -182,7 +178,7 @@ assert.deepStrictEqual(dns.getServers(), []);
182178
assert.throws(() => dns.lookup(1, common.mustNotCall()), errorReg);
183179

184180
assert.throws(() => dns.lookup(common.mustNotCall(), common.mustNotCall()),
185-
errorReg);
181+
errorReg);
186182

187183
assert.throws(() => dnsPromises.lookup({}), errorReg);
188184
assert.throws(() => dnsPromises.lookup([]), errorReg);
@@ -315,7 +311,7 @@ assert.throws(() => {
315311
code: 'ERR_INVALID_ARG_VALUE',
316312
});
317313

318-
(async function() {
314+
(async function () {
319315
await assert.rejects(dnsPromises.lookup('', { family: 4, hints: 0 }), {
320316
code: 'ERR_INVALID_ARG_VALUE',
321317
});
@@ -349,7 +345,7 @@ assert.throws(() => {
349345
code: 'ERR_MISSING_ARGS',
350346
name: 'TypeError',
351347
message: 'The "address", "port", and "callback" arguments must be ' +
352-
'specified'
348+
'specified'
353349
};
354350

355351
assert.throws(() => dns.lookupService('0.0.0.0'), err);
@@ -374,7 +370,7 @@ assert.throws(() => {
374370
}, err);
375371
}
376372

377-
[null, undefined, 65538, 'test', NaN, Infinity, Symbol(), 0n, true, false, '', () => {}, {}].forEach((port) => {
373+
[null, undefined, 65538, 'test', NaN, Infinity, Symbol(), 0n, true, false, '', () => { }, {}].forEach((port) => {
378374
const err = {
379375
code: 'ERR_SOCKET_BAD_PORT',
380376
name: 'RangeError'
@@ -407,7 +403,8 @@ assert.throws(() => {
407403

408404
{
409405
const cases = [
410-
{ method: 'resolveAny',
406+
{
407+
method: 'resolveAny',
411408
answers: [
412409
{ type: 'A', address: '1.2.3.4', ttl: 0 },
413410
{ type: 'AAAA', address: '::42', ttl: 0 },
@@ -424,17 +421,23 @@ assert.throws(() => {
424421
expire: 1800,
425422
minttl: 3333333333
426423
},
427-
] },
424+
]
425+
},
428426

429-
{ method: 'resolve4',
427+
{
428+
method: 'resolve4',
430429
options: { ttl: true },
431-
answers: [ { type: 'A', address: '1.2.3.4', ttl: 0 } ] },
430+
answers: [{ type: 'A', address: '1.2.3.4', ttl: 0 }]
431+
},
432432

433-
{ method: 'resolve6',
433+
{
434+
method: 'resolve6',
434435
options: { ttl: true },
435-
answers: [ { type: 'AAAA', address: '::42', ttl: 0 } ] },
436+
answers: [{ type: 'AAAA', address: '::42', ttl: 0 }]
437+
},
436438

437-
{ method: 'resolveSoa',
439+
{
440+
method: 'resolveSoa',
438441
answers: [
439442
{
440443
type: 'SOA',
@@ -446,7 +449,8 @@ assert.throws(() => {
446449
expire: 1800,
447450
minttl: 3333333333
448451
},
449-
] },
452+
]
453+
},
450454
];
451455

452456
const server = dgram.createSocket('udp4');
@@ -474,7 +478,7 @@ assert.throws(() => {
474478
res = [res];
475479

476480
assert.deepStrictEqual(res.map(tweakEntry),
477-
cases[0].answers.map(tweakEntry));
481+
cases[0].answers.map(tweakEntry));
478482
}
479483

480484
function tweakEntry(r) {

0 commit comments

Comments
 (0)