Skip to content

multiple definition of InstallSymbolizeOpenObjectFileCallback when linking with glog #3063

@wangrufeng

Description

@wangrufeng

Describe the bug

When compiling brpc with glog, the linker reports:

> Linking protoc-gen-mcpack
g++ -o protoc-gen-mcpack -std=c++0x -DBRPC_WITH_GLOG=1 -DGFLAGS_NS=google -D__const__=__unused__ -g -DBTHREAD_USE_FAST_PTHREAD_MUTEX -D_GNU_SOURCE -DUSE_SYMBOLIZE -DNO_TCMALLOC -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DNDEBUG -DBRPC_REVISION=\"1.10.0\|HEAD\|75763d4c\|2024-07-23T10:25:56+08:00\" -O2 -pipe -Wall -W -fPIC -fstrict-aliasing -Wno-invalid-offsetof -Wno-unused-parameter -fno-omit-frame-pointer -Wno-aligned-new -I./src -I/usr/include/ -L/usr/lib64 -Xlinker "-(" src/idl_options.pb.cc src/mcpack2pb/generator.o libbrpc.a -Wl,-Bstatic -lprotobuf -lprotoc -lglog -Wl,-Bdynamic -Xlinker "-)" -lpthread -lssl -lcrypto -ldl -lz -lrt -lgflags -lleveldb
> Copying to output/include
> Copying to output/lib
libbrpc.a(symbolize.o): In function `google::InstallSymbolizeOpenObjectFileCallback(int (*)(unsigned long, unsigned long&, unsigned long&, char*, int))':
brpc/src/butil/third_party/symbolize/symbolize.cc:90: multiple definition of `google::InstallSymbolizeOpenObjectFileCallback(int (*)(unsigned long, unsigned long&, unsigned long&, char*, int))'
/usr/lib64/libglog.a(symbolize.cc.o):(.text+0x1f): first defined here

Root Cause:

  • This issue was may be related to changes in PR Fix malloc deadlock caused by contention profiler #2684 (测试在该commit前的代码可链接通过,之后的会出现该问题)
  • InstallSymbolizeOpenObjectFileCallback() in src/butil/third_party/symbolize/symbolize.cc is not marked as BAIDU_WEAK, causing a symbol conflict with glog

To Reproduce

  1. Build brpc >=1.10 with glog (-lglog).
  2. Observe linker error due to duplicate symbol.

Expected behavior

Mark InstallSymbolizeOpenObjectFileCallback() as BAIDU_WEAK to prevent symbol collision

Versions
OS: Anolis OS 8.6
Compiler: 8.5.0 20210514
brpc: >=1.10
glog: 0.5.0
protobuf: 3.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions