MallocExtension declaration in tcmalloc_extension.h blocks UBSAN build
- Dominant language
- C++
- Stars
- 17.6k
- Forks
- 4.1k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 69
Description
**Describe the bug (描述bug)**
[`MallocExtension`](https://github.com/apache/incubator-brpc/blob/dfe659ba364ab2ff59f94c70418d429904f2194f/src/brpc/details/tcmalloc_extension.h#L72) declaration in `brpc/details/tcmalloc_extension.h` is a (potentially mismatching) copy of `malloc_extension.h` provided by `google-perftools` package.
I understand that BRPC **intentially** left it there with no virtual methods defined, hoping provided by linking `libtcmalloc.so` provided by `google-perftools` package. Otherwise (_i.e._ when linking `jemalloc` or using default implementation), `MallocExtension` has no key function.
We can call it _WAI_ in most scenarios, but when not linking `tcmalloc` and in UBSAN build, a linking failure regarding `undefined reference to 'typeinfo for MallocExtension'` persists.
Moreover, the modern `tcmalloc` (greatly different from the one provided by `google-perftools` package) has a totally different definition of `MallocExtension`, so evening linking _this_ `tcmalloc` won't help.
I know that we can workaround this issue by `fno-sanitize=vptr`, but since `MallocExtension` is the **only** problematic type blocking linking, I would consider it's not worth the regression.
**To Reproduce (复现方法)**
Build a binary depending on `brpc` in UBSAN mode.
**Expected behavior (期望行为)**
Successful UBSAN build.
**Versions (各种版本)**
OS: Ubuntu 22.04
Compiler: Clang 12.0.1
brpc: 1.2.0
protobuf: 21.1
**Additional context/screenshots (更多上下文/截图)**
Pending.
Contributor guide
Research direction
Start with src/brpc/details/tcmalloc_extension.h, especially the MallocExtension declaration, and reproduce the link failure by building a brpc-dependent binary in UBSAN mode with the stated Ubuntu, Clang, and brpc versions. Compare the declaration with the google-perftools and modern tcmalloc definitions mentioned in the report. Done means the UBSAN build links successfully without requiring the fno-sanitize=vptr workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100