Re: [PATCH] lto.inc: add DEBUG_PREFIX_MAP back to TARGET_LDFLAGS

Richard Purdie
2026-02-04T09:34:46Z

On Wed, 2026-02-04 at 13:26 +0800, changqing.li@windriver.com wrote:
> From: Changqing Li <changqing.li@windriver.com>
>
> DEBUG_PREFIX_MAP is appended to TARGET_LDFLAGS in commit [1] for fixing
> reproducible issue when LTO is enabled. It is removed in comit [2] since
> this commit causes cgo binary not reproducible. But actually, we still
> need this DEBUG_PREFIX_MAP in LDFLAGS when LTO enabled. So, only appened
> it when LTO is enabled. Refer [3] for the history, with this patch,
> patch [4] is also needed for cgo + lto enabled.
>
> [1] https://git.openembedded.org/openembedded-core/commit/?id=fddaecc88979967d0e00e2fafdbaaabec030da9f
> [2] https://git.openembedded.org/openembedded-core/commit/?id=1797741aad02b8bf429fac4b81e30cdda64b5448
> [3] https://lists.openembedded.org/g/openembedded-core/topic/patch_bitbake_conf_remove/117408334
> [4] https://lists.openembedded.org/g/openembedded-core/message/230059
>
> Signed-off-by: Changqing Li <changqing.li@windriver.com>
> ---
>  meta/conf/distro/include/lto.inc | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/meta/conf/distro/include/lto.inc b/meta/conf/distro/include/lto.inc
> index 227f0c5c2a..cef92901e3 100644
> --- a/meta/conf/distro/include/lto.inc
> +++ b/meta/conf/distro/include/lto.inc
> @@ -49,5 +49,6 @@ LTO:toolchain-clang = "${@bb.utils.contains('DISTRO_FEATURES', 'thin-lto', '-flt
>
>  SELECTED_OPTIMIZATION:append = "${@bb.utils.contains('DISTRO_FEATURES', 'lto', ' ${LTO}', '', d)}"
>  TARGET_LDFLAGS:append:class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'lto', ' ${LTO}', '', d)}"
> +TARGET_LDFLAGS:append:class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'lto', ' ${DEBUG_PREFIX_MAP}', '', d)}"
>
>  SELECTED_OPTIMIZATION[vardeps] += "LTO LTOEXTRA"

We need a bit more information. Which version of gcc did you see this issue with?

gcc see this as a bug, for example they added this to fix it:

https://gcc.gnu.org/cgit/gcc/commit/?id=7cc2df084b7977653a9b59cbc34a9ad500ae619c

In:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101473#c21

"I think it is a bug - -fdebug-prefix-map should be fully reflected in
the LTO IL and thus we should not end up creating un-remapped
references to files (we should not create many references to files late
anyway)."

i.e. it is a bug if we have to set this in LDFLAGS if I understand
correctly. So we should file a bug with gcc about this, assuming you
were using gcc 12 or later.

Cheers,

Richard