Thread: PG_CFLAGS rpath Passthrough Issue

PG_CFLAGS rpath Passthrough Issue

From
"David E. Wheeler"
Date:
Hello Hackers,

I'm trying to compile an extension with PG_CFLAGS1[1]:

```sh
make PG_CFLAGS='-Wl,-rpath,$ORIGIN'
```

This works, but for some reason the rpath value is truncated:

```console
# chrpath -l src/semver.so
src/semver.so: RUNPATH=RIGIN
```

Do I need to do something different to include the missing characters `$O`? Or is there an issue with the quoting of
thesevariables in PGXS? 

Thanks,

David

[1]: https://github.com/postgres/postgres/blob/c7fc880/src/makefiles/pgxs.mk#L58


Attachment

Re: PG_CFLAGS rpath Passthrough Issue

From
Laurenz Albe
Date:
On Fri, 2025-03-14 at 12:58 -0400, David E. Wheeler wrote:
> I'm trying to compile an extension with PG_CFLAGS1[1]:
>
> ```sh
> make PG_CFLAGS='-Wl,-rpath,$ORIGIN'
> ```
>
> This works, but for some reason the rpath value is truncated:
>
> ```console
> # chrpath -l src/semver.so
> src/semver.so: RUNPATH=RIGIN
> ```
>
> Do I need to do something different to include the missing characters `$O`? Or is there an issue with the quoting of
thesevariables in PGXS? 

It is a quoting issue.

Trial and error showed my that the following works:

  make CFLAGS='-Wl,-rpath,\$$ORIGIN'

... at least when I run it on the shell.  Putting it into an RPM spec file
might require more escaping, no idea.

Yours,
Laurenz Albe



Re: PG_CFLAGS rpath Passthrough Issue

From
"David E. Wheeler"
Date:
On Mar 14, 2025, at 17:13, Laurenz Albe <laurenz.albe@cybertec.at> wrote:

> It is a quoting issue.
>
> Trial and error showed my that the following works:
>
>  make CFLAGS='-Wl,-rpath,\$$ORIGIN'
>
> ... at least when I run it on the shell.  Putting it into an RPM spec file
> might require more escaping, no idea.

Confirmed, this works, thank you.

But, just. WAT. 30 years in this business and shell string escaping continues to elude me. I tried lots of different
combinationsof escaping, but this weird double-$ never occurred to me. 

Best,

David
Attachment

Re: PG_CFLAGS rpath Passthrough Issue

From
Álvaro Herrera
Date:
On 2025-Mar-14, David E. Wheeler wrote:

> But, just. WAT. 30 years in this business and shell string escaping
> continues to elude me. I tried lots of different combinations of
> escaping, but this weird double-$ never occurred to me.

It's make.  From its info manual:

 6.1 Basics of Variable References

   To substitute a variable’s value, write a dollar sign followed by the name
   of the variable in parentheses or braces: either ‘$(foo)’ or ‘${foo}’ is a
   valid reference to the variable foo. This special significance of
   ‘$’ is why you must write ‘$$’ to have the effect of a single dollar sign in
   a file name or recipe.

I'm surprised that you don't need \$\$ though.  I wonder if
  make CFLAGS='-Wl,-rpath,$$ORIGIN'
isn't enough actually?

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"Learn about compilers. Then everything looks like either a compiler or
a database, and now you have two problems but one of them is fun."
            https://twitter.com/thingskatedid/status/1456027786158776329



Re: PG_CFLAGS rpath Passthrough Issue

From
"David E. Wheeler"
Date:
On Mar 15, 2025, at 07:58, Álvaro Herrera <alvherre@alvh.no-ip.org> wrote:

> It's make.  From its info manual:

Oh, that explains it. It hadn’t occurred to me that make could eval strings passed to it like that, but of course it
does.
>
> I'm surprised that you don't need \$\$ though.  I wonder if
>  make CFLAGS='-Wl,-rpath,$$ORIGIN'
> isn't enough actually?

Oddly, no:

# make CFLAGS='-Wl,-rpath,$$ORIGIN'
# chrpath src/semver.so
src/semver.so: RUNPATH=

Gotta have the backslash.

Best,

David


Attachment