On Sat, Jul 1, 2023 at 5:34 PM Andrew Haley via Gcc-help <gcc-help@xxxxxxxxxxx> wrote: > > On 6/30/23 07:28, Jędrzej Dudkiewicz via Gcc-help wrote: > > This is basically the same as > > https://stackoverflow.com/questions/76580329/hide-symbols-from-executable > > I pasted it below in its entirety. > > > > If this is primarily a binutils question I will paste it there, but I > > *think* it is mostly a gcc related question. > > You don't say whether you are using -ffunction-sections. Andrew, Thank you for responding. I have added `-ffunction-sections` and `-fdata-sections` and also `-Wl,--gc-sections` to the linker. This did nothing (size is identical as without these switches). Let's try a different way: `arm-linux-gnueabihf-nm -C prog` shows for example: mqtt::client<mqtt::tcp_endpoint<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor> >, boost::asio::io_context::strand>, 2u>::async_connect_impl(std::vector<boost::variant<mqtt::v5::property::payload_format_indicator, mqtt::v5::property::message_expiry_interval, mqtt::v5::property::content_type, mqtt::v5::property::response_topic, mqtt::v5::property::correlation_data, mqtt::v5::property::subscription_identifier, mqtt::v5::property::session_expiry_interval, mqtt::v5::property::assigned_client_identifier, mqtt::v5::property::server_keep_alive, mqtt::v5::property::authentication_method, mqtt::v5::property::authentication_data, mqtt::v5::property::request_problem_information, mqtt::v5::property::will_delay_interval, mqtt::v5::property::request_response_information, mqtt::v5::property::response_information, mqtt::v5::property::server_reference, mqtt::v5::property::reason_string, mqtt::v5::property::receive_maximum, mqtt::v5::property::topic_alias_maximum, mqtt::v5::property::topic_alias, mqtt::v5::property::maximum_qos, mqtt::v5::property::retain_available, mqtt::v5::property::user_property, mqtt::v5::property::maximum_packet_size, mqtt::v5::property::wildcard_subscription_available, mqtt::v5::property::subscription_identifier_available, mqtt::v5::property::shared_subscription_available>, std::allocator<boost::variant<mqtt::v5::property::payload_format_indicator, mqtt::v5::property::message_expiry_interval, mqtt::v5::property::content_type, mqtt::v5::property::response_topic, mqtt::v5::property::correlation_data, mqtt::v5::property::subscription_identifier, mqtt::v5::property::session_expiry_interval, mqtt::v5::property::assigned_client_identifier, mqtt::v5::property::server_keep_alive, mqtt::v5::property::authentication_method, mqtt::v5::property::authentication_data, mqtt::v5::property::request_problem_information, mqtt::v5::property::will_delay_interval, mqtt::v5::property::request_response_information, mqtt::v5::property::response_information, mqtt::v5::property::server_reference, mqtt::v5::property::reason_string, mqtt::v5::property::receive_maximum, mqtt::v5::property::topic_alias_maximum, mqtt::v5::property::topic_alias, mqtt::v5::property::maximum_qos, mqtt::v5::property::retain_available, mqtt::v5::property::user_property, mqtt::v5::property::maximum_packet_size, mqtt::v5::property::wildcard_subscription_available, mqtt::v5::property::subscription_identifier_available, mqtt::v5::property::shared_subscription_available> > >, boost::any, std::function<void (boost::system::error_code)>)::{lambda(boost::system::error_code, boost::asio::ip::basic_resolver_results<boost::asio::ip::tcp>)#1}::operator()(boost::system::error_code, boost::asio::ip::basic_resolver_results<boost::asio::ip::tcp>)::{lambda(boost::system::error_code, auto:1)#1}::~basic_resolver_results() My questions is why this symbols is visible (via `nm` or `readelf`) externally - my understanding is that since binaries are not expected to be used as shared objects, it is enough to keep in symbols tables only point of entry (so "main" or "_start" or whatever appropriate) OR symbols that are to be imported from shared library. And probably some other other stuff about which I don't know. But the main idea is that since this symbol is not read from an external source (it is defined in the binary itself), it shouldn't be visible. So why is it visible? Also, the only file where "mqtt::client" is used is compiled as follows (split for easier reading): /usr/local/bin/arm-linux-gnueabihf-g++-9.2.0 -DMQTT_USE_TLS -I/home/jd/repos/pac/zs-comm/inc -I/home/jd/repos/pac/zs-comm/svcbase/inc -I/home/jd/repos/pac/zs-comm/svcbase/config/inc -I/home/jd/repos/pac/zs-comm/svcbase/logger/inc -isystem /opt/ZS/deps/include -O3 -DNDEBUG -Wall -Wextra -pedantic -Wno-psabi-Os -fvisibility=hidden -fvisibility-inlines-hidden -flto -ffunction-sections -fdata-sections -pthread -std=gnu++17 -MD -MT CMakeFiles/paccomm.dir/src/endpoint_mqtt.cpp.o -MF CMakeFiles/paccomm.dir/src/endpoint_mqtt.cpp.o.d -o CMakeFiles/paccomm.dir/src/endpoint_mqtt.cpp.o -c /home/jd/repos/pac/zs-comm/src/endpoint_mqtt.cpp Whole binary is linked like this: /usr/local/bin/arm-linux-gnueabihf-g++-9.2.0 -O3 -DNDEBUG -rdynamic -Wl,--exclude-libs,ALL -Wl,--discard-all -Wl,-flto -Wl,--gc-sections <object files> -o <program_name> -Wl,-rpath,<value_of_rpath> -lboost_system -lboost_filesystem -lssl -lcrypto svcbase/libimbase.a -pthread -lboost_system -lboost_filesystem -lssl -lcrypto -luuid svcbase/config/libineffcfg.a svcbase/logger/libzslog.a I hope this is more than enough information. Thanks, -- Jędrzej Dudkiewicz I really hate this damn machine, I wish that they would sell it. It never does just what I want, but only what I tell it.