Re: Issues with building cpp extensions on PostgreSQL 10+

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Oleksii Kliukin <alexk(at)hintbits(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Issues with building cpp extensions on PostgreSQL 10+
Date: 2020-04-01 02:26:38
Message-ID: 20200401022638.GL17676@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Patch applied to PG 10, thanks. I don't know about your other questions,
but if you want to propose a patch, we can review it. Thanks.

---------------------------------------------------------------------------

On Fri, Mar 20, 2020 at 05:02:15PM +0100, Oleksii Kliukin wrote:
> 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
>

> diff --git a/src/Makefile.shlib b/src/Makefile.shlib
> index eb45daedc8..342496eecd 100644
> --- a/src/Makefile.shlib
> +++ b/src/Makefile.shlib
> @@ -101,6 +101,7 @@ endif
> # Try to keep the sections in some kind of order, folks...
>
> override CFLAGS += $(CFLAGS_SL)
> +override CXXFLAGS += $(CFLAGS_SL)
> ifdef SO_MAJOR_VERSION
> # libraries ought to use this to refer to versioned gettext domain names
> override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EnterpriseDB https://enterprisedb.com

+ As you are, so once was I. As I am, so you will be. +
+ Ancient Roman grave inscription +

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message movead.li@highgo.ca 2020-04-01 02:42:37 Re: recovery_target_action=pause with confusing hint
Previous Message Amit Kapila 2020-04-01 02:24:45 Re: error context for vacuum to include block number