diff mbox series

[2/2] bitbake.conf: Switch prefix mapping to use -ffile-prefix-map

Message ID 20250418175911.4033750-2-raj.khem@gmail.com
State Accepted, archived
Commit ff73fa7ef7666a6dbe34f15515bc3ab6e574c5b0
Headers show
Series [v2,1/2] glibc: Forward -ffile-prefix-map option to assembler flags | expand

Commit Message

Khem Raj April 18, 2025, 5:59 p.m. UTC
-ffile-prefix map is more comprehensive when it comes to reproducible
builds and its superset of all prefix-mapping options in compilers

This makes is cleaner and workable across gcc and clang, clang does not
support -fcanon-prefix-map and it has to be explicitly omitted when using
clang.

There are lambdas generated in templates by clang which still get the
absolute paths despite -fdebug-prefix-map, this helps with that as well.

nasm is an outlier and we have fixed it by adding -fdebug-prefix-map option
luckily we do not pass DEBUG_PREFIX_MAP to nasm, in all recipes which use
nasm either pass -fdebug-prefix-map explicitly to nasm or they rewrite it
to use nasm flags syntax.

We have discussed this in past [1]

[1] https://patchwork.yoctoproject.org/project/oe-core/patch/20230428032030.2047920-1-raj.khem@gmail.com/#10281

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Cc: Jacob Kroon <jacob.kroon@gmail.com>
Cc: Martin Jansa <Martin.Jansa@gmail.com>
---
v2: Drop using --ffile-prefix in go

 meta/conf/bitbake.conf                     | 14 +++++---------
 meta/recipes-devtools/rust/cargo_1.85.1.bb |  2 +-
 2 files changed, 6 insertions(+), 10 deletions(-)

Comments

Richard Purdie April 21, 2025, 12:29 p.m. UTC | #1
On Fri, 2025-04-18 at 10:59 -0700, Khem Raj via lists.openembedded.org wrote:
> -ffile-prefix map is more comprehensive when it comes to reproducible
> builds and its superset of all prefix-mapping options in compilers
> 
> This makes is cleaner and workable across gcc and clang, clang does not
> support -fcanon-prefix-map and it has to be explicitly omitted when using
> clang.
> 
> There are lambdas generated in templates by clang which still get the
> absolute paths despite -fdebug-prefix-map, this helps with that as well.
> 
> nasm is an outlier and we have fixed it by adding -fdebug-prefix-map option
> luckily we do not pass DEBUG_PREFIX_MAP to nasm, in all recipes which use
> nasm either pass -fdebug-prefix-map explicitly to nasm or they rewrite it
> to use nasm flags syntax.
> 
> We have discussed this in past [1]
> 
> [1] https://patchwork.yoctoproject.org/project/oe-core/patch/20230428032030.2047920-1-raj.khem@gmail.com/#10281
> 
> Signed-off-by: Khem Raj <raj.khem@gmail.com>
> Cc: Jacob Kroon <jacob.kroon@gmail.com>
> Cc: Martin Jansa <Martin.Jansa@gmail.com>
> ---
> v2: Drop using --ffile-prefix in go
> 
>  meta/conf/bitbake.conf                     | 14 +++++---------
>  meta/recipes-devtools/rust/cargo_1.85.1.bb |  2 +-
>  2 files changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
> index 8f90026f7c2..b4e1964f77d 100644
> --- a/meta/conf/bitbake.conf
> +++ b/meta/conf/bitbake.conf
> @@ -652,15 +652,11 @@ EXTRA_OEMAKE:prepend:task-install = "${PARALLEL_MAKEINST} "
>  ##################################################################
>  TARGET_DBGSRC_DIR ?= "/usr/src/debug/${PN}/${PV}"
>  # Beware: applied last to first
> -DEBUG_PREFIX_MAP ?= "-fcanon-prefix-map \
> - -fmacro-prefix-map=${S}=${TARGET_DBGSRC_DIR} \
> - -fdebug-prefix-map=${S}=${TARGET_DBGSRC_DIR} \
> - -fmacro-prefix-map=${B}=${TARGET_DBGSRC_DIR} \
> - -fdebug-prefix-map=${B}=${TARGET_DBGSRC_DIR} \
> - -fdebug-prefix-map=${STAGING_DIR_HOST}= \
> - -fmacro-prefix-map=${STAGING_DIR_HOST}= \
> - -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \
> - -fmacro-prefix-map=${STAGING_DIR_NATIVE}= \
> +DEBUG_PREFIX_MAP ?= "\
> + -ffile-prefix-map=${S}=${TARGET_DBGSRC_DIR} \
> + -ffile-prefix-map=${B}=${TARGET_DBGSRC_DIR} \
> + -ffile-prefix-map=${STAGING_DIR_HOST}= \
> + -ffile-prefix-map=${STAGING_DIR_NATIVE}= \
>  "
>  DEBUG_LEVELFLAG ?= "-g"
>  
> diff --git a/meta/recipes-devtools/rust/cargo_1.85.1.bb b/meta/recipes-devtools/rust/cargo_1.85.1.bb
> index db18ecfda9a..150c2d2b801 100644
> --- a/meta/recipes-devtools/rust/cargo_1.85.1.bb
> +++ b/meta/recipes-devtools/rust/cargo_1.85.1.bb
> @@ -19,7 +19,7 @@ CARGO_VENDORING_DIRECTORY = "${RUSTSRC}/vendor"
>  
>  inherit cargo pkgconfig
>  
> -DEBUG_PREFIX_MAP += "-fdebug-prefix-map=${RUSTSRC}/vendor=${TARGET_DBGSRC_DIR}"
> +DEBUG_PREFIX_MAP += "-ffile-prefix-map=${RUSTSRC}/vendor=${TARGET_DBGSRC_DIR}"
>  
>  do_cargo_setup_snapshot () {
>  	${UNPACKDIR}/rust-snapshot-components/${CARGO_SNAPSHOT}/install.sh --prefix="${WORKDIR}/${CARGO_SNAPSHOT}" --disable-ldconfig

I'm a supporter of cleaning this up and doing this but I think we have a selftest failure that needs invesitgation:

https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/1469
https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/1386

I'm thinking it comes from this patch, I'll need to confirm that though.

Cheers,

Richard
Khem Raj April 21, 2025, 6:28 p.m. UTC | #2
On Mon, Apr 21, 2025 at 5:29 AM Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:
>
> On Fri, 2025-04-18 at 10:59 -0700, Khem Raj via lists.openembedded.org wrote:
> > -ffile-prefix map is more comprehensive when it comes to reproducible
> > builds and its superset of all prefix-mapping options in compilers
> >
> > This makes is cleaner and workable across gcc and clang, clang does not
> > support -fcanon-prefix-map and it has to be explicitly omitted when using
> > clang.
> >
> > There are lambdas generated in templates by clang which still get the
> > absolute paths despite -fdebug-prefix-map, this helps with that as well.
> >
> > nasm is an outlier and we have fixed it by adding -fdebug-prefix-map option
> > luckily we do not pass DEBUG_PREFIX_MAP to nasm, in all recipes which use
> > nasm either pass -fdebug-prefix-map explicitly to nasm or they rewrite it
> > to use nasm flags syntax.
> >
> > We have discussed this in past [1]
> >
> > [1] https://patchwork.yoctoproject.org/project/oe-core/patch/20230428032030.2047920-1-raj.khem@gmail.com/#10281
> >
> > Signed-off-by: Khem Raj <raj.khem@gmail.com>
> > Cc: Jacob Kroon <jacob.kroon@gmail.com>
> > Cc: Martin Jansa <Martin.Jansa@gmail.com>
> > ---
> > v2: Drop using --ffile-prefix in go
> >
> >  meta/conf/bitbake.conf                     | 14 +++++---------
> >  meta/recipes-devtools/rust/cargo_1.85.1.bb |  2 +-
> >  2 files changed, 6 insertions(+), 10 deletions(-)
> >
> > diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
> > index 8f90026f7c2..b4e1964f77d 100644
> > --- a/meta/conf/bitbake.conf
> > +++ b/meta/conf/bitbake.conf
> > @@ -652,15 +652,11 @@ EXTRA_OEMAKE:prepend:task-install = "${PARALLEL_MAKEINST} "
> >  ##################################################################
> >  TARGET_DBGSRC_DIR ?= "/usr/src/debug/${PN}/${PV}"
> >  # Beware: applied last to first
> > -DEBUG_PREFIX_MAP ?= "-fcanon-prefix-map \
> > - -fmacro-prefix-map=${S}=${TARGET_DBGSRC_DIR} \
> > - -fdebug-prefix-map=${S}=${TARGET_DBGSRC_DIR} \
> > - -fmacro-prefix-map=${B}=${TARGET_DBGSRC_DIR} \
> > - -fdebug-prefix-map=${B}=${TARGET_DBGSRC_DIR} \
> > - -fdebug-prefix-map=${STAGING_DIR_HOST}= \
> > - -fmacro-prefix-map=${STAGING_DIR_HOST}= \
> > - -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \
> > - -fmacro-prefix-map=${STAGING_DIR_NATIVE}= \
> > +DEBUG_PREFIX_MAP ?= "\
> > + -ffile-prefix-map=${S}=${TARGET_DBGSRC_DIR} \
> > + -ffile-prefix-map=${B}=${TARGET_DBGSRC_DIR} \
> > + -ffile-prefix-map=${STAGING_DIR_HOST}= \
> > + -ffile-prefix-map=${STAGING_DIR_NATIVE}= \
> >  "
> >  DEBUG_LEVELFLAG ?= "-g"
> >
> > diff --git a/meta/recipes-devtools/rust/cargo_1.85.1.bb b/meta/recipes-devtools/rust/cargo_1.85.1.bb
> > index db18ecfda9a..150c2d2b801 100644
> > --- a/meta/recipes-devtools/rust/cargo_1.85.1.bb
> > +++ b/meta/recipes-devtools/rust/cargo_1.85.1.bb
> > @@ -19,7 +19,7 @@ CARGO_VENDORING_DIRECTORY = "${RUSTSRC}/vendor"
> >
> >  inherit cargo pkgconfig
> >
> > -DEBUG_PREFIX_MAP += "-fdebug-prefix-map=${RUSTSRC}/vendor=${TARGET_DBGSRC_DIR}"
> > +DEBUG_PREFIX_MAP += "-ffile-prefix-map=${RUSTSRC}/vendor=${TARGET_DBGSRC_DIR}"
> >
> >  do_cargo_setup_snapshot () {
> >       ${UNPACKDIR}/rust-snapshot-components/${CARGO_SNAPSHOT}/install.sh --prefix="${WORKDIR}/${CARGO_SNAPSHOT}" --disable-ldconfig
>
> I'm a supporter of cleaning this up and doing this but I think we have a selftest failure that needs invesitgation:
>
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/23/builds/1469
> https://autobuilder.yoctoproject.org/valkyrie/#/builders/35/builds/1386
>
> I'm thinking it comes from this patch, I'll need to confirm that though.
>

I looked further and your suspicion is right. Its in copydebugsources
function in package class that
we explicitly look for -fdebug-prefix-map in cflags to map the source
file locations which ofcourse was failing now.
I have sent v3 with this fix and some more cleanups.

> Cheers,
>
> Richard
diff mbox series

Patch

diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 8f90026f7c2..b4e1964f77d 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -652,15 +652,11 @@  EXTRA_OEMAKE:prepend:task-install = "${PARALLEL_MAKEINST} "
 ##################################################################
 TARGET_DBGSRC_DIR ?= "/usr/src/debug/${PN}/${PV}"
 # Beware: applied last to first
-DEBUG_PREFIX_MAP ?= "-fcanon-prefix-map \
- -fmacro-prefix-map=${S}=${TARGET_DBGSRC_DIR} \
- -fdebug-prefix-map=${S}=${TARGET_DBGSRC_DIR} \
- -fmacro-prefix-map=${B}=${TARGET_DBGSRC_DIR} \
- -fdebug-prefix-map=${B}=${TARGET_DBGSRC_DIR} \
- -fdebug-prefix-map=${STAGING_DIR_HOST}= \
- -fmacro-prefix-map=${STAGING_DIR_HOST}= \
- -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \
- -fmacro-prefix-map=${STAGING_DIR_NATIVE}= \
+DEBUG_PREFIX_MAP ?= "\
+ -ffile-prefix-map=${S}=${TARGET_DBGSRC_DIR} \
+ -ffile-prefix-map=${B}=${TARGET_DBGSRC_DIR} \
+ -ffile-prefix-map=${STAGING_DIR_HOST}= \
+ -ffile-prefix-map=${STAGING_DIR_NATIVE}= \
 "
 DEBUG_LEVELFLAG ?= "-g"
 
diff --git a/meta/recipes-devtools/rust/cargo_1.85.1.bb b/meta/recipes-devtools/rust/cargo_1.85.1.bb
index db18ecfda9a..150c2d2b801 100644
--- a/meta/recipes-devtools/rust/cargo_1.85.1.bb
+++ b/meta/recipes-devtools/rust/cargo_1.85.1.bb
@@ -19,7 +19,7 @@  CARGO_VENDORING_DIRECTORY = "${RUSTSRC}/vendor"
 
 inherit cargo pkgconfig
 
-DEBUG_PREFIX_MAP += "-fdebug-prefix-map=${RUSTSRC}/vendor=${TARGET_DBGSRC_DIR}"
+DEBUG_PREFIX_MAP += "-ffile-prefix-map=${RUSTSRC}/vendor=${TARGET_DBGSRC_DIR}"
 
 do_cargo_setup_snapshot () {
 	${UNPACKDIR}/rust-snapshot-components/${CARGO_SNAPSHOT}/install.sh --prefix="${WORKDIR}/${CARGO_SNAPSHOT}" --disable-ldconfig