lpsmith / postgresql-libpq

Low-level Haskell bindings for libpq
BSD 3-Clause "New" or "Revised" License
19 stars 18 forks source link

Avoid segfaults on Windows when linking against official PostgreSQL distribution #45

Closed RyanGlScott closed 6 years ago

RyanGlScott commented 6 years ago

Due to https://sourceware.org/bugzilla/show_bug.cgi?id=22948, if we specify extra-libraries: pq instead of extra-libraries: libpq within postgresql-libpq.cabal, then if you attempt to build postgresql-libpq against the official PostgreSQL distribution for Windows, then ld will link against libpq.dll directly (instead of the import library, libpq.lib). This can lead to segfaults, as libpq.dll will truncate R_X86_64_PC32 relocations.

As a (hopefully temporary) hack, we avoid this issue by forcing ld to link against the libpq.lib import library directly by specifying extra-libraries: libpq on Windows. I've confirmed that this works with both the official Windows PostgreSQL distribution as well as the MinGW-w64 version.

This should fix https://github.com/lpsmith/postgresql-libpq/issues/43.

lpsmith commented 6 years ago

Thanks, even if I had access to a windows box at the moment, it would have probably taken me considerable effort to diagnose and fix this issue.