Skip to content

Ruby: wrap calls to memcpy so that gem is compatible with pre-2.14 glibc#2804

Merged
acozzette merged 1 commit intoprotocolbuffers:masterfrom
acozzette:ruby-memcpy
Mar 9, 2017
Merged

Ruby: wrap calls to memcpy so that gem is compatible with pre-2.14 glibc#2804
acozzette merged 1 commit intoprotocolbuffers:masterfrom
acozzette:ruby-memcpy

Conversation

@acozzette
Copy link
Copy Markdown

This commit adds a __wrap_memcpy function and a linker flag to use that
in place of memcpy for our Ruby gem C extension. This allows us to
always use the 2.2.5 version of memcpy, making it possible to use the
gem on distributions with pre-2.14 versions of glibc.

Before this change:
$ objdump -T protobuf_c.so | grep memcpy
0000000000000000 DF UND 0000000000000000 GLIBC_2.3.4 __memcpy_chk
0000000000000000 DF UND 0000000000000000 GLIBC_2.14 memcpy

After:
$ objdump -T protobuf_c.so | grep memcpy
0000000000000000 DF UND 0000000000000000 GLIBC_2.2.5 memcpy
0000000000000000 DF UND 0000000000000000 GLIBC_2.3.4 __memcpy_chk
0000000000042450 g DF .text 0000000000000005 Base __wrap_memcpy

This is based on gRPC's solution to a similar problem:
https://github.com/grpc/grpc/blob/5098508d2d41a116113f7e333c516cd9ef34a943/src/core/lib/support/wrap_memcpy.c
However, we have not so far run into any issues with callers using
memcpy when they should be using memmove, so in this commit I did not
add anything to redirect memcpy to memmove.

This fixes issue #2783.

@acozzette
Copy link
Copy Markdown
Author

@haberman @nicolasnoble Does this look ok?

@nicolasnoble
Copy link
Copy Markdown
Contributor

The point of the memmove call is to provide an alternative to the "x86_64" case; if someone builds that code on linux that isn't Intel 64 bits, the resolution of the _wrap_memcpy symbol won't happen and you'll get a linker error.

@nicolasnoble
Copy link
Copy Markdown
Contributor

Also, you should only add the LDFLAGS if the OS is Linux.

@acozzette
Copy link
Copy Markdown
Author

Thanks @nicolasnoble, I went ahead and made those fixes. I was thinking I would actually prefer to use __real_memcpy (which points to the "real" memcpy) in the Linux, non-x86-64 case, but I found that wrapping __real_memcpy mysteriously causes this test case to segfault. I'd like to figure out why that is, but for now I just set it up to use memmove.

This commit adds a __wrap_memcpy function and a linker flag to use that
in place of memcpy for our Ruby gem C extension. This allows us to
always use the 2.2.5 version of memcpy, making it possible to use the
gem on distributions with pre-2.14 versions of glibc.

Before this change:
$ objdump -T protobuf_c.so | grep memcpy
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.3.4 __memcpy_chk
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.14  memcpy

After:
$ objdump -T protobuf_c.so | grep memcpy
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 memcpy
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.3.4 __memcpy_chk
0000000000042450 g    DF .text  0000000000000005  Base __wrap_memcpy

This is based on gRPC's solution to a similar problem:
https://github.com/grpc/grpc/blob/5098508d2d41a116113f7e333c516cd9ef34a943/src/core/lib/support/wrap_memcpy.c

This fixes issue protocolbuffers#2783.
@haberman
Copy link
Copy Markdown
Member

haberman commented Mar 9, 2017

LGTM.

@acozzette acozzette merged commit bbfb9d5 into protocolbuffers:master Mar 9, 2017
@acozzette acozzette deleted the ruby-memcpy branch March 9, 2017 22:30
copybara-service Bot pushed a commit that referenced this pull request Jun 26, 2025
This shim was added in 2017 to make binary gems compatible with pre-2.14 glibc: #2804

glibc 2.14 was released in 2011.  Our Python wheels build for manylinux 2014, which requires glibc 2.17 or later: https://github.com/pypa/manylinux?tab=readme-ov-file#manylinux2014-centos-7-based-glibc-217

We should no longer need binary compatibility with a 14-year-old glibc.

Fixes: #11935
PiperOrigin-RevId: 776175307
copybara-service Bot pushed a commit that referenced this pull request Jun 26, 2025
This shim was added in 2017 to make binary gems compatible with pre-2.14 glibc: #2804

glibc 2.14 was released in 2011.  Our Python wheels build for manylinux 2014, which requires glibc 2.17 or later: https://github.com/pypa/manylinux?tab=readme-ov-file#manylinux2014-centos-7-based-glibc-217

We should no longer need binary compatibility with a 14-year-old glibc.

Fixes: #11935
PiperOrigin-RevId: 776175307
copybara-service Bot pushed a commit that referenced this pull request Jun 26, 2025
This shim was added in 2017 to make binary gems compatible with pre-2.14 glibc: #2804

glibc 2.14 was released in 2011.  Our Python wheels build for manylinux 2014, which requires glibc 2.17 or later: https://github.com/pypa/manylinux?tab=readme-ov-file#manylinux2014-centos-7-based-glibc-217

We should no longer need binary compatibility with a 14-year-old glibc.

Fixes: #11935
PiperOrigin-RevId: 776288819
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants