Skip to content

Commit

Permalink
Make sure folly's memcpy/memset not replaced by glibc's implementation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
helloguo authored and facebook-github-bot committed Jul 6, 2024
1 parent ac93e22 commit b0d11fa
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions folly/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ cpp_library(
],
},
compiler_flags = roar_no_jit(),
link_whole = True, # Set link_whole to force linker to use __folly_memset
modular_headers = False,
exported_deps = select({
"DEFAULT": [],
Expand Down Expand Up @@ -889,6 +890,7 @@ cpp_library(
],
},
compiler_flags = roar_no_jit(),
link_whole = True, # Set link_whole to force linker to use __folly_memcpy
modular_headers = False,
exported_deps = select({
"DEFAULT": [],
Expand Down

0 comments on commit b0d11fa

Please sign in to comment.