Re: LTO aggressively optimizing out function despite explicit calls in logical decoding

From: Andres Freund <andres(at)anarazel(dot)de>
To: Arkady Skvorcov <arkashaskv(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: LTO aggressively optimizing out function despite explicit calls in logical decoding
Date: 2025-11-07 15:10:19
Message-ID: qic7zk26o4rujrtetiduzcloajjxkbdsxs2xmfuojq6g23wbgr@ic4oldvznli2
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2025-11-06 11:39:03 +0400, Arkady Skvorcov wrote:
> I'm working on a logical decoding improvement and running into a persistent
> build issue where LTO (-flto=thin) is optimizing out my LogicalWaitForWal
> function, even though there are explicit calls to it.
>
> The situation:
>
> Function LogicalWaitForWal() is defined in
> src/backend/replication/logical/logical.c
>
> It's called directly from logical_read_xlog_page_cv() in the same file
>
> logical_read_xlog_page_cv is assigned as the page_read callback via
> XL_ROUTINE in multiple places in logical.c
>
> The function appears in the object file (nm logical.o shows it)
>
> But it's completely absent from the final binary (nm postgres shows nothing)

Presumably what is happening is that it is inlined into the caller(s)?

> Is there a PostgreSQL-specific pattern or macro I should be using to ensure
> functions aren't optimized out when they're called via function pointers
> assigned in structs?

What problem is this actually causing for you?

Greetings,

Andres Freund

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-11-07 15:14:55 Re: Reorganize GUC structs
Previous Message Bertrand Drouvot 2025-11-07 15:03:03 Re: Consistently use the XLogRecPtrIsInvalid() macro