From 4ae50c97d10cf6a38fb2e90ad932824c847cc97a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 14 Jun 2022 14:15:53 -0700 Subject: [PATCH] ircd: Various symbol internalizing and PLT reductions. --- include/ircd/exception.h | 4 +-- include/ircd/fmt.h | 6 ++-- include/ircd/net/acceptor.h | 3 +- include/ircd/net/acceptor_udp.h | 3 +- include/ircd/net/dns.h | 11 ++++-- include/ircd/net/dns_resolver.h | 6 ++-- include/ircd/net/socket.h | 3 +- include/ircd/panic.h | 2 +- include/ircd/rfc3986.h | 2 +- include/ircd/run.h | 3 +- ircd/cl.cc | 2 ++ ircd/exception.cc | 4 +++ ircd/fmt.cc | 63 +++++++++++++++++++++------------ ircd/fpe.cc | 1 + ircd/ios.cc | 7 ++-- ircd/logger.cc | 2 ++ ircd/net.cc | 29 ++++++++++++--- ircd/net_dns_netdb.cc | 2 ++ ircd/vg.cc | 13 +++++++ 19 files changed, 120 insertions(+), 46 deletions(-) diff --git a/include/ircd/exception.h b/include/ircd/exception.h index 94de28202..0c19a43d3 100644 --- a/include/ircd/exception.h +++ b/include/ircd/exception.h @@ -136,7 +136,7 @@ struct ircd::exception /// Remember: the order of the catch blocks is important. /// #define IRCD_EXCEPTION(parent, name) \ -struct name \ +struct [[gnu::visibility("protected")]] name \ :parent \ { \ template \ @@ -180,7 +180,7 @@ struct name \ /// Hides the name of the exception when generating a string #define IRCD_EXCEPTION_HIDENAME(parent, name) \ -struct name \ +struct [[gnu::visibility("protected")]] name \ :parent \ { \ template \ diff --git a/include/ircd/fmt.h b/include/ircd/fmt.h index 58179330e..4874d0508 100644 --- a/include/ircd/fmt.h +++ b/include/ircd/fmt.h @@ -56,15 +56,15 @@ class ircd::fmt::snprintf const_buffer fmt; // Current running position in the fmtstr. short idx; // Keeps count of the args for better err msgs - protected: - bool finished() const; - size_t remaining() const; + bool finished() const noexcept; + size_t remaining() const noexcept; size_t consumed() const { return out.consumed(); } string_view completed() const { return out.completed(); } void append(const string_view &); void argument(const arg &); + protected: IRCD_OVERLOAD(internal) snprintf(internal_t, const mutable_buffer &, const string_view &, const va_rtti &); diff --git a/include/ircd/net/acceptor.h b/include/ircd/net/acceptor.h index 5236ebe48..95cf56434 100644 --- a/include/ircd/net/acceptor.h +++ b/include/ircd/net/acceptor.h @@ -17,7 +17,8 @@ // definition file if you need low level access to this acceptor API. /// Implementation to net::listener. See listener.h for additional interface. -struct ircd::net::acceptor +struct [[gnu::visibility("protected")]] +ircd::net::acceptor :std::enable_shared_from_this { using error_code = boost::system::error_code; diff --git a/include/ircd/net/acceptor_udp.h b/include/ircd/net/acceptor_udp.h index 18dca9227..621508d50 100644 --- a/include/ircd/net/acceptor_udp.h +++ b/include/ircd/net/acceptor_udp.h @@ -16,7 +16,8 @@ // is part of the stack which can be included in your // definition file if you need low level access to this acceptor API. -struct ircd::net::acceptor_udp +struct [[gnu::visibility("protected")]] +ircd::net::acceptor_udp { using error_code = boost::system::error_code; using datagram = listener_udp::datagram; diff --git a/include/ircd/net/dns.h b/include/ircd/net/dns.h index 2892b5d28..b723b5365 100644 --- a/include/ircd/net/dns.h +++ b/include/ircd/net/dns.h @@ -101,9 +101,14 @@ struct ircd::net::dns::opts }; /// (internal) -struct ircd::net::dns::init +class [[gnu::visibility("hidden")]] +ircd::net::dns::init { - static void service_init(), service_fini() noexcept; + static void + service_init(), + service_fini() noexcept; - init(), ~init() noexcept; + public: + init(); + ~init() noexcept; }; diff --git a/include/ircd/net/dns_resolver.h b/include/ircd/net/dns_resolver.h index 76a7ae170..5e966d28a 100644 --- a/include/ircd/net/dns_resolver.h +++ b/include/ircd/net/dns_resolver.h @@ -27,7 +27,8 @@ namespace ircd::net::dns uint16_t resolver_call(const hostport &, const opts &); } -struct ircd::net::dns::resolver +struct [[gnu::visibility("protected")]] +ircd::net::dns::resolver { using header = rfc1035::header; @@ -100,7 +101,8 @@ struct ircd::net::dns::resolver ~resolver() noexcept; }; -struct ircd::net::dns::tag +struct [[gnu::visibility("protected")]] +ircd::net::dns::tag { uint16_t id {0}; hostport hp; diff --git a/include/ircd/net/socket.h b/include/ircd/net/socket.h index cf1769b5b..70e0de833 100644 --- a/include/ircd/net/socket.h +++ b/include/ircd/net/socket.h @@ -26,7 +26,8 @@ namespace ircd::net /// Internal socket interface /// -struct ircd::net::socket +struct [[gnu::visibility("protected")]] +ircd::net::socket :std::enable_shared_from_this { struct io; diff --git a/include/ircd/panic.h b/include/ircd/panic.h index de671d192..f52335e29 100644 --- a/include/ircd/panic.h +++ b/include/ircd/panic.h @@ -26,7 +26,7 @@ namespace ircd /// the triggering callsite should be eliminated. Nevertheless it throws /// normally in release mode for recovering at an exception handler. #define IRCD_PANICKING(parent, name) \ -struct name \ +struct [[gnu::visibility("protected")]] name \ :parent \ { \ template \ diff --git a/include/ircd/rfc3986.h b/include/ircd/rfc3986.h index 200e719ed..b62549d35 100644 --- a/include/ircd/rfc3986.h +++ b/include/ircd/rfc3986.h @@ -71,7 +71,6 @@ struct ircd::rfc3986::uri uri() = default; }; -#pragma GCC visibility push(default) // Exposition of individual grammatical elements. Due to the diverse and // foundational applications of this unit, we offer a public list of references // to individual rules in the grammar; many of these are directly specified in @@ -81,6 +80,7 @@ struct ircd::rfc3986::uri // which take a reference to any apropos rule. To avoid exposure of // boost::spirit in project headers these types are carefully crafted thin forward // declarations, so spirit itself is not included here. +#pragma GCC visibility push(default) namespace ircd::rfc3986::parser { using it = const char *; diff --git a/include/ircd/run.h b/include/ircd/run.h index e149cb6c2..02391646d 100644 --- a/include/ircd/run.h +++ b/include/ircd/run.h @@ -136,7 +136,8 @@ struct ircd::run::changed /// otherwise an exception is thrown. /// template -struct ircd::run::barrier +struct [[gnu::visibility("internal")]] +ircd::run::barrier { template barrier(args&&... a) diff --git a/ircd/cl.cc b/ircd/cl.cc index e90b9d3b6..88892a5aa 100644 --- a/ircd/cl.cc +++ b/ircd/cl.cc @@ -2224,11 +2224,13 @@ ircd::cl::offload_opts "cl" }; +[[gnu::visibility("hidden")]] void ircd::cl::work::init() { } +[[using gnu: cold, visibility("hidden")]] void ircd::cl::work::fini() noexcept diff --git a/ircd/exception.cc b/ircd/exception.cc index 59144ec38..14f812f5e 100644 --- a/ircd/exception.cc +++ b/ircd/exception.cc @@ -246,11 +246,13 @@ noexcept // // Out-of-line placement +[[gnu::visibility("protected")]] ircd::exception::~exception() noexcept { } +[[gnu::visibility("protected")]] ssize_t ircd::exception::generate(const string_view &fmt, const va_rtti &ap) @@ -259,6 +261,7 @@ noexcept return fmt::vsnprintf(buf, sizeof(buf), fmt, ap); } +[[gnu::visibility("protected")]] ssize_t ircd::exception::generate(const char *const &name, const string_view &fmt, @@ -275,6 +278,7 @@ noexcept return size; } +[[gnu::visibility("protected")]] const char * ircd::exception::what() const noexcept diff --git a/ircd/fmt.cc b/ircd/fmt.cc index 8a6a5df50..d89b77828 100644 --- a/ircd/fmt.cc +++ b/ircd/fmt.cc @@ -8,8 +8,7 @@ // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. -namespace ircd { namespace fmt -__attribute__((visibility("internal"))) +namespace ircd::fmt { using namespace ircd::spirit; @@ -29,22 +28,23 @@ __attribute__((visibility("internal"))) constexpr char SPECIFIER_TERMINATOR {'$'}; template - bool generate_string(char *&out, const size_t &max, generator&&, const arg &val); + static bool generate_string(char *&out, const size_t &max, generator&&, const arg &val); template - bool generate(mutable_buffer &, gen&&, attr&&...); + static bool generate(mutable_buffer &, gen&&, attr&&...); template - bool visit_type(const arg &val, lambda&& closure); + static bool visit_type(const arg &val, lambda&& closure); - void handle_specifier(mutable_buffer &out, const uint &idx, const spec &, const arg &); -}} + static void handle_specifier(mutable_buffer &out, const uint &idx, const spec &, const arg &); +} /// Structural representation of a format specifier. The parse of each /// specifier in the format string creates one of these. -struct ircd::fmt::spec +struct [[gnu::visibility("internal")]] +ircd::fmt::spec { char sign {'+'}; char pad {' '}; @@ -67,12 +67,15 @@ BOOST_FUSION_ADAPT_STRUCT ) #pragma GCC visibility pop -#pragma GCC visibility push(internal) /// The format string parser grammar. namespace ircd::fmt::parser { template - using rule = qi::rule; + struct [[gnu::visibility("internal")]] rule + :qi::rule + { + using qi::rule::rule; + }; const expr specsym { @@ -104,13 +107,13 @@ namespace ircd::fmt::parser "specifier" }; } -#pragma GCC visibility pop /// A format specifier handler module. This allows a new "%foo" to be defined /// with custom handling by overriding. This abstraction is inserted into a /// mapping key'ed by the supplied names leading to an instance of this. /// -class ircd::fmt::specifier +class [[gnu::visibility("hidden")]] +ircd::fmt::specifier { static std::map> registry; @@ -130,7 +133,8 @@ class ircd::fmt::specifier decltype(ircd::fmt::specifier::registry) ircd::fmt::specifier::registry; -struct ircd::fmt::string_specifier +struct [[gnu::visibility("hidden")]] +ircd::fmt::string_specifier :specifier { static const std::tuple @@ -156,7 +160,8 @@ const ircd::fmt::string_specifier decltype(ircd::fmt::string_specifier::types) ircd::fmt::string_specifier::types; -struct ircd::fmt::bool_specifier +struct [[gnu::visibility("hidden")]] +ircd::fmt::bool_specifier :specifier { static const std::tuple @@ -181,7 +186,8 @@ const ircd::fmt::bool_specifier decltype(ircd::fmt::bool_specifier::types) ircd::fmt::bool_specifier::types; -struct ircd::fmt::signed_specifier +struct [[gnu::visibility("hidden")]] +ircd::fmt::signed_specifier :specifier { static const std::tuple @@ -206,7 +212,8 @@ const ircd::fmt::signed_specifier decltype(ircd::fmt::signed_specifier::types) ircd::fmt::signed_specifier::types; -struct ircd::fmt::unsigned_specifier +struct [[gnu::visibility("hidden")]] +ircd::fmt::unsigned_specifier :specifier { static const std::tuple @@ -228,7 +235,8 @@ const ircd::fmt::unsigned_specifier { "u"s, "lu"s, "zu"s } }; -struct ircd::fmt::hex_lowercase_specifier +struct [[gnu::visibility("hidden")]] +ircd::fmt::hex_lowercase_specifier :specifier { static const std::tuple @@ -253,7 +261,8 @@ const ircd::fmt::hex_lowercase_specifier decltype(ircd::fmt::hex_lowercase_specifier::types) ircd::fmt::hex_lowercase_specifier::types; -struct ircd::fmt::hex_uppercase_specifier +struct [[gnu::visibility("hidden")]] +ircd::fmt::hex_uppercase_specifier :specifier { static const std::tuple @@ -281,7 +290,8 @@ ircd::fmt::hex_uppercase_specifier::types; decltype(ircd::fmt::unsigned_specifier::types) ircd::fmt::unsigned_specifier::types; -struct ircd::fmt::float_specifier +struct [[gnu::visibility("hidden")]] +ircd::fmt::float_specifier :specifier { static const std::tuple @@ -306,7 +316,8 @@ const ircd::fmt::float_specifier decltype(ircd::fmt::float_specifier::types) ircd::fmt::float_specifier::types; -struct ircd::fmt::char_specifier +struct [[gnu::visibility("hidden")]] +ircd::fmt::char_specifier :specifier { bool operator()(char *&out, const size_t &max, const spec &, const arg &val) const override; @@ -317,7 +328,8 @@ const ircd::fmt::char_specifier "c"s }; -struct ircd::fmt::pointer_specifier +struct [[gnu::visibility("hidden")]] +ircd::fmt::pointer_specifier :specifier { bool operator()(char *&out, const size_t &max, const spec &, const arg &val) const override; @@ -332,6 +344,7 @@ const ircd::fmt::pointer_specifier // snprintf::snprintf // +[[gnu::visibility("protected")]] ircd::fmt::snprintf::snprintf(internal_t, const mutable_buffer &out, const string_view &fmt, @@ -386,6 +399,7 @@ catch(const std::out_of_range &e) }; } +[[gnu::visibility("hidden")]] void ircd::fmt::snprintf::argument(const arg &val) { @@ -426,6 +440,7 @@ ircd::fmt::snprintf::argument(const arg &val) consume(this->fmt, size(leg)); } +[[gnu::visibility("hidden")]] void ircd::fmt::snprintf::append(const string_view &src) { @@ -435,18 +450,20 @@ ircd::fmt::snprintf::append(const string_view &src) }); } +[[gnu::visibility("hidden")]] size_t ircd::fmt::snprintf::remaining() -const +const noexcept { return out.remaining()? out.remaining() - 1: 0; } +[[gnu::visibility("hidden")]] bool ircd::fmt::snprintf::finished() -const +const noexcept { return empty(fmt) || !remaining(); } diff --git a/ircd/fpe.cc b/ircd/fpe.cc index 6e8f5b287..3b20a4901 100644 --- a/ircd/fpe.cc +++ b/ircd/fpe.cc @@ -12,6 +12,7 @@ #pragma STDC FENV_ACCESS on #endif +[[gnu::visibility("protected")]] void ircd::fpe::debug_info() { diff --git a/ircd/ios.cc b/ircd/ios.cc index 194a505da..224198df4 100644 --- a/ircd/ios.cc +++ b/ircd/ios.cc @@ -56,6 +56,7 @@ ircd::boost_version_abi "boost", info::versions::ABI //TODO: get this }; +[[gnu::visibility("hidden")]] void ircd::ios::init(asio::executor &&user) { @@ -78,7 +79,7 @@ ircd::ios::init(asio::executor &&user) ios::main = *ios::primary; } -[[gnu::cold]] +[[using gnu: cold, visibility("hidden")]] void ircd::ios::forking() { @@ -89,7 +90,7 @@ ircd::ios::forking() #endif } -[[gnu::cold]] +[[using gnu: cold, visibility("hidden")]] void ircd::ios::forked_child() { @@ -100,7 +101,7 @@ ircd::ios::forked_child() #endif } -[[gnu::cold]] +[[using gnu: cold, visibility("hidden")]] void ircd::ios::forked_parent() { diff --git a/ircd/logger.cc b/ircd/logger.cc index c404123a9..b0d97bb66 100644 --- a/ircd/logger.cc +++ b/ircd/logger.cc @@ -121,6 +121,7 @@ ircd::log::hook; // init // +[[gnu::visibility("hidden")]] void ircd::log::init() { @@ -145,6 +146,7 @@ ircd::log::init() ircd::log::ready = true; } +[[using gnu: cold, visibility("hidden")]] void ircd::log::fini() { diff --git a/ircd/net.cc b/ircd/net.cc index fe9f9c7f3..f9dc683b2 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -1215,6 +1215,7 @@ ircd::net::ssl_cipher_blacklist { "default", string_view{} }, }; +[[gnu::visibility("hidden")]] boost::asio::ssl::context ircd::net::sslv23_client { @@ -1222,12 +1223,10 @@ ircd::net::sslv23_client }; decltype(ircd::net::socket::count) -ircd::net::socket::count -{}; +ircd::net::socket::count; decltype(ircd::net::socket::instances) -ircd::net::socket::instances -{}; +ircd::net::socket::instances; decltype(ircd::net::socket::desc_connect) ircd::net::socket::desc_connect @@ -2698,6 +2697,7 @@ ircd::net::string(const mutable_buffer &buf, }; } +[[gnu::visibility("protected")]] ircd::net::ipport ircd::net::make_ipport(const boost::asio::ip::udp::endpoint &ep) { @@ -2707,6 +2707,7 @@ ircd::net::make_ipport(const boost::asio::ip::udp::endpoint &ep) }; } +[[gnu::visibility("protected")]] ircd::net::ipport ircd::net::make_ipport(const boost::asio::ip::tcp::endpoint &ep) { @@ -2716,6 +2717,7 @@ ircd::net::make_ipport(const boost::asio::ip::tcp::endpoint &ep) }; } +[[gnu::visibility("protected")]] boost::asio::ip::udp::endpoint ircd::net::make_endpoint_udp(const ipport &ipport) { @@ -2725,6 +2727,7 @@ ircd::net::make_endpoint_udp(const ipport &ipport) }; } +[[gnu::visibility("protected")]] boost::asio::ip::tcp::endpoint ircd::net::make_endpoint(const ipport &ipport) { @@ -2757,6 +2760,7 @@ const // net/ipaddr.h // +[[gnu::visibility("protected")]] boost::asio::ip::address ircd::net::make_address(const ipaddr &ipaddr) { @@ -2765,6 +2769,7 @@ ircd::net::make_address(const ipaddr &ipaddr) ip::address(make_address(ipaddr.v6)); } +[[gnu::visibility("protected")]] boost::asio::ip::address ircd::net::make_address(const string_view &ip) try @@ -2781,12 +2786,14 @@ catch(const boost::system::system_error &e) throw_system_error(e); } +[[gnu::visibility("protected")]] boost::asio::ip::address_v4 ircd::net::make_address(const uint32_t &ip) { return ip::address_v4{ip}; } +[[gnu::visibility("protected")]] boost::asio::ip::address_v6 ircd::net::make_address(const uint128_t &ip) { @@ -2906,6 +2913,7 @@ ircd::net::ipaddr::ipaddr(const uint128_t &ip) { } +[[gnu::visibility("protected")]] ircd::net::ipaddr::ipaddr(const asio::ip::address &address) { const auto address_ @@ -3080,12 +3088,14 @@ ircd::net::string(const mutable_buffer &buf, // net/asio.h // +[[gnu::visibility("protected")]] std::string ircd::net::string(const ip::tcp::endpoint &ep) { return string(make_ipport(ep)); } +[[gnu::visibility("protected")]] ircd::string_view ircd::net::string(const mutable_buffer &buf, const ip::tcp::endpoint &ep) @@ -3093,24 +3103,28 @@ ircd::net::string(const mutable_buffer &buf, return string(buf, make_ipport(ep)); } +[[gnu::visibility("protected")]] std::string ircd::net::host(const ip::tcp::endpoint &ep) { return string(addr(ep)); } +[[gnu::visibility("protected")]] boost::asio::ip::address ircd::net::addr(const ip::tcp::endpoint &ep) { return ep.address(); } +[[gnu::visibility("protected")]] uint16_t ircd::net::port(const ip::tcp::endpoint &ep) { return ep.port(); } +[[gnu::visibility("protected")]] std::string ircd::net::string(const ip::address &addr) { @@ -3120,6 +3134,7 @@ ircd::net::string(const ip::address &addr) string(addr.to_v6()); } +[[gnu::visibility("protected")]] std::string ircd::net::string(const ip::address_v4 &addr) { @@ -3130,12 +3145,14 @@ ircd::net::string(const ip::address_v4 &addr) }); } +[[gnu::visibility("protected")]] std::string ircd::net::string(const ip::address_v6 &addr) { return addr.to_string(); } +[[gnu::visibility("protected")]] ircd::string_view ircd::net::string(const mutable_buffer &out, const ip::address &addr) @@ -3146,6 +3163,7 @@ ircd::net::string(const mutable_buffer &out, string(out, addr.to_v6()); } +[[gnu::visibility("protected")]] ircd::string_view ircd::net::string(const mutable_buffer &out, const ip::address_v4 &addr) @@ -3161,6 +3179,7 @@ ircd::net::string(const mutable_buffer &out, }; } +[[gnu::visibility("protected")]] ircd::string_view ircd::net::string(const mutable_buffer &out, const ip::address_v6 &addr) @@ -3188,6 +3207,7 @@ ircd::buffer::null_buffers null_buffer }}; +[[gnu::visibility("protected")]] ircd::buffer::mutable_buffer::operator boost::asio::mutable_buffer() const noexcept @@ -3198,6 +3218,7 @@ const noexcept }; } +[[gnu::visibility("protected")]] ircd::buffer::const_buffer::operator boost::asio::const_buffer() const noexcept diff --git a/ircd/net_dns_netdb.cc b/ircd/net_dns_netdb.cc index d11140cd5..1c61a3894 100644 --- a/ircd/net_dns_netdb.cc +++ b/ircd/net_dns_netdb.cc @@ -22,6 +22,7 @@ namespace ircd::net::dns /// Custom internal database. This translates a service name and protocol /// into a port number. Note that a query to this table will only be made /// after the system query does not return results (or cannot be made). +[[gnu::visibility("internal")]] decltype(ircd::net::dns::service_ports) ircd::net::dns::service_ports { @@ -31,6 +32,7 @@ ircd::net::dns::service_ports /// Custom internal database. This translates a service port and protocol /// into a service name. Note that a query to this table will only be made /// after the system query does not return results (or cannot be made). +[[gnu::visibility("internal")]] decltype(ircd::net::dns::service_names) ircd::net::dns::service_names { diff --git a/ircd/vg.cc b/ircd/vg.cc index d63a3bd12..d05db0a30 100644 --- a/ircd/vg.cc +++ b/ircd/vg.cc @@ -12,6 +12,7 @@ #include bool // vg::stack // +[[gnu::visibility("protected")]] void ircd::vg::stack::del(const uint &id) noexcept @@ -84,6 +90,7 @@ noexcept #endif } +[[gnu::visibility("protected")]] uint ircd::vg::stack::add(const mutable_buffer &buf) noexcept @@ -105,6 +112,7 @@ namespace ircd::prof::vg static bool _enabled; } +[[gnu::visibility("protected")]] void ircd::prof::vg::stop() noexcept @@ -116,6 +124,7 @@ noexcept #endif } +[[gnu::visibility("protected")]] void ircd::prof::vg::start() noexcept @@ -127,6 +136,7 @@ noexcept #endif } +[[gnu::visibility("protected")]] void ircd::prof::vg::reset() { @@ -135,6 +145,7 @@ ircd::prof::vg::reset() #endif } +[[gnu::visibility("protected")]] void ircd::prof::vg::toggle() { @@ -143,6 +154,7 @@ ircd::prof::vg::toggle() #endif } +[[gnu::visibility("protected")]] void ircd::prof::vg::dump(const char *const reason) { @@ -151,6 +163,7 @@ ircd::prof::vg::dump(const char *const reason) #endif } +[[gnu::visibility("protected")]] bool ircd::prof::vg::enabled() {