Skip to content

Commit 1564c6d

Browse files
committed
[#28914] YSQL: link postgres's excutables with CXX instead of CC
Summary: There are multiple postgres's executable linked with various YB libraries (`-lyb_pggate_util` `-lyb_pggate`). These libraries are linked dynamically. In case of running such executables built in `ASAN` mode the `symbol lookup` error like the following may occur: ``` [2025-10-01T23:49:31.377Z] [m-1] W1001 23:49:25.568262 371043 subprocess.cc:210] [initdb] /share/jenkins/workspace/yugabyte-db-phabricator/yugabyte-db/build/asan-clang19-dynamic-ninja/postgres/bin/initdb: symbol lookup error: /opt/yb-build/thirdparty/yugabyte-db-thirdparty-v20250812204937-6c7155ea61-almalinux9-x86_64-clang19/installed/asan/lib/libprotobuf.so.32: undefined symbol: __ubsan_vptr_type_cache ``` The root cause of such error is that there is no `__ubsan_vptr_type_cache` function in executable while dynamically library use it. This function is added/used when executable/library is build (linked) with the `-fsanitize` flag. In spite of the fact postgres executables uses same set of flags (including `-fsanitize`) for building like YB's C++ library C and C++ compilers process them in different way (i.e. uses different set of auxiliary functions). To solve the issue it is required to use C++ for linking instead of C for executables which may load instrumented dynamic libraries build with C++. This approach is already used for `postgres` executable: ``` ... CCLD = $(CXX) ... postgres: $(OBJS) $(CCLD) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(LIBS) -o $@ ... ``` This diff spreads same approach on all executables which are linked (i.e. adds `-lyb_pggate*`) against YB's libraries in `Makefile`. Jira: DB-18637 Test Plan: Jenkins Reviewers: fizaa, pjain, myang, kramanathan, jason Reviewed By: jason Subscribers: jason, yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D47153
1 parent a71febe commit 1564c6d

File tree

6 files changed

+13
-13
lines changed

6 files changed

+13
-13
lines changed

src/postgres/src/Makefile.global.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
274274
LLVM_CFLAGS = @LLVM_CFLAGS@
275275
LLVM_CXXFLAGS = @LLVM_CXXFLAGS@
276276

277+
YB_CCLD = @CXX@
278+
277279
# Kind-of compilers
278280

279281
BISON = @BISON@
@@ -828,7 +830,7 @@ endif
828830
# since we put -l switches into LDFLAGS and those are order-sensitive.
829831
# In addition, include CFLAGS and LDFLAGS_EX per project conventions.
830832
%: %.o
831-
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
833+
$(YB_CCLD) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
832834

833835
ifndef PGXS
834836

src/postgres/src/backend/Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ endif
6262
# later, after initializing SHLIB_LINK.
6363
LIBS += -L$(YB_BUILD_ROOT)/lib -lyb_util -lyb_pggate -lyb_pggate_util
6464

65-
CCLD = $(CXX)
66-
6765
# Shared library configuration (see Makefile_ybpostgres.shlib -- included below)
6866
PGFILEDESC = "Postgres shared library"
6967
NAME = yb_pgbackend
@@ -103,7 +101,7 @@ ifneq ($(PORTNAME), win32)
103101
ifneq ($(PORTNAME), aix)
104102

105103
postgres: $(OBJS)
106-
$(CCLD) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(LIBS) -o $@
104+
$(YB_CCLD) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(LIBS) -o $@
107105

108106
endif
109107
endif
@@ -112,7 +110,7 @@ endif
112110
ifeq ($(PORTNAME), cygwin)
113111

114112
postgres: $(OBJS)
115-
$(CCLD) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) -Wl,--stack,$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(LIBS) -o $@
113+
$(YB_CCLD) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) -Wl,--stack,$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(LIBS) -o $@
116114

117115
# libpostgres.a is actually built in the preceding rule, but we need this to
118116
# ensure it's newer than postgres; see notes in src/backend/parser/Makefile
@@ -125,7 +123,7 @@ ifeq ($(PORTNAME), win32)
125123
LIBS += -lsecur32
126124

127125
postgres: $(OBJS) $(WIN32RES)
128-
$(CCLD) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(LIBS) -o $@$(X)
126+
$(YB_CCLD) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(LIBS) -o $@$(X)
129127

130128
# libpostgres.a is actually built in the preceding rule, but we need this to
131129
# ensure it's newer than postgres; see notes in src/backend/parser/Makefile
@@ -137,7 +135,7 @@ endif # win32
137135
ifeq ($(PORTNAME), aix)
138136

139137
postgres: $(POSTGRES_IMP)
140-
$(CCLD) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) $(LDFLAGS_EX) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
138+
$(YB_CCLD) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) $(LDFLAGS_EX) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
141139

142140
$(POSTGRES_IMP): $(OBJS)
143141
$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)

src/postgres/src/bin/initdb/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ OBJS = \
4949
all: initdb
5050

5151
initdb: $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils
52-
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
52+
$(YB_CCLD) $(CLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
5353

5454
# We must pull in localtime.c from src/timezones
5555
localtime.c: % : $(top_srcdir)/src/timezone/%

src/postgres/src/bin/pg_dump/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ LIBS += -L$(YB_BUILD_ROOT)/lib -lyb_util $(YB_PG_EXE_LD_FLAGS_AFTER_YB_LIBS)
4444
all: ysql_dump pg_restore ysql_dumpall
4545

4646
ysql_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils
47-
$(CC) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
47+
$(YB_CCLD) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
4848

4949
pg_restore: pg_restore.o $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils
50-
$(CC) $(CFLAGS) pg_restore.o $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
50+
$(YB_CCLD) $(CFLAGS) pg_restore.o $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
5151

5252
ysql_dumpall: pg_dumpall.o dumputils.o $(WIN32RES) | submake-libpq submake-libpgport submake-libpgfeutils
53-
$(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(WIN32RES) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
53+
$(YB_CCLD) $(CFLAGS) pg_dumpall.o dumputils.o $(WIN32RES) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
5454

5555
install: all installdirs
5656
$(INSTALL_PROGRAM) ysql_dump$(X) '$(DESTDIR)$(bindir)'/ysql_dump$(X)

src/postgres/src/bin/pgbench/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ LIBS += $(PTHREAD_LIBS) -lyb_util $(YB_PG_EXE_LD_FLAGS_AFTER_YB_LIBS)
2424
all: ysql_bench
2525

2626
ysql_bench: $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils
27-
$(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
27+
$(YB_CCLD) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
2828

2929
# exprscan is compiled as part of exprparse
3030
exprparse.o: exprscan.c

src/postgres/src/makefiles/pgxs.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,5 +472,5 @@ endif
472472

473473
ifdef PROGRAM
474474
$(PROGRAM): $(OBJS)
475-
$(CC) $(CFLAGS) $(OBJS) $(PG_LIBS_INTERNAL) $(LDFLAGS) $(LDFLAGS_EX) $(PG_LIBS) $(LIBS) -o $@$(X)
475+
$(YB_CCLD) $(CFLAGS) $(OBJS) $(PG_LIBS_INTERNAL) $(LDFLAGS) $(LDFLAGS_EX) $(PG_LIBS) $(LIBS) -o $@$(X)
476476
endif

0 commit comments

Comments
 (0)