Skip to content

Commit b0d11fa

Browse files
helloguofacebook-github-bot
authored andcommitted
Make sure folly's memcpy/memset not replaced by glibc's implementation
Summary: `__folly_memcpy` and `__folly_memset` are supposed to be used in prod. However, they may be replaced by libc's implementation when `link_group_map` is used. The issue comes from two places: (1) The `link_group_map` may cause "folly/__memcpy-use__/__objects__/memcpy.S.o" to be put after "libc.so" in the xxx.thinlto.index.argsfile. (2) Even if "folly/__memcpy-use__/__objects__/memcpy.S.o" comes before "libc.so", `__folly_memcpy` may still be replaced by libc's implementation in some cases. For example: if there's no reference to `memcpy` before "folly/__memcpy-use__/__objects__/memcpy.S.o", the symbol `memcpy` inside memcpy.S.o is considered to be a lazy symbol, which will be replaced by the definition inside "libc.so". To make sure `__folly_memcpy` and `__folly_memset` are linked, this diff sets link_whole for cpp_library memcpy-use and memset-use. Because memcpy-use and memset-use only contain the necessary symbols, link_whole doesn't cause size bloat. Reviewed By: WenleiHe Differential Revision: D58921357 fbshipit-source-id: f5c7161dda24edd1ac808042715931d9b8dfaf10
1 parent ac93e22 commit b0d11fa

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

folly/BUCK

+2
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ cpp_library(
814814
],
815815
},
816816
compiler_flags = roar_no_jit(),
817+
link_whole = True, # Set link_whole to force linker to use __folly_memset
817818
modular_headers = False,
818819
exported_deps = select({
819820
"DEFAULT": [],
@@ -889,6 +890,7 @@ cpp_library(
889890
],
890891
},
891892
compiler_flags = roar_no_jit(),
893+
link_whole = True, # Set link_whole to force linker to use __folly_memcpy
892894
modular_headers = False,
893895
exported_deps = select({
894896
"DEFAULT": [],

0 commit comments

Comments
 (0)