Building Extension on Linux fails with relocation error

From: Binaek Sarkar <binaek(at)turbot(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: Kai Daguerre <kai(at)turbot(dot)com>, Binaek Sarkar <binaek89(at)gmail(dot)com>
Subject: Building Extension on Linux fails with relocation error
Date: 2023-12-21 08:28:16
Message-ID: CAAi87c1LHt54DaOGpuAMW2cXygU63v6W2-kEq6OYGjfYnKLzkQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am new to PostgreSQL extension development and am currently working on
the *steampipe-postgres-fdw* project.

This is a *Foreign Data Wrapper (FDW) written in Go*, and while I have
successfully built it on Darwin systems, I am facing challenges when
building on Linux, particularly with *pgxs.mk <http://pgxs.mk>* against
PostgreSQL 14.

The issue arises with a Go module that is compiled into a .a archive file
using -buildmode=c-archive, leading to a *file size of approximately 393 MB*.
During the build process using *pgxs.mk <http://pgxs.mk>*, I encounter
several errors related to relocation and DWARF debug information, such as:

/usr/bin/ld: steampipe_postgres_fdw.a(go.o): relocation
R_AARCH64_ADR_PREL_PG_HI21 against symbol `type:string' which may bind
externally can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: DWARF error: line info data is bigger (0x65f0639) than the
space remaining in the section (0xe86ef9)
...

The log is for aarch64 - but I am getting similar errors for amd64 as well

Interestingly, the *build completes successfully when the .a file is
smaller* (around 100 MB).

As someone new to this area, I am a bit unclear on the following points:

- Best practices for compiling Go code for PostgreSQL FDWs on Linux
with *pgxs.mk
<http://pgxs.mk>*, especially regarding *-fPIC* and managing large
archive file sizes.
- Understanding and resolving the relocation and DWARF errors in the
context of PostgreSQL extension development.
- Any known issues or special considerations for building Go-based FDWs
for PostgreSQL 14 on Linux.

Any advice, insights, or pointers to relevant resources from the community
will be helpful.

Thank you for your time and assistance.

I am attaching a minimal piece of code to be able to reproduce - although
> the *go toolchain* is required

Best regards,
Binaek Sarkar

Attachment Content-Type Size
fdw.zip application/zip 16.8 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrien Nayrat 2023-12-21 10:36:38 Re: "invalid contrecord" error on replica
Previous Message Thomas Munro 2023-12-21 06:50:11 Re: How to generate random bigint