Skip to content

format.h should include <cstdlib> #63935

@aschwarzusp

Description

@aschwarzusp

Version

26.3.0

Platform

Gentoo Linux 7.0.12

Subsystem

No response

What steps will reproduce the bug?

Try to compile nodejs using libcxx. This usually involves using Clang and LLVM to compile.

How often does it reproduce? Is there a required condition?

It is easily reproducible in any affected environment as long as #include is missing in format.h, because it is required to define malloc version.

What is the expected behavior? Why is that the expected behavior?

Successful compilation

What do you see instead?

[2820/3400] clang++ -MMD -MF obj/deps/LIEF/src/PE/liblief.CodeIntegrity.o.d -D_GLIBCXX_USE_CXX11_ABI=1 -D_FILE_OFFSET_BITS=64 -DNODE_OPENSSL_CONF_NAME=nodejs_conf -DNODE_OPENSSL_CERT_STORE -DICU_NO_USER_DATA_OVERRIDE -D__STDC_FORMAT_MACROS -DLIEF_STATIC '-DMBEDTLS_CONFIG_FILE="config/mbedtls/config.h"' -DMBEDTLS_NO_PLATFORM_ENTROPY -DSPDLOG_DISABLE_DEFAULT_LOGGER -DSPDLOG_NO_EXCEPTIONS '-DSPDLOG_FUNCTION=""' -DNDEBUG -I../../deps/LIEF -I../../deps/LIEF/include -I../../deps/LIEF/src -I../../deps/LIEF/third-party/mbedtls/include -I../../deps/LIEF/third-party/mbedtls/library -I../../deps/LIEF/third-party/spdlog/include -I../../deps/LIEF/third-party/frozen/include -I../../deps/LIEF/include/LIEF/third-party -I../../deps/LIEF/include/LIEF/third-party/internal -pthread -Wall -Wextra -Wno-unused-parameter -fPIC -m64 -fno-omit-frame-pointer -march=native -O2 -pipe -fno-rtti -fno-exceptions -fno-strict-aliasing -std=gnu++20 -std=gnu++17 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wpedantic -Wno-expansion-to-defined -Werror=return-type -fno-exceptions -c ../../deps/LIEF/src/PE/CodeIntegrity.cpp -o obj/deps/LIEF/src/PE/liblief.CodeIntegrity.o
�[31mFAILED: [code=1] �[0mobj/deps/LIEF/src/PE/liblief.CodeIntegrity.o
clang++ -MMD -MF obj/deps/LIEF/src/PE/liblief.CodeIntegrity.o.d -D_GLIBCXX_USE_CXX11_ABI=1 -D_FILE_OFFSET_BITS=64 -DNODE_OPENSSL_CONF_NAME=nodejs_conf -DNODE_OPENSSL_CERT_STORE -DICU_NO_USER_DATA_OVERRIDE -D__STDC_FORMAT_MACROS -DLIEF_STATIC '-DMBEDTLS_CONFIG_FILE="config/mbedtls/config.h"' -DMBEDTLS_NO_PLATFORM_ENTROPY -DSPDLOG_DISABLE_DEFAULT_LOGGER -DSPDLOG_NO_EXCEPTIONS '-DSPDLOG_FUNCTION=""' -DNDEBUG -I../../deps/LIEF -I../../deps/LIEF/include -I../../deps/LIEF/src -I../../deps/LIEF/third-party/mbedtls/include -I../../deps/LIEF/third-party/mbedtls/library -I../../deps/LIEF/third-party/spdlog/include -I../../deps/LIEF/third-party/frozen/include -I../../deps/LIEF/include/LIEF/third-party -I../../deps/LIEF/include/LIEF/third-party/internal -pthread -Wall -Wextra -Wno-unused-parameter -fPIC -m64 -fno-omit-frame-pointer -march=native -O2 -pipe -fno-rtti -fno-exceptions -fno-strict-aliasing -std=gnu++20 -std=gnu++17 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -Wpedantic -Wno-expansion-to-defined -Werror=return-type -fno-exceptions -c ../../deps/LIEF/src/PE/CodeIntegrity.cpp -o obj/deps/LIEF/src/PE/liblief.CodeIntegrity.o
In file included from ../../deps/LIEF/src/PE/CodeIntegrity.cpp:16:
In file included from ../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/fmt.h:24:
In file included from ../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/base.h:2987:
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:747:28: error: use of undeclared identifier 'malloc'
747 | T* p = static_cast<T*>(malloc(n * sizeof(T)));
| ^~~~~~
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:752:35: error: call to function 'free' that is neither visible in the template definition nor found by argument-dependent lookup
752 | void deallocate(T* p, size_t) { free(p); }
| ^
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:812:46: note: in instantiation of member function 'fmt::detail::allocator::deallocate' requested here
812 | if (old_data != self.store_) self.alloc_.deallocate(old_data, old_capacity);
| ^
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:821:27: note: in instantiation of member function 'fmt::basic_memory_buffer::grow' requested here
821 | : detail::buffer(grow), alloc_(alloc) {
| ^
/usr/include/sched.h:84:7: note: 'free' should be declared prior to the call site
84 | void (free)(void );
| ^
In file included from ../../deps/LIEF/src/PE/CodeIntegrity.cpp:16:
In file included from ../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/fmt.h:24:
In file included from ../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/base.h:2987:
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:752:35: error: call to function 'free' that is neither visible in the template definition nor found by argument-dependent lookup
752 | void deallocate(T
p, size_t) { free(p); }
| ^
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:812:46: note: in instantiation of member function 'fmt::detail::allocator::deallocate' requested here
812 | if (old_data != self.store_) self.alloc_.deallocate(old_data, old_capacity);
| ^
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:821:27: note: in instantiation of member function 'fmt::basic_memory_buffer::grow' requested here
821 | : detail::buffer(grow), alloc_(alloc) {
| ^
/usr/include/sched.h:84:7: note: 'free' should be declared prior to the call site
84 | void (free)(void );
| ^
In file included from ../../deps/LIEF/src/PE/CodeIntegrity.cpp:16:
In file included from ../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/fmt.h:24:
In file included from ../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/base.h:2987:
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:752:35: error: call to function 'free' that is neither visible in the template definition nor found by argument-dependent lookup
752 | void deallocate(T
p, size_t) { free(p); }
| ^
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:812:46: note: in instantiation of member function 'fmt::detail::allocator::deallocate' requested here
812 | if (old_data != self.store_) self.alloc_.deallocate(old_data, old_capacity);
| ^
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:821:27: note: in instantiation of member function 'fmt::basic_memory_buffer<unsigned int, 32>::grow' requested here
821 | : detail::buffer(grow), alloc_(alloc) {
| ^
/usr/include/sched.h:84:7: note: 'free' should be declared prior to the call site
84 | void (free)(void );
| ^
In file included from ../../deps/LIEF/src/PE/CodeIntegrity.cpp:16:
In file included from ../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/fmt.h:24:
In file included from ../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/base.h:2987:
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:752:35: error: call to function 'free' that is neither visible in the template definition nor found by argument-dependent lookup
752 | void deallocate(T
p, size_t) { free(p); }
| ^
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:812:46: note: in instantiation of member function 'fmt::detail::allocator<wchar_t>::deallocate' requested here
812 | if (old_data != self.store_) self.alloc_.deallocate(old_data, old_capacity);
| ^
../../deps/LIEF/third-party/spdlog/include/spdlog/fmt/bundled/format.h:821:27: note: in instantiation of member function 'fmt::basic_memory_buffer<wchar_t>::grow' requested here
821 | : detail::buffer(grow), alloc_(alloc) {
| ^
/usr/include/sched.h:84:7: note: 'free' should be declared prior to the call site
84 | void (free)(void *);
| ^
5 errors generated.

Additional information

Reference: https://bugs.gentoo.org/977376

This is solved by pull request 63934 (#63934) on said Gentoo system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions