Issues with building cpp extensions on PostgreSQL 10+

From: Oleksii Kliukin <alexk(at)hintbits(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Issues with building cpp extensions on PostgreSQL 10+
Date: 2020-03-20 16:02:15
Message-ID: E4A49A6B-621B-4830-A374-970EBB7D1328@hintbits.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

I’ve recently tried to build an extension that employs C++ files and also
passes them to a linker to make a shared library. I’ve discovered a few
issues with them:

- in v10 CFLAGS_SL is not appended to the CXXFLAGS in Makefile.shlib,
resulting in cpp files compiled without -fPIC, leading to errors when
creating the shared library out of them. In v11 and above CFLAGS_SL is
prepended to the PG_CXXFLAGS, but there are no PG_CXXFLAGS on v10, and the
Makefile does nothing to add them to CXXFLAGS. Patch is attached.

- not just with v10, when building bc files from cpp, there are no CXXFLAGS
passed; as a result, when building a source with non-standard flags (i.e
-std=c++11) one would get an error during building of bc files.

The rules in the Makefile.global.(in) look like:

ifndef COMPILE.c.bc
# -Wno-ignored-attributes added so gnu_printf doesn't trigger
# warnings, when the main binary is compiled with C.
COMPILE.c.bc = $(CLANG) -Wno-ignored-attributes $(BITCODE_CFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
endif

ifndef COMPILE.cxx.bc
COMPILE.cxx.bc = $(CLANG) -xc++ -Wno-ignored-attributes $(BITCODE_CXXFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
endif

%.bc : %.c
$(COMPILE.c.bc) -o $@ $<

%.bc : %.cpp
$(COMPILE.cxx.bc) -o $@ $<

However, there seems to be no way to override BITCODE_CXXFLAGS to include
any specific C++ compilation flags that are also required to build object
files from cpp. Same applies to .bc derived from .c files with
BITCODE_CFLAGS respectively.

I am wondering if we could define something like PG_BITCODE_CXXFLAGS and
PG_BITCODE_CFLAGS in pgxs.mk to be able to override those. If this sound
like a right strategy, I’ll prepare a patch.

Cheers,
Oleksii “Alex” Kluukin

Attachment Content-Type Size
cxxflags_shared_libraries_pg10.diff application/octet-stream 454 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Li, Zheng 2020-03-20 16:05:59 Correlated IN/Any Subquery Transformation
Previous Message Corey Huinker 2020-03-20 15:48:24 Re: Add A Glossary