Opened 3 hours ago

Last modified 2 hours ago

#71052 new defect

llvm-19 @19.1.1: possibly rpath-related problems on macOS Sequoia

Reported by: tglsfdc (Tom Lane) Owned by:
Priority: Normal Milestone:
Component: ports Version: 2.10.2
Keywords: Cc:
Port: llvm-19

Description

I'm having difficulty building postgresql with LLVM support (configure option --with-llvm) on Sequoia + Xcode 16.0, though it worked fine on previous macOS versions. Problem number one is a weird linker warning at build time:

ccache clang -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -Wmissing-variable-declarations -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -Wno-format-truncation -Wno-cast-function-type-strict -g -O2 ...lots-of-.o-files-here... -L../../src/port -L../../src/common -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk  -L/opt/local/libexec/llvm-19/lib  -Wl,-dead_strip_dylibs   -Wl,-export_dynamic -lz -lm -L/opt/local/lib -licui18n -licuuc -licudata -o postgres

ld: warning: reexported library with install name '@rpath/libunwind.1.dylib' found at '/opt/local/libexec/llvm-19/lib/libunwind.1.0.dylib' couldn't be matched with any parent library and will be linked directly

This is weird because so far as I can see, there's no reason for that library to be pulled into this link. There's no -lunwind in the command, nor do we use any of the APIs exported by that library. (We do use backtrace() and backtrace_symbols(), if that's relevant.) For that matter, the core server executable doesn't reference any LLVM stuff at all; all of that is in a separate loadable library that is not what this command is building. I've verified that removing -L/opt/local/libexec/llvm-19/lib from this link command silences the warning, but what's causing it?

Problem number two is that the built LLVM library fails at runtime, with

ERROR:  could not load library "/Users/tgl/pgsql/lib/postgresql/llvmjit.dylib": dlopen(/Users/tgl/pgsql/lib/postgresql/llvmjit.dylib, 0x000A): Library not loaded: @rpath/libLLVM.dylib
          Referenced from: <554524D2-EA18-38B0-9475-F9275F1A2822> /Users/tgl/pgsql/lib/postgresql/llvmjit.dylib
          Reason: no LC_RPATH's found

I gathered from some other tickets that the reason for this is a lack of a linker -rpath switch, and indeed if I add -Wl,-rpath,/opt/local/libexec/llvm-19/lib to the LDFLAGS then this problem goes away. However, I argue that this is LLVM's fault not postgresql's fault, because (a) llvm-config --ldflags mentions no such requirement, and (b) this all worked fine without that before Sequoia.

This is not specific to llvm-19; I get the same results with llvm-18. I've tried building with both the Apple-supplied clang and clang from MacPorts, no difference.

Change History (1)

comment:1 Changed 2 hours ago by tglsfdc (Tom Lane)

Forgot to mention that adding -Wl,-rpath,... does not silence the whining about libunwind, which makes that even odder.

Note: See TracTickets for help on using tickets.