AnDiXL opened a new pull request, #3698:
URL: https://github.com/apache/brpc/pull/3698

   ### What problem does this PR solve?
   
   `ResourcePool`, `ObjectPool`, their `LocalPool` and `SocketPool` are 
declared with `BAIDU_CACHELINE_ALIGNMENT` and created with plain `new`. C++17 
uses the aligned `operator new` for them. C++14 builds don't, and glibc then 
returns only 16-byte aligned storage. CMake and `config_brpc.sh` both pick 
C++14 when protobuf < 22.
   
   On Ubuntu 22.04 with Clang 14, this crashes client connects in 
`Socket::ResetFileDescriptor` (`_transport` is null). It reproduces 3/3 with 
the FlatBuffers protocol tests in #3559. Rebuilding only `socket.cpp` with 
`-faligned-new` or `-std=gnu++17` fixes it, and `-std=gnu++17 -fno-aligned-new` 
brings the crash back. GCC 11 in C++14 mode misaligns these objects the same 
way, but it did not crash in those tests.
   
   ### What is changed and the side effects?
   
   - CMake and `config_brpc.sh` pass `-faligned-new` when the compiler accepts 
it. Bazel already builds with C++17 and is unchanged.
   - New test `ResourcePoolTest.plain_new_honors_cacheline_alignment` fails 
when aligned new is not in effect.
   - C++17 builds are unaffected. C++14 builds now need a C++ runtime that 
provides aligned `operator new`: libstdc++ from GCC 7, or libc++.
   
   ### Tests
   
   Ubuntu 22.04 Clang 14: the new test passes, and fails with 
`-DBRPC_HAS_ALIGNED_NEW=OFF`. `config_brpc.sh` with Clang 14 and GCC 11 
produces `-std=c++14 -faligned-new`. macOS Apple clang 15 detects the flag.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to