Skip to content

Commit 556c239

Browse files
authored
GH-47412: [C++] Use inlineshidden visibility in Meson configuration (#47413)
### Rationale for this change I was under the false impression that 'hidden' visibility hid the most symbols from shared libraries. As it turns out, 'inlineshidden' performs the most symbol hiding, so we can achieve the best hygeine and smallest libraries from that option. A local release build shows the following library sizes on main: 21M src/arrow/libarrow-compute.so 16M src/arrow/libarrow.so 21M src/arrow/flight/libarrow-flight.so 2.5M src/arrow/acero/libarrow-acero.so With this PR showing a small improvement in some libraries: 21M src/arrow/libarrow-compute.so 16M src/arrow/libarrow.so 20M src/arrow/flight/libarrow-flight.so 2.4M src/arrow/acero/libarrow-acero.so ### What changes are included in this PR? Usage of 'hidden' has been replaced with 'inlineshidden'. I also added hidden symbol visibility to the compute library, where it was errantly missing before ### Are these changes tested? Yes ### Are there any user-facing changes? No * GitHub Issue: #47412 Authored-by: Will Ayd <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
1 parent 403ba70 commit 556c239

File tree

5 files changed

+109
-70
lines changed

5 files changed

+109
-70
lines changed

cpp/src/arrow/acero/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ arrow_acero_lib = library(
8181
'arrow-acero',
8282
sources: arrow_acero_srcs,
8383
dependencies: [arrow_compute_dep, arrow_dep, threads_dep],
84-
gnu_symbol_visibility: 'hidden',
84+
gnu_symbol_visibility: 'inlineshidden',
8585
)
8686

8787
arrow_acero_dep = declare_dependency(link_with: [arrow_acero_lib])

cpp/src/arrow/flight/meson.build

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,30 @@ fs = import('fs')
5252
protoc = find_program('protoc')
5353

5454
flight_proto_path = fs.parent(meson.project_source_root()) / 'format'
55+
56+
# To ensure messages from proto files are created correctly, we need to
57+
# pass in dllexport_decl=<...> . Unfortunately, it doesn't appear that we
58+
# can just pass in dllexport_decl=ARROW_FLIGHT_EXPORT, as the visibility
59+
# macro won't be easily available to the generated proto file. See also
60+
# https://github.com/protocolbuffers/protobuf/issues/19422
61+
if cpp_compiler.get_id() == 'msvc'
62+
if get_option('default_library') != 'static'
63+
proto_visibility = 'dllexport_decl=__declspec(dllexport):'
64+
else
65+
proto_visibility = ''
66+
endif
67+
else
68+
proto_visibility = 'dllexport_decl=__attribute__((visibility("default"))):'
69+
endif
70+
5571
flight_proto_files = custom_target(
5672
'arrow-flight-proto-files',
5773
input: [flight_proto_path / 'Flight.proto'],
5874
output: ['Flight.pb.cc', 'Flight.pb.h'],
5975
command: [
6076
protoc,
6177
'--proto_path=' + flight_proto_path,
62-
'--cpp_out=' + meson.current_build_dir(),
78+
'--cpp_out=@0@@1@'.format(proto_visibility, meson.current_build_dir()),
6379
'@INPUT@',
6480
],
6581
)
@@ -117,7 +133,9 @@ arrow_flight = library(
117133
abseil_sync_dep,
118134
thread_dep,
119135
],
120-
cpp_args: '-DARROW_FLIGHT_EXPORTING',
136+
cpp_shared_args: ['-DARROW_FLIGHT_EXPORTING'],
137+
cpp_static_args: ['-DARROW_FLIGHT_STATIC'],
138+
gnu_symbol_visibility: 'inlineshidden',
121139
)
122140

123141
arrow_flight_dep = declare_dependency(
@@ -135,7 +153,9 @@ if needs_testing
135153
'test_util.cc',
136154
],
137155
dependencies: [arrow_test_dep, arrow_flight_dep, thread_dep],
138-
gnu_symbol_visibility: 'hidden',
156+
cpp_shared_args: ['-DARROW_FLIGHT_EXPORTING'],
157+
cpp_static_args: ['-DARROW_FLIGHT_STATIC'],
158+
gnu_symbol_visibility: 'inlineshidden',
139159
)
140160

141161
arrow_flight_test_dep = declare_dependency(

cpp/src/arrow/flight/serialization_internal.h

Lines changed: 80 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -99,69 +99,86 @@ Status UnpackProtoAction(const Action& action, google::protobuf::Message* out);
9999

100100
// These functions depend on protobuf types which are not exported in the Flight DLL.
101101

102-
Status FromProto(const google::protobuf::Timestamp& pb_timestamp, Timestamp* timestamp);
103-
Status FromProto(const pb::ActionType& pb_type, ActionType* type);
104-
Status FromProto(const pb::Action& pb_action, Action* action);
105-
Status FromProto(const pb::Result& pb_result, Result* result);
106-
Status FromProto(const pb::CancelFlightInfoResult& pb_result,
107-
CancelFlightInfoResult* result);
108-
Status FromProto(const pb::Criteria& pb_criteria, Criteria* criteria);
109-
Status FromProto(const pb::Location& pb_location, Location* location);
110-
Status FromProto(const pb::Ticket& pb_ticket, Ticket* ticket);
111-
Status FromProto(const pb::FlightData& pb_data, FlightDescriptor* descriptor,
112-
std::unique_ptr<ipc::Message>* message);
113-
Status FromProto(const pb::FlightDescriptor& pb_descr, FlightDescriptor* descr);
114-
Status FromProto(const pb::FlightEndpoint& pb_endpoint, FlightEndpoint* endpoint);
115-
Status FromProto(const pb::RenewFlightEndpointRequest& pb_request,
116-
RenewFlightEndpointRequest* request);
117-
Status FromProto(const pb::FlightInfo& pb_info, FlightInfo::Data* info);
118-
Status FromProto(const pb::FlightInfo& pb_info, std::unique_ptr<FlightInfo>* info);
119-
Status FromProto(const pb::PollInfo& pb_info, PollInfo* info);
120-
Status FromProto(const pb::PollInfo& pb_info, std::unique_ptr<PollInfo>* info);
121-
Status FromProto(const pb::CancelFlightInfoRequest& pb_request,
122-
CancelFlightInfoRequest* request);
123-
Status FromProto(const pb::SchemaResult& pb_result, SchemaResult* result);
124-
Status FromProto(const pb::BasicAuth& pb_basic_auth, BasicAuth* info);
125-
Status FromProto(const pb::SetSessionOptionsRequest& pb_request,
126-
SetSessionOptionsRequest* request);
127-
Status FromProto(const pb::SetSessionOptionsResult& pb_result,
128-
SetSessionOptionsResult* result);
129-
Status FromProto(const pb::GetSessionOptionsRequest& pb_request,
130-
GetSessionOptionsRequest* request);
131-
Status FromProto(const pb::GetSessionOptionsResult& pb_result,
132-
GetSessionOptionsResult* result);
133-
Status FromProto(const pb::CloseSessionRequest& pb_request, CloseSessionRequest* request);
134-
Status FromProto(const pb::CloseSessionResult& pb_result, CloseSessionResult* result);
135-
136-
Status ToProto(const Timestamp& timestamp, google::protobuf::Timestamp* pb_timestamp);
137-
Status ToProto(const FlightDescriptor& descr, pb::FlightDescriptor* pb_descr);
138-
Status ToProto(const FlightEndpoint& endpoint, pb::FlightEndpoint* pb_endpoint);
139-
Status ToProto(const RenewFlightEndpointRequest& request,
140-
pb::RenewFlightEndpointRequest* pb_request);
141-
Status ToProto(const FlightInfo& info, pb::FlightInfo* pb_info);
142-
Status ToProto(const PollInfo& info, pb::PollInfo* pb_info);
143-
Status ToProto(const CancelFlightInfoRequest& request,
144-
pb::CancelFlightInfoRequest* pb_request);
145-
Status ToProto(const ActionType& type, pb::ActionType* pb_type);
146-
Status ToProto(const Action& action, pb::Action* pb_action);
147-
Status ToProto(const Result& result, pb::Result* pb_result);
148-
Status ToProto(const CancelFlightInfoResult& result,
149-
pb::CancelFlightInfoResult* pb_result);
150-
Status ToProto(const Criteria& criteria, pb::Criteria* pb_criteria);
151-
Status ToProto(const Location& location, pb::Location* pb_location);
152-
Status ToProto(const SchemaResult& result, pb::SchemaResult* pb_result);
153-
Status ToProto(const Ticket& ticket, pb::Ticket* pb_ticket);
154-
Status ToProto(const BasicAuth& basic_auth, pb::BasicAuth* pb_basic_auth);
155-
Status ToProto(const SetSessionOptionsRequest& request,
156-
pb::SetSessionOptionsRequest* pb_request);
157-
Status ToProto(const SetSessionOptionsResult& result,
158-
pb::SetSessionOptionsResult* pb_result);
159-
Status ToProto(const GetSessionOptionsRequest& request,
160-
pb::GetSessionOptionsRequest* pb_request);
161-
Status ToProto(const GetSessionOptionsResult& result,
162-
pb::GetSessionOptionsResult* pb_result);
163-
Status ToProto(const CloseSessionRequest& request, pb::CloseSessionRequest* pb_request);
164-
Status ToProto(const CloseSessionResult& result, pb::CloseSessionResult* pb_result);
102+
ARROW_FLIGHT_EXPORT Status FromProto(const google::protobuf::Timestamp& pb_timestamp,
103+
Timestamp* timestamp);
104+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::ActionType& pb_type, ActionType* type);
105+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::Action& pb_action, Action* action);
106+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::Result& pb_result, Result* result);
107+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::CancelFlightInfoResult& pb_result,
108+
CancelFlightInfoResult* result);
109+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::Criteria& pb_criteria, Criteria* criteria);
110+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::Location& pb_location, Location* location);
111+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::Ticket& pb_ticket, Ticket* ticket);
112+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::FlightData& pb_data,
113+
FlightDescriptor* descriptor,
114+
std::unique_ptr<ipc::Message>* message);
115+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::FlightDescriptor& pb_descr,
116+
FlightDescriptor* descr);
117+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::FlightEndpoint& pb_endpoint,
118+
FlightEndpoint* endpoint);
119+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::RenewFlightEndpointRequest& pb_request,
120+
RenewFlightEndpointRequest* request);
121+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::FlightInfo& pb_info,
122+
FlightInfo::Data* info);
123+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::FlightInfo& pb_info,
124+
std::unique_ptr<FlightInfo>* info);
125+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::PollInfo& pb_info, PollInfo* info);
126+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::PollInfo& pb_info,
127+
std::unique_ptr<PollInfo>* info);
128+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::CancelFlightInfoRequest& pb_request,
129+
CancelFlightInfoRequest* request);
130+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::SchemaResult& pb_result,
131+
SchemaResult* result);
132+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::BasicAuth& pb_basic_auth, BasicAuth* info);
133+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::SetSessionOptionsRequest& pb_request,
134+
SetSessionOptionsRequest* request);
135+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::SetSessionOptionsResult& pb_result,
136+
SetSessionOptionsResult* result);
137+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::GetSessionOptionsRequest& pb_request,
138+
GetSessionOptionsRequest* request);
139+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::GetSessionOptionsResult& pb_result,
140+
GetSessionOptionsResult* result);
141+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::CloseSessionRequest& pb_request,
142+
CloseSessionRequest* request);
143+
ARROW_FLIGHT_EXPORT Status FromProto(const pb::CloseSessionResult& pb_result,
144+
CloseSessionResult* result);
145+
146+
ARROW_FLIGHT_EXPORT Status ToProto(const Timestamp& timestamp,
147+
google::protobuf::Timestamp* pb_timestamp);
148+
ARROW_FLIGHT_EXPORT Status ToProto(const FlightDescriptor& descr,
149+
pb::FlightDescriptor* pb_descr);
150+
ARROW_FLIGHT_EXPORT Status ToProto(const FlightEndpoint& endpoint,
151+
pb::FlightEndpoint* pb_endpoint);
152+
ARROW_FLIGHT_EXPORT Status ToProto(const RenewFlightEndpointRequest& request,
153+
pb::RenewFlightEndpointRequest* pb_request);
154+
ARROW_FLIGHT_EXPORT Status ToProto(const FlightInfo& info, pb::FlightInfo* pb_info);
155+
ARROW_FLIGHT_EXPORT Status ToProto(const PollInfo& info, pb::PollInfo* pb_info);
156+
ARROW_FLIGHT_EXPORT Status ToProto(const CancelFlightInfoRequest& request,
157+
pb::CancelFlightInfoRequest* pb_request);
158+
ARROW_FLIGHT_EXPORT Status ToProto(const ActionType& type, pb::ActionType* pb_type);
159+
ARROW_FLIGHT_EXPORT Status ToProto(const Action& action, pb::Action* pb_action);
160+
ARROW_FLIGHT_EXPORT Status ToProto(const Result& result, pb::Result* pb_result);
161+
ARROW_FLIGHT_EXPORT Status ToProto(const CancelFlightInfoResult& result,
162+
pb::CancelFlightInfoResult* pb_result);
163+
ARROW_FLIGHT_EXPORT Status ToProto(const Criteria& criteria, pb::Criteria* pb_criteria);
164+
ARROW_FLIGHT_EXPORT Status ToProto(const Location& location, pb::Location* pb_location);
165+
ARROW_FLIGHT_EXPORT Status ToProto(const SchemaResult& result,
166+
pb::SchemaResult* pb_result);
167+
ARROW_FLIGHT_EXPORT Status ToProto(const Ticket& ticket, pb::Ticket* pb_ticket);
168+
ARROW_FLIGHT_EXPORT Status ToProto(const BasicAuth& basic_auth,
169+
pb::BasicAuth* pb_basic_auth);
170+
ARROW_FLIGHT_EXPORT Status ToProto(const SetSessionOptionsRequest& request,
171+
pb::SetSessionOptionsRequest* pb_request);
172+
ARROW_FLIGHT_EXPORT Status ToProto(const SetSessionOptionsResult& result,
173+
pb::SetSessionOptionsResult* pb_result);
174+
ARROW_FLIGHT_EXPORT Status ToProto(const GetSessionOptionsRequest& request,
175+
pb::GetSessionOptionsRequest* pb_request);
176+
ARROW_FLIGHT_EXPORT Status ToProto(const GetSessionOptionsResult& result,
177+
pb::GetSessionOptionsResult* pb_result);
178+
ARROW_FLIGHT_EXPORT Status ToProto(const CloseSessionRequest& request,
179+
pb::CloseSessionRequest* pb_request);
180+
ARROW_FLIGHT_EXPORT Status ToProto(const CloseSessionResult& result,
181+
pb::CloseSessionResult* pb_result);
165182

166183
Status ToPayload(const FlightDescriptor& descr, std::shared_ptr<Buffer>* out);
167184

cpp/src/arrow/flight/transport/grpc/customize_grpc.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "arrow/flight/platform.h"
2424
#include "arrow/flight/type_fwd.h"
25+
#include "arrow/flight/visibility.h"
2526
#include "arrow/util/config.h"
2627

2728
// Silence protobuf warnings
@@ -63,8 +64,8 @@ ::grpc::Status FlightDataSerialize(const arrow::flight::FlightPayload& msg,
6364

6465
// Read internal::FlightData from grpc::ByteBuffer containing FlightData
6566
// protobuf without copying
66-
::grpc::Status FlightDataDeserialize(::grpc::ByteBuffer* buffer,
67-
arrow::flight::internal::FlightData* out);
67+
ARROW_FLIGHT_EXPORT ::grpc::Status FlightDataDeserialize(
68+
::grpc::ByteBuffer* buffer, arrow::flight::internal::FlightData* out);
6869
} // namespace grpc
6970
} // namespace transport
7071
} // namespace flight

cpp/src/arrow/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ arrow_lib = library(
426426
include_directories: arrow_includes,
427427
dependencies: arrow_deps,
428428
install: true,
429-
gnu_symbol_visibility: 'hidden',
429+
gnu_symbol_visibility: 'inlineshidden',
430430
cpp_shared_args: ['-DARROW_EXPORTING'],
431431
)
432432

@@ -489,6 +489,7 @@ if needs_compute
489489
sources: arrow_compute_lib_sources,
490490
dependencies: arrow_dep,
491491
install: true,
492+
gnu_symbol_visibility: 'inlineshidden',
492493
cpp_shared_args: ['-DARROW_COMPUTE_EXPORTING'],
493494
)
494495
arrow_compute_dep = declare_dependency(

0 commit comments

Comments
 (0)