Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use C++ compiler for linking #3766

Merged
merged 1 commit into from
Dec 15, 2023
Merged

Conversation

gjasny
Copy link
Contributor

@gjasny gjasny commented Nov 6, 2023

When building with Clang and enabled Sanitizer for Undefined Behavior it is important to use the C++ (and not the C) compiler to drive linking.

Otherwise linking fails with errors like:

/usr/bin/ld: output/pjsua2-test-x86_64-unknown-linux-gnu/main.o: in function `main':
main.cpp:(.text+0xaa): undefined reference to `__ubsan_vptr_type_cache'

To reproduce use something like that:

export CC="/usr/lib/llvm-14/bin/clang"
export CXX="/usr/lib/llvm-14/bin/clang++"
export CPPFLAGS="$CPPFLAGS -DNDEBUG"
export CXXFLAGS="$CXXFLAGS -stdlib=libstdc++ -std=gnu++17 -m64 -fPIC -O3 -fsanitize=undefined"
export CFLAGS="$CFLAGS -m64 -fPIC -O3 -fsanitize=undefined"
export LDFLAGS="$LDFLAGS -m64 -fsanitize=undefined"

./configure --disable-shared --enable-static --enable-epoll --disable-sound --disable-video --disable-speex-aec --disable-l16-codec --disable-gsm-codec --disable-g7221-codec --disable-speex-codec --disable-ilbc-codec --disable-sdl --disable-ffmpeg --disable-v4l2 --disable-openh264 --disable-opencore-amr --disable-silk --disable-opus --disable-bcg729 --disable-libyuv --disable-libwebrtc
make -C pjsip/build pjsua2-test -j24

When building with Clang and enabled Sanitizer for Undefined
Behavior it is important to use the C++ (and not the C) compiler
to drive linking.

Otherwise linking fails with errors like:

```
/usr/bin/ld: output/pjsua2-test-x86_64-unknown-linux-gnu/main.o: in function `main':
main.cpp:(.text+0xaa): undefined reference to `__ubsan_vptr_type_cache'
```

To reproduce use something like that:
```
export CC="/usr/lib/llvm-14/bin/clang"
export CXX="/usr/lib/llvm-14/bin/clang++"
export CPPFLAGS="$CPPFLAGS -DNDEBUG"
export CXXFLAGS="$CXXFLAGS -stdlib=libstdc++ -std=gnu++17 -m64 -fPIC -O3 -fsanitize=undefined"
export CFLAGS="$CFLAGS -m64 -fPIC -O3 -fsanitize=undefined"
export LDFLAGS="$LDFLAGS -m64 -fsanitize=undefined"

./configure --disable-shared --enable-static --enable-epoll --disable-sound --disable-video --disable-speex-aec --disable-l16-codec --disable-gsm-codec --disable-g7221-codec --disable-speex-codec --disable-ilbc-codec --disable-sdl --disable-ffmpeg --disable-v4l2 --disable-openh264 --disable-opencore-amr --disable-silk --disable-opus --disable-bcg729 --disable-libyuv --disable-libwebrtc
make -C pjsip/build pjsua2-test -j24
```
@sauwming
Copy link
Member

Since the issue only happened when someone is using sanitizer, and the sanitiser setup requires a lot of configuration anyway, why is it not the user's responsibility to ensure that it works?

i.e. why not the user just add one more:
export LD=$CXX

@gjasny
Copy link
Contributor Author

gjasny commented Dec 15, 2023

Because the error is within the pjproject realm. You must not use a C compiler to link C++ code.

@sauwming sauwming merged commit 48f3723 into pjsip:master Dec 15, 2023
28 of 34 checks passed
xhit pushed a commit to xhit/pjproject that referenced this pull request Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants