All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/8] package: Switch debug source handling to use prefix map
@ 2022-08-16 20:57 Richard Purdie
  2022-08-16 20:57 ` [PATCH 2/8] libgcc/gcc-runtime: Improve source reference handling Richard Purdie
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Richard Purdie @ 2022-08-16 20:57 UTC (permalink / raw)
  To: openembedded-core

Reproducible builds are no longer a configuration option but are required.
We also rely on the prefix mapping capability of the compilers now.

As such, rewrite the source locating code to use the prefix maps instead
of taking a guess about WORKDIR which isn't correct for kernels, gcc,
externalsrc and probably more.

Instead, iterate the maps to locate any matching source code, keeping
in mind that multiple maps may map to one target location.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/classes-global/package.bbclass | 68 ++++++++++++-----------------
 1 file changed, 28 insertions(+), 40 deletions(-)

diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass
index 418400da8c9..2d985d8affd 100644
--- a/meta/classes-global/package.bbclass
+++ b/meta/classes-global/package.bbclass
@@ -565,26 +565,16 @@ def copydebugsources(debugsrcdir, sources, d):
         objcopy = d.getVar("OBJCOPY")
         workdir = d.getVar("WORKDIR")
         sdir = d.getVar("S")
-        sparentdir = os.path.dirname(os.path.dirname(sdir))
-        sbasedir = os.path.basename(os.path.dirname(sdir)) + "/" + os.path.basename(sdir)
-        workparentdir = os.path.dirname(os.path.dirname(workdir))
-        workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" + os.path.basename(workdir)
-
-        # If S isnt based on WORKDIR we can infer our sources are located elsewhere,
-        # e.g. using externalsrc; use S as base for our dirs
-        if workdir in sdir or 'work-shared' in sdir:
-            basedir = workbasedir
-            parentdir = workparentdir
-        else:
-            basedir = sbasedir
-            parentdir = sparentdir
+        cflags = d.expand("${CFLAGS}")
 
-        # If build path exists in sourcefile, it means toolchain did not use
-        # -fdebug-prefix-map to compile
-        if checkbuildpath(sourcefile, d):
-            localsrc_prefix = parentdir + "/"
-        else:
-            localsrc_prefix = "/usr/src/debug/"
+        prefixmap = {}
+        for flag in cflags.split():
+            if not flag.startswith("-fdebug-prefix-map"):
+                continue
+            if "recipe-sysroot" in flag:
+                continue
+            flag = flag.split("=")
+            prefixmap[flag[1]] = flag[2]
 
         nosuchdir = []
         basepath = dvar
@@ -595,28 +585,26 @@ def copydebugsources(debugsrcdir, sources, d):
         bb.utils.mkdirhier(basepath)
         cpath.updatecache(basepath)
 
-        # Ignore files from the recipe sysroots (target and native)
-        processdebugsrc =  "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | "
-        # We need to ignore files that are not actually ours
-        # we do this by only paying attention to items from this package
-        processdebugsrc += "fgrep -zw '%s' | "
-        # Remove prefix in the source paths
-        processdebugsrc += "sed 's#%s##g' | "
-        processdebugsrc += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s' 2>/dev/null)"
-
-        cmd = processdebugsrc % (sourcefile, basedir, localsrc_prefix, parentdir, dvar, debugsrcdir)
-        try:
-            subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
-        except subprocess.CalledProcessError:
-            # Can "fail" if internal headers/transient sources are attempted
-            pass
-
-        # cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced.
-        # Work around this by manually finding and copying any symbolic links that made it through.
-        cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s')" % \
-                (dvar, debugsrcdir, dvar, debugsrcdir, parentdir, dvar, debugsrcdir)
-        subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
+        for pmap in prefixmap:
+            # Ignore files from the recipe sysroots (target and native)
+            cmd =  "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | " % sourcefile
+            # We need to ignore files that are not actually ours
+            # we do this by only paying attention to items from this package
+            cmd += "fgrep -zw '%s' | " % prefixmap[pmap]
+            # Remove prefix in the source paths
+            cmd += "sed 's#%s/##g' | " % (prefixmap[pmap])
+            cmd += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s' 2>/dev/null)" % (pmap, dvar, prefixmap[pmap])
 
+            try:
+                subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
+            except subprocess.CalledProcessError:
+                # Can "fail" if internal headers/transient sources are attempted
+                pass
+            # cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced.
+            # Work around this by manually finding and copying any symbolic links that made it through.
+            cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s')" % \
+                    (dvar, prefixmap[pmap], dvar, prefixmap[pmap], pmap, dvar, prefixmap[pmap])
+            subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
 
         # debugsources.list may be polluted from the host if we used externalsrc,
         # cpio uses copy-pass and may have just created a directory structure
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 2/8] libgcc/gcc-runtime: Improve source reference handling
  2022-08-16 20:57 [PATCH 1/8] package: Switch debug source handling to use prefix map Richard Purdie
@ 2022-08-16 20:57 ` Richard Purdie
  2022-08-16 20:57 ` [PATCH 3/8] bitbake.conf: Handle S and B separately for debug mapping Richard Purdie
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Richard Purdie @ 2022-08-16 20:57 UTC (permalink / raw)
  To: openembedded-core

This code was some of the earliest reproducible build work we did. To
correctly handle the encoding of file paths, we used relative build
paths to run configure which resulted in relative build paths in the
binaries.

We now have more modern approaches used elsewhere with the prefix remapping
options. These work best with absolute paths, not relative ones. As such,
drop the relative path mangling and switch to using prefix mapping
exclusively on absolute paths.

This makes the code matc the rest of the system and triggers the correct
code to be added in /usr/src/debug.

We have to include both file-prefix and debug-prefix since the assembler
only looks at debug-prefix.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/recipes-devtools/gcc/gcc-runtime.inc   | 22 ++++++++++-----------
 meta/recipes-devtools/gcc/libgcc-common.inc | 11 +++++++++--
 2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/meta/recipes-devtools/gcc/gcc-runtime.inc b/meta/recipes-devtools/gcc/gcc-runtime.inc
index b8bfdcedadf..35a3077a4a7 100644
--- a/meta/recipes-devtools/gcc/gcc-runtime.inc
+++ b/meta/recipes-devtools/gcc/gcc-runtime.inc
@@ -51,16 +51,15 @@ RUNTIMETARGET:libc-newlib = "libstdc++-v3"
 # libgfortran needs separate recipe due to libquadmath dependency
 
 # Relative path to be repaced into debug info
-REL_S = "/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}"
-
-DEBUG_PREFIX_MAP:class-target = " \
-   -fdebug-prefix-map=${WORKDIR}/${MLPREFIX}recipe-sysroot= \
-   -fdebug-prefix-map=${WORKDIR}/recipe-sysroot-native= \
-   -fdebug-prefix-map=${S}=${REL_S} \
-   -fdebug-prefix-map=${S}/include=${REL_S}/libstdc++-v3/../include \
-   -fdebug-prefix-map=${S}/libiberty=${REL_S}/libstdc++-v3/../libiberty \
-   -fdebug-prefix-map=${S}/libgcc=${REL_S}/libstdc++-v3/../libgcc \
-   -fdebug-prefix-map=${B}=${REL_S} \
+DEBUGSOURCE = "/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}"
+
+DEBUG_PREFIX_MAP = " \
+   -ffile-prefix-map=${WORKDIR}/${MLPREFIX}recipe-sysroot= \
+   -ffile-prefix-map=${WORKDIR}/recipe-sysroot-native= \
+   -ffile-prefix-map=${B}=${DEBUGSOURCE} \
+   -ffile-prefix-map=${S}=${DEBUGSOURCE} \
+   -fdebug-prefix-map=${B}=${DEBUGSOURCE} \
+   -fdebug-prefix-map=${S}=${DEBUGSOURCE} \
    -ffile-prefix-map=${B}/${HOST_SYS}/libstdc++-v3/include=${includedir}/c++/${BINV} \
    "
 
@@ -77,8 +76,7 @@ do_configure () {
 		mkdir -p ${B}/${TARGET_SYS}/$d/
 		cd ${B}/${TARGET_SYS}/$d/
 		chmod a+x ${S}/$d/configure
-		relpath=${@os.path.relpath("${S}/$d", "${B}/${TARGET_SYS}/$d")}
-		$relpath/configure ${CONFIGUREOPTS} ${EXTRA_OECONF}
+		${S}/$d/configure ${CONFIGUREOPTS} ${EXTRA_OECONF}
 		if [ "$d" = "libgcc" ]; then
 			(cd ${B}/${TARGET_SYS}/libgcc; oe_runmake enable-execute-stack.c unwind.h md-unwind-support.h sfp-machine.h gthr-default.h)
 		fi
diff --git a/meta/recipes-devtools/gcc/libgcc-common.inc b/meta/recipes-devtools/gcc/libgcc-common.inc
index cf8d6b7ed6e..e8139263132 100644
--- a/meta/recipes-devtools/gcc/libgcc-common.inc
+++ b/meta/recipes-devtools/gcc/libgcc-common.inc
@@ -4,14 +4,21 @@ require gcc-configure-common.inc
 
 INHIBIT_DEFAULT_DEPS = "1"
 
+DEBUGSOURCE = "/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}"
+DEBUG_PREFIX_MAP = " \
+   -fdebug-prefix-map=${WORKDIR}/${MLPREFIX}recipe-sysroot= \
+   -fdebug-prefix-map=${WORKDIR}/recipe-sysroot-native= \
+   -fdebug-prefix-map=${B}=${DEBUGSOURCE} \
+   -fdebug-prefix-map=${S}=${DEBUGSOURCE} \
+   "
+
 do_configure () {
 	install -d ${D}${base_libdir} ${D}${libdir}
 	mkdir -p ${B}/${BPN}
 	mkdir -p ${B}/${TARGET_SYS}/${BPN}/
 	cd ${B}/${BPN}
 	chmod a+x ${S}/${BPN}/configure
-	relpath=${@os.path.relpath("${S}/${BPN}", "${B}/${BPN}")}
-	$relpath/configure ${CONFIGUREOPTS} ${EXTRA_OECONF}
+	${S}/${BPN}/configure ${CONFIGUREOPTS} ${EXTRA_OECONF}
 }
 EXTRACONFFUNCS += "extract_stashed_builddir"
 do_configure[depends] += "${COMPILERDEP}"
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 3/8] bitbake.conf: Handle S and B separately for debug mapping
  2022-08-16 20:57 [PATCH 1/8] package: Switch debug source handling to use prefix map Richard Purdie
  2022-08-16 20:57 ` [PATCH 2/8] libgcc/gcc-runtime: Improve source reference handling Richard Purdie
@ 2022-08-16 20:57 ` Richard Purdie
  2022-08-16 20:57 ` [PATCH 4/8] python3-cython: Update code to match debug path changes Richard Purdie
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Richard Purdie @ 2022-08-16 20:57 UTC (permalink / raw)
  To: openembedded-core

We don't really need to keep S and B separate for debug source purposes
and there shouldn't be source references in WORKDIR that isn't S and B
either.

Separating these out simplifies the shared-work directory handling for
gcc and should also help fix external source usage. Therefore handle
S and B in DEBUG_PREFIX_MAP separately and clean up other code.

Indentation is reduced here as it is introduced on every compiler
commandline so minimising it is helpful.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/conf/bitbake.conf                      | 11 +++++++----
 meta/recipes-devtools/gcc/gcc-runtime.inc   | 13 -------------
 meta/recipes-devtools/gcc/libgcc-common.inc |  8 --------
 3 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index bdfb6784371..dd2df8a5520 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -645,10 +645,13 @@ EXTRA_OEMAKE:prepend:task-install = "${PARALLEL_MAKEINST} "
 # Optimization flags.
 ##################################################################
 # Beware: applied last to first
-DEBUG_PREFIX_MAP ?= "-fmacro-prefix-map=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR} \
-                     -fdebug-prefix-map=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR} \
-                     -fdebug-prefix-map=${STAGING_DIR_HOST}= \
-                     -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \
+DEBUG_PREFIX_MAP ?= "-fmacro-prefix-map=${S}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR} \
+ -fdebug-prefix-map=${S}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR} \
+ -fmacro-prefix-map=${B}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR} \
+ -fdebug-prefix-map=${B}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR} \
+ -fdebug-prefix-map=${STAGING_DIR_HOST}= \
+ -fmacro-prefix-map=${STAGING_DIR_HOST}= \
+ -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \
 "
 DEBUG_FLAGS ?= "-g -feliminate-unused-debug-types ${DEBUG_PREFIX_MAP}"
 
diff --git a/meta/recipes-devtools/gcc/gcc-runtime.inc b/meta/recipes-devtools/gcc/gcc-runtime.inc
index 35a3077a4a7..fa5b048dab7 100644
--- a/meta/recipes-devtools/gcc/gcc-runtime.inc
+++ b/meta/recipes-devtools/gcc/gcc-runtime.inc
@@ -50,19 +50,6 @@ RUNTIMETARGET:libc-newlib = "libstdc++-v3"
 # libiberty
 # libgfortran needs separate recipe due to libquadmath dependency
 
-# Relative path to be repaced into debug info
-DEBUGSOURCE = "/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}"
-
-DEBUG_PREFIX_MAP = " \
-   -ffile-prefix-map=${WORKDIR}/${MLPREFIX}recipe-sysroot= \
-   -ffile-prefix-map=${WORKDIR}/recipe-sysroot-native= \
-   -ffile-prefix-map=${B}=${DEBUGSOURCE} \
-   -ffile-prefix-map=${S}=${DEBUGSOURCE} \
-   -fdebug-prefix-map=${B}=${DEBUGSOURCE} \
-   -fdebug-prefix-map=${S}=${DEBUGSOURCE} \
-   -ffile-prefix-map=${B}/${HOST_SYS}/libstdc++-v3/include=${includedir}/c++/${BINV} \
-   "
-
 do_configure () {
 	export CXX="${CXX} -nostdinc++ -L${WORKDIR}/dummylib"
 	# libstdc++ isn't built yet so CXX would error not able to find it which breaks stdc++'s configure
diff --git a/meta/recipes-devtools/gcc/libgcc-common.inc b/meta/recipes-devtools/gcc/libgcc-common.inc
index e8139263132..d9084af51ad 100644
--- a/meta/recipes-devtools/gcc/libgcc-common.inc
+++ b/meta/recipes-devtools/gcc/libgcc-common.inc
@@ -4,14 +4,6 @@ require gcc-configure-common.inc
 
 INHIBIT_DEFAULT_DEPS = "1"
 
-DEBUGSOURCE = "/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}"
-DEBUG_PREFIX_MAP = " \
-   -fdebug-prefix-map=${WORKDIR}/${MLPREFIX}recipe-sysroot= \
-   -fdebug-prefix-map=${WORKDIR}/recipe-sysroot-native= \
-   -fdebug-prefix-map=${B}=${DEBUGSOURCE} \
-   -fdebug-prefix-map=${S}=${DEBUGSOURCE} \
-   "
-
 do_configure () {
 	install -d ${D}${base_libdir} ${D}${libdir}
 	mkdir -p ${B}/${BPN}
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 4/8] python3-cython: Update code to match debug path changes
  2022-08-16 20:57 [PATCH 1/8] package: Switch debug source handling to use prefix map Richard Purdie
  2022-08-16 20:57 ` [PATCH 2/8] libgcc/gcc-runtime: Improve source reference handling Richard Purdie
  2022-08-16 20:57 ` [PATCH 3/8] bitbake.conf: Handle S and B separately for debug mapping Richard Purdie
@ 2022-08-16 20:57 ` Richard Purdie
  2022-08-16 20:57 ` [PATCH 5/8] gcc-cross: Fix relative links Richard Purdie
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Richard Purdie @ 2022-08-16 20:57 UTC (permalink / raw)
  To: openembedded-core

Match the changes to debug prefixes in bitbake.conf.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 .../python/python3-cython_0.29.32.bb          | 20 ++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/meta/recipes-devtools/python/python3-cython_0.29.32.bb b/meta/recipes-devtools/python/python3-cython_0.29.32.bb
index 26333cb2718..28a1386310b 100644
--- a/meta/recipes-devtools/python/python3-cython_0.29.32.bb
+++ b/meta/recipes-devtools/python/python3-cython_0.29.32.bb
@@ -20,17 +20,19 @@ do_install:append() {
 PACKAGEBUILDPKGD += "cython_fix_sources"
 
 cython_fix_sources () {
-	for f in ${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython-${PV}/Cython/Compiler/FlowControl.c \
-		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython-${PV}/Cython/Compiler/FusedNode.c \
-		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython-${PV}/Cython/Compiler/Scanning.c \
-		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython-${PV}/Cython/Compiler/Visitor.c \
-		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython-${PV}/Cython/Plex/Actions.c \
-		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython-${PV}/Cython/Plex/Scanners.c \
-		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython-${PV}/Cython/Runtime/refnanny.c \
-		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython-${PV}/Cython/Tempita/_tempita.c \
+	for f in ${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython/Compiler/FlowControl.c \
+		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython/Compiler/FusedNode.c \
+		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython/Compiler/Scanning.c \
+		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython/Compiler/Visitor.c \
+		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython/Plex/Actions.c \
+		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython/Plex/Scanners.c \
+		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython/Runtime/refnanny.c \
+		${PKGD}/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}/Cython/Tempita/_tempita.c \
 		${PKGD}${libdir}/${PYTHON_DIR}/site-packages/Cython*/SOURCES.txt; do
+		echo $f >> /tmp/rp5
 		if [ -e $f ]; then
-			sed -i -e 's#${WORKDIR}#/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}#g' $f
+			echo sed -i -e 's#${WORKDIR}/Cython-${PV}#/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}#g'  >> /tmp/rp5
+			sed -i -e 's#${WORKDIR}/Cython-${PV}#/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR}#g' $f
 		fi
 	done
 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 5/8] gcc-cross: Fix relative links
  2022-08-16 20:57 [PATCH 1/8] package: Switch debug source handling to use prefix map Richard Purdie
                   ` (2 preceding siblings ...)
  2022-08-16 20:57 ` [PATCH 4/8] python3-cython: Update code to match debug path changes Richard Purdie
@ 2022-08-16 20:57 ` Richard Purdie
  2022-08-16 20:57 ` [PATCH 6/8] gcc: Resolve relative prefix-map filenames Richard Purdie
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Richard Purdie @ 2022-08-16 20:57 UTC (permalink / raw)
  To: openembedded-core

Now that we're using absolute paths to run configure, there are absolute
path symlinks within gcc's output. Use our script that fixes these so
that the sstate objects work correctly.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/recipes-devtools/gcc/gcc-cross.inc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/meta/recipes-devtools/gcc/gcc-cross.inc b/meta/recipes-devtools/gcc/gcc-cross.inc
index 3ffa1f0c460..a540fb2434a 100644
--- a/meta/recipes-devtools/gcc/gcc-cross.inc
+++ b/meta/recipes-devtools/gcc/gcc-cross.inc
@@ -149,6 +149,7 @@ do_gcc_stash_builddir () {
 	# Makefile does move-if-change which can end up with 'timestamp' as file contents so break links to those files
 	rm $dest/gcc/include/*.h
 	cp gcc/include/*.h $dest/gcc/include/
+	sysroot-relativelinks.py $dest
 }
 addtask do_gcc_stash_builddir after do_compile before do_install
 SSTATETASKS += "do_gcc_stash_builddir"
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 6/8] gcc: Resolve relative prefix-map filenames
  2022-08-16 20:57 [PATCH 1/8] package: Switch debug source handling to use prefix map Richard Purdie
                   ` (3 preceding siblings ...)
  2022-08-16 20:57 ` [PATCH 5/8] gcc-cross: Fix relative links Richard Purdie
@ 2022-08-16 20:57 ` Richard Purdie
  2022-08-16 20:57 ` [PATCH 7/8] gcc: Add a patch to avoid hardcoded paths in libgcc on powerpc Richard Purdie
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Richard Purdie @ 2022-08-16 20:57 UTC (permalink / raw)
  To: openembedded-core

Add a patch to gcc so that relative paths are handled by -fdebug-prefix-map
and friends. In OE we use relative paths in autotools and removing that
creates a lot of issues we'd have to fix. This alternative allows us to
fix the paths within gcc and improve our debug file coverage (and SPDX
manifests) accordingly.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/recipes-devtools/gcc/gcc-12.1.inc        |  1 +
 .../gcc/gcc/prefix-map-realpath.patch         | 62 +++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100644 meta/recipes-devtools/gcc/gcc/prefix-map-realpath.patch

diff --git a/meta/recipes-devtools/gcc/gcc-12.1.inc b/meta/recipes-devtools/gcc/gcc-12.1.inc
index 56678c78bef..c42fa3d72f0 100644
--- a/meta/recipes-devtools/gcc/gcc-12.1.inc
+++ b/meta/recipes-devtools/gcc/gcc-12.1.inc
@@ -65,6 +65,7 @@ SRC_URI = "${BASEURI} \
            file://0025-Move-sched.h-include-ahead-of-user-headers.patch \
            file://0026-rust-recursion-limit.patch \
            file://0001-libsanitizer-cherry-pick-9cf13067cb5088626ba7-from-u.patch \
+           file://prefix-map-realpath.patch \
 "
 SRC_URI[sha256sum] = "62fd634889f31c02b64af2c468f064b47ad1ca78411c45abe6ac4b5f8dd19c7b"
 
diff --git a/meta/recipes-devtools/gcc/gcc/prefix-map-realpath.patch b/meta/recipes-devtools/gcc/gcc/prefix-map-realpath.patch
new file mode 100644
index 00000000000..3544f61a744
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc/prefix-map-realpath.patch
@@ -0,0 +1,62 @@
+Relative paths don't work with -fdebug-prefix-map and friends. This
+can lead to paths which the user wanted to be remapped being missed.
+Setting -fdebug-prefix-map to work with a relative path isn't practical
+either.
+
+Instead, call gcc's realpath function on the incomming path name before
+comparing it with the remapping. This means other issues like symlinks
+are also accounted for and leads to a more consistent remapping experience.
+
+Upstream-Status: Pending [need to see if gcc developers would accept this]
+Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
+
+
+Index: gcc-12.1.0/gcc/file-prefix-map.cc
+===================================================================
+--- gcc-12.1.0.orig/gcc/file-prefix-map.cc
++++ gcc-12.1.0/gcc/file-prefix-map.cc
+@@ -70,19 +70,28 @@ remap_filename (file_prefix_map *maps, c
+   file_prefix_map *map;
+   char *s;
+   const char *name;
++  char *realname;
+   size_t name_len;
+ 
++  if (lbasename (filename) == filename)
++    return filename;
++
++  realname = lrealpath (filename);
++
+   for (map = maps; map; map = map->next)
+-    if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0)
++    if (filename_ncmp (realname, map->old_prefix, map->old_len) == 0)
+       break;
+-  if (!map)
++  if (!map) {
++    free (realname);
+     return filename;
+-  name = filename + map->old_len;
++  }
++  name = realname + map->old_len;
+   name_len = strlen (name) + 1;
+ 
+   s = (char *) ggc_alloc_atomic (name_len + map->new_len);
+   memcpy (s, map->new_prefix, map->new_len);
+   memcpy (s + map->new_len, name, name_len);
++  free (realname);
+   return s;
+ }
+ 
+Index: gcc-12.1.0/libcpp/macro.cc
+===================================================================
+--- gcc-12.1.0.orig/libcpp/macro.cc
++++ gcc-12.1.0/libcpp/macro.cc
+@@ -563,7 +563,7 @@ _cpp_builtin_macro_text (cpp_reader *pfi
+ 	    if (!name)
+ 	      abort ();
+ 	  }
+-	if (pfile->cb.remap_filename)
++	if (pfile->cb.remap_filename && !pfile->state.in_directive)
+ 	  name = pfile->cb.remap_filename (name);
+ 	len = strlen (name);
+ 	buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 7/8] gcc: Add a patch to avoid hardcoded paths in libgcc on powerpc
  2022-08-16 20:57 [PATCH 1/8] package: Switch debug source handling to use prefix map Richard Purdie
                   ` (4 preceding siblings ...)
  2022-08-16 20:57 ` [PATCH 6/8] gcc: Resolve relative prefix-map filenames Richard Purdie
@ 2022-08-16 20:57 ` Richard Purdie
  2022-08-16 22:45   ` [OE-core] " Khem Raj
  2022-08-16 20:57 ` [PATCH 8/8] skeleton/service: Ensure debug path handling works as intended Richard Purdie
  2022-08-16 21:24 ` [OE-core] [PATCH 1/8] package: Switch debug source handling to use prefix map Christopher Larson
  7 siblings, 1 reply; 11+ messages in thread
From: Richard Purdie @ 2022-08-16 20:57 UTC (permalink / raw)
  To: openembedded-core

Tweak the powerpc code to just include filenames rather than full paths
to avoid build reproducibility issues.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/recipes-devtools/gcc/gcc-12.1.inc        |  1 +
 .../gcc/gcc/hardcoded-paths.patch             | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 meta/recipes-devtools/gcc/gcc/hardcoded-paths.patch

diff --git a/meta/recipes-devtools/gcc/gcc-12.1.inc b/meta/recipes-devtools/gcc/gcc-12.1.inc
index c42fa3d72f0..488e0c95b18 100644
--- a/meta/recipes-devtools/gcc/gcc-12.1.inc
+++ b/meta/recipes-devtools/gcc/gcc-12.1.inc
@@ -66,6 +66,7 @@ SRC_URI = "${BASEURI} \
            file://0026-rust-recursion-limit.patch \
            file://0001-libsanitizer-cherry-pick-9cf13067cb5088626ba7-from-u.patch \
            file://prefix-map-realpath.patch \
+           file://hardcoded-paths.patch \
 "
 SRC_URI[sha256sum] = "62fd634889f31c02b64af2c468f064b47ad1ca78411c45abe6ac4b5f8dd19c7b"
 
diff --git a/meta/recipes-devtools/gcc/gcc/hardcoded-paths.patch b/meta/recipes-devtools/gcc/gcc/hardcoded-paths.patch
new file mode 100644
index 00000000000..aa3d16f6000
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc/hardcoded-paths.patch
@@ -0,0 +1,19 @@
+Avoid encoding build paths into sources used for floating point on powerpc.
+(MACHINE=qemuppc bitbake libgcc).
+
+Upstream-Status: Pending
+Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
+
+Index: gcc-12.1.0/libgcc/config/rs6000/t-float128
+===================================================================
+--- gcc-12.1.0.orig/libgcc/config/rs6000/t-float128
++++ gcc-12.1.0/libgcc/config/rs6000/t-float128
+@@ -103,7 +103,7 @@ $(ibm128_dec_objs)	: INTERNAL_CFLAGS +=
+ $(fp128_softfp_src) : $(srcdir)/soft-fp/$(subst -sw,,$(subst kf,tf,$@)) $(fp128_dep)
+ 	@src="$(srcdir)/soft-fp/$(subst -sw,,$(subst kf,tf,$@))"; \
+ 	echo "Create $@"; \
+-	(echo "/* file created from $$src */"; \
++	(echo "/* file created from `basename $$src` */"; \
+ 	 echo; \
+ 	 sed -f $(fp128_sed) < $$src) > $@
+ 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 8/8] skeleton/service: Ensure debug path handling works as intended
  2022-08-16 20:57 [PATCH 1/8] package: Switch debug source handling to use prefix map Richard Purdie
                   ` (5 preceding siblings ...)
  2022-08-16 20:57 ` [PATCH 7/8] gcc: Add a patch to avoid hardcoded paths in libgcc on powerpc Richard Purdie
@ 2022-08-16 20:57 ` Richard Purdie
  2022-08-16 21:24 ` [OE-core] [PATCH 1/8] package: Switch debug source handling to use prefix map Christopher Larson
  7 siblings, 0 replies; 11+ messages in thread
From: Richard Purdie @ 2022-08-16 20:57 UTC (permalink / raw)
  To: openembedded-core

DEBUG_PREFIX_MAP uses ${S} but that wasn't set correctly for this
recipe meaning cwd during the build (WORKDIR) was encoded into the
binary leading to buildpath warnings in debug symbols. Set S correctly
to avoid this issue.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta-skeleton/recipes-skeleton/service/service_0.1.bb | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/meta-skeleton/recipes-skeleton/service/service_0.1.bb b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
index d1d8c5f3656..912f6b0f611 100644
--- a/meta-skeleton/recipes-skeleton/service/service_0.1.bb
+++ b/meta-skeleton/recipes-skeleton/service/service_0.1.bb
@@ -9,6 +9,8 @@ SRC_URI = "file://skeleton \
 	   file://COPYRIGHT \
 	   "
 
+S = "${WORKDIR}"
+
 do_compile () {
 	${CC} ${CFLAGS} ${LDFLAGS} ${WORKDIR}/skeleton_test.c -o ${WORKDIR}/skeleton-test
 }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [OE-core] [PATCH 1/8] package: Switch debug source handling to use prefix map
  2022-08-16 20:57 [PATCH 1/8] package: Switch debug source handling to use prefix map Richard Purdie
                   ` (6 preceding siblings ...)
  2022-08-16 20:57 ` [PATCH 8/8] skeleton/service: Ensure debug path handling works as intended Richard Purdie
@ 2022-08-16 21:24 ` Christopher Larson
  2022-08-16 22:51   ` Khem Raj
  7 siblings, 1 reply; 11+ messages in thread
From: Christopher Larson @ 2022-08-16 21:24 UTC (permalink / raw)
  To: Richard Purdie; +Cc: Patches and discussions about the oe-core layer

[-- Attachment #1: Type: text/plain, Size: 6563 bytes --]

Looks like a good series, thanks for your work on this. LGTM.

On Tue, Aug 16, 2022 at 1:57 PM Richard Purdie <
richard.purdie@linuxfoundation.org> wrote:

> Reproducible builds are no longer a configuration option but are required.
> We also rely on the prefix mapping capability of the compilers now.
>
> As such, rewrite the source locating code to use the prefix maps instead
> of taking a guess about WORKDIR which isn't correct for kernels, gcc,
> externalsrc and probably more.
>
> Instead, iterate the maps to locate any matching source code, keeping
> in mind that multiple maps may map to one target location.
>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
>  meta/classes-global/package.bbclass | 68 ++++++++++++-----------------
>  1 file changed, 28 insertions(+), 40 deletions(-)
>
> diff --git a/meta/classes-global/package.bbclass
> b/meta/classes-global/package.bbclass
> index 418400da8c9..2d985d8affd 100644
> --- a/meta/classes-global/package.bbclass
> +++ b/meta/classes-global/package.bbclass
> @@ -565,26 +565,16 @@ def copydebugsources(debugsrcdir, sources, d):
>          objcopy = d.getVar("OBJCOPY")
>          workdir = d.getVar("WORKDIR")
>          sdir = d.getVar("S")
> -        sparentdir = os.path.dirname(os.path.dirname(sdir))
> -        sbasedir = os.path.basename(os.path.dirname(sdir)) + "/" +
> os.path.basename(sdir)
> -        workparentdir = os.path.dirname(os.path.dirname(workdir))
> -        workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" +
> os.path.basename(workdir)
> -
> -        # If S isnt based on WORKDIR we can infer our sources are located
> elsewhere,
> -        # e.g. using externalsrc; use S as base for our dirs
> -        if workdir in sdir or 'work-shared' in sdir:
> -            basedir = workbasedir
> -            parentdir = workparentdir
> -        else:
> -            basedir = sbasedir
> -            parentdir = sparentdir
> +        cflags = d.expand("${CFLAGS}")
>
> -        # If build path exists in sourcefile, it means toolchain did not
> use
> -        # -fdebug-prefix-map to compile
> -        if checkbuildpath(sourcefile, d):
> -            localsrc_prefix = parentdir + "/"
> -        else:
> -            localsrc_prefix = "/usr/src/debug/"
> +        prefixmap = {}
> +        for flag in cflags.split():
> +            if not flag.startswith("-fdebug-prefix-map"):
> +                continue
> +            if "recipe-sysroot" in flag:
> +                continue
> +            flag = flag.split("=")
> +            prefixmap[flag[1]] = flag[2]
>
>          nosuchdir = []
>          basepath = dvar
> @@ -595,28 +585,26 @@ def copydebugsources(debugsrcdir, sources, d):
>          bb.utils.mkdirhier(basepath)
>          cpath.updatecache(basepath)
>
> -        # Ignore files from the recipe sysroots (target and native)
> -        processdebugsrc =  "LC_ALL=C ; sort -z -u '%s' | egrep -v -z
> '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | "
> -        # We need to ignore files that are not actually ours
> -        # we do this by only paying attention to items from this package
> -        processdebugsrc += "fgrep -zw '%s' | "
> -        # Remove prefix in the source paths
> -        processdebugsrc += "sed 's#%s##g' | "
> -        processdebugsrc += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner
> '%s%s' 2>/dev/null)"
> -
> -        cmd = processdebugsrc % (sourcefile, basedir, localsrc_prefix,
> parentdir, dvar, debugsrcdir)
> -        try:
> -            subprocess.check_output(cmd, shell=True,
> stderr=subprocess.STDOUT)
> -        except subprocess.CalledProcessError:
> -            # Can "fail" if internal headers/transient sources are
> attempted
> -            pass
> -
> -        # cpio seems to have a bug with -lL together and symbolic links
> are just copied, not dereferenced.
> -        # Work around this by manually finding and copying any symbolic
> links that made it through.
> -        cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd
> '%s' ; cpio -pd0mL --no-preserve-owner '%s%s')" % \
> -                (dvar, debugsrcdir, dvar, debugsrcdir, parentdir, dvar,
> debugsrcdir)
> -        subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
> +        for pmap in prefixmap:
> +            # Ignore files from the recipe sysroots (target and native)
> +            cmd =  "LC_ALL=C ; sort -z -u '%s' | egrep -v -z
> '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | " % sourcefile
> +            # We need to ignore files that are not actually ours
> +            # we do this by only paying attention to items from this
> package
> +            cmd += "fgrep -zw '%s' | " % prefixmap[pmap]
> +            # Remove prefix in the source paths
> +            cmd += "sed 's#%s/##g' | " % (prefixmap[pmap])
> +            cmd += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s'
> 2>/dev/null)" % (pmap, dvar, prefixmap[pmap])
>
> +            try:
> +                subprocess.check_output(cmd, shell=True,
> stderr=subprocess.STDOUT)
> +            except subprocess.CalledProcessError:
> +                # Can "fail" if internal headers/transient sources are
> attempted
> +                pass
> +            # cpio seems to have a bug with -lL together and symbolic
> links are just copied, not dereferenced.
> +            # Work around this by manually finding and copying any
> symbolic links that made it through.
> +            cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g |
> (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s')" % \
> +                    (dvar, prefixmap[pmap], dvar, prefixmap[pmap], pmap,
> dvar, prefixmap[pmap])
> +            subprocess.check_output(cmd, shell=True,
> stderr=subprocess.STDOUT)
>
>          # debugsources.list may be polluted from the host if we used
> externalsrc,
>          # cpio uses copy-pass and may have just created a directory
> structure
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#169455):
> https://lists.openembedded.org/g/openembedded-core/message/169455
> Mute This Topic: https://lists.openembedded.org/mt/93068145/3617123
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [
> kergoth@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
>

-- 
Christopher Larson
chris_larson@mentor.com, chris.larson@siemens.com, kergoth@gmail.com
Principal Software Engineer, Embedded Linux Solutions, Siemens Digital
Industries Software

[-- Attachment #2: Type: text/html, Size: 8665 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [OE-core] [PATCH 7/8] gcc: Add a patch to avoid hardcoded paths in libgcc on powerpc
  2022-08-16 20:57 ` [PATCH 7/8] gcc: Add a patch to avoid hardcoded paths in libgcc on powerpc Richard Purdie
@ 2022-08-16 22:45   ` Khem Raj
  0 siblings, 0 replies; 11+ messages in thread
From: Khem Raj @ 2022-08-16 22:45 UTC (permalink / raw)
  To: Richard Purdie; +Cc: openembedded-core

On Tue, Aug 16, 2022 at 1:58 PM Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:
>
> Tweak the powerpc code to just include filenames rather than full paths
> to avoid build reproducibility issues.
>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> ---
>  meta/recipes-devtools/gcc/gcc-12.1.inc        |  1 +
>  .../gcc/gcc/hardcoded-paths.patch             | 19 +++++++++++++++++++
>  2 files changed, 20 insertions(+)
>  create mode 100644 meta/recipes-devtools/gcc/gcc/hardcoded-paths.patch
>
> diff --git a/meta/recipes-devtools/gcc/gcc-12.1.inc b/meta/recipes-devtools/gcc/gcc-12.1.inc
> index c42fa3d72f0..488e0c95b18 100644
> --- a/meta/recipes-devtools/gcc/gcc-12.1.inc
> +++ b/meta/recipes-devtools/gcc/gcc-12.1.inc
> @@ -66,6 +66,7 @@ SRC_URI = "${BASEURI} \
>             file://0026-rust-recursion-limit.patch \
>             file://0001-libsanitizer-cherry-pick-9cf13067cb5088626ba7-from-u.patch \
>             file://prefix-map-realpath.patch \
> +           file://hardcoded-paths.patch \
>  "
>  SRC_URI[sha256sum] = "62fd634889f31c02b64af2c468f064b47ad1ca78411c45abe6ac4b5f8dd19c7b"
>
> diff --git a/meta/recipes-devtools/gcc/gcc/hardcoded-paths.patch b/meta/recipes-devtools/gcc/gcc/hardcoded-paths.patch
> new file mode 100644
> index 00000000000..aa3d16f6000
> --- /dev/null
> +++ b/meta/recipes-devtools/gcc/gcc/hardcoded-paths.patch
> @@ -0,0 +1,19 @@
> +Avoid encoding build paths into sources used for floating point on powerpc.
> +(MACHINE=qemuppc bitbake libgcc).
> +
> +Upstream-Status: Pending
> +Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> +
> +Index: gcc-12.1.0/libgcc/config/rs6000/t-float128
> +===================================================================
> +--- gcc-12.1.0.orig/libgcc/config/rs6000/t-float128
> ++++ gcc-12.1.0/libgcc/config/rs6000/t-float128
> +@@ -103,7 +103,7 @@ $(ibm128_dec_objs) : INTERNAL_CFLAGS +=
> + $(fp128_softfp_src) : $(srcdir)/soft-fp/$(subst -sw,,$(subst kf,tf,$@)) $(fp128_dep)
> +       @src="$(srcdir)/soft-fp/$(subst -sw,,$(subst kf,tf,$@))"; \
> +       echo "Create $@"; \
> +-      (echo "/* file created from $$src */"; \
> ++      (echo "/* file created from `basename $$src` */"; \
> +        echo; \
> +        sed -f $(fp128_sed) < $$src) > $@
> +

This one looks an easily upstreamable change.

> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#169461): https://lists.openembedded.org/g/openembedded-core/message/169461
> Mute This Topic: https://lists.openembedded.org/mt/93068152/1997914
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [OE-core] [PATCH 1/8] package: Switch debug source handling to use prefix map
  2022-08-16 21:24 ` [OE-core] [PATCH 1/8] package: Switch debug source handling to use prefix map Christopher Larson
@ 2022-08-16 22:51   ` Khem Raj
  0 siblings, 0 replies; 11+ messages in thread
From: Khem Raj @ 2022-08-16 22:51 UTC (permalink / raw)
  To: Christopher Larson
  Cc: Richard Purdie, Patches and discussions about the oe-core layer

Series looks good now to me. I think we should upstream the gcc
patches as well since its
a good change to have everywhere. I am seeing one issue in curl-config
now getting buildpaths [1]
emitted into it, but it could be clang only problem too, I will look
more into it

[1] http://sprunge.us/JmSaGG

On Tue, Aug 16, 2022 at 2:24 PM Christopher Larson <kergoth@gmail.com> wrote:
>
> Looks like a good series, thanks for your work on this. LGTM.
>
> On Tue, Aug 16, 2022 at 1:57 PM Richard Purdie <richard.purdie@linuxfoundation.org> wrote:
>>
>> Reproducible builds are no longer a configuration option but are required.
>> We also rely on the prefix mapping capability of the compilers now.
>>
>> As such, rewrite the source locating code to use the prefix maps instead
>> of taking a guess about WORKDIR which isn't correct for kernels, gcc,
>> externalsrc and probably more.
>>
>> Instead, iterate the maps to locate any matching source code, keeping
>> in mind that multiple maps may map to one target location.
>>
>> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
>> ---
>>  meta/classes-global/package.bbclass | 68 ++++++++++++-----------------
>>  1 file changed, 28 insertions(+), 40 deletions(-)
>>
>> diff --git a/meta/classes-global/package.bbclass b/meta/classes-global/package.bbclass
>> index 418400da8c9..2d985d8affd 100644
>> --- a/meta/classes-global/package.bbclass
>> +++ b/meta/classes-global/package.bbclass
>> @@ -565,26 +565,16 @@ def copydebugsources(debugsrcdir, sources, d):
>>          objcopy = d.getVar("OBJCOPY")
>>          workdir = d.getVar("WORKDIR")
>>          sdir = d.getVar("S")
>> -        sparentdir = os.path.dirname(os.path.dirname(sdir))
>> -        sbasedir = os.path.basename(os.path.dirname(sdir)) + "/" + os.path.basename(sdir)
>> -        workparentdir = os.path.dirname(os.path.dirname(workdir))
>> -        workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" + os.path.basename(workdir)
>> -
>> -        # If S isnt based on WORKDIR we can infer our sources are located elsewhere,
>> -        # e.g. using externalsrc; use S as base for our dirs
>> -        if workdir in sdir or 'work-shared' in sdir:
>> -            basedir = workbasedir
>> -            parentdir = workparentdir
>> -        else:
>> -            basedir = sbasedir
>> -            parentdir = sparentdir
>> +        cflags = d.expand("${CFLAGS}")
>>
>> -        # If build path exists in sourcefile, it means toolchain did not use
>> -        # -fdebug-prefix-map to compile
>> -        if checkbuildpath(sourcefile, d):
>> -            localsrc_prefix = parentdir + "/"
>> -        else:
>> -            localsrc_prefix = "/usr/src/debug/"
>> +        prefixmap = {}
>> +        for flag in cflags.split():
>> +            if not flag.startswith("-fdebug-prefix-map"):
>> +                continue
>> +            if "recipe-sysroot" in flag:
>> +                continue
>> +            flag = flag.split("=")
>> +            prefixmap[flag[1]] = flag[2]
>>
>>          nosuchdir = []
>>          basepath = dvar
>> @@ -595,28 +585,26 @@ def copydebugsources(debugsrcdir, sources, d):
>>          bb.utils.mkdirhier(basepath)
>>          cpath.updatecache(basepath)
>>
>> -        # Ignore files from the recipe sysroots (target and native)
>> -        processdebugsrc =  "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | "
>> -        # We need to ignore files that are not actually ours
>> -        # we do this by only paying attention to items from this package
>> -        processdebugsrc += "fgrep -zw '%s' | "
>> -        # Remove prefix in the source paths
>> -        processdebugsrc += "sed 's#%s##g' | "
>> -        processdebugsrc += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s' 2>/dev/null)"
>> -
>> -        cmd = processdebugsrc % (sourcefile, basedir, localsrc_prefix, parentdir, dvar, debugsrcdir)
>> -        try:
>> -            subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
>> -        except subprocess.CalledProcessError:
>> -            # Can "fail" if internal headers/transient sources are attempted
>> -            pass
>> -
>> -        # cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced.
>> -        # Work around this by manually finding and copying any symbolic links that made it through.
>> -        cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s')" % \
>> -                (dvar, debugsrcdir, dvar, debugsrcdir, parentdir, dvar, debugsrcdir)
>> -        subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
>> +        for pmap in prefixmap:
>> +            # Ignore files from the recipe sysroots (target and native)
>> +            cmd =  "LC_ALL=C ; sort -z -u '%s' | egrep -v -z '((<internal>|<built-in>)$|/.*recipe-sysroot.*/)' | " % sourcefile
>> +            # We need to ignore files that are not actually ours
>> +            # we do this by only paying attention to items from this package
>> +            cmd += "fgrep -zw '%s' | " % prefixmap[pmap]
>> +            # Remove prefix in the source paths
>> +            cmd += "sed 's#%s/##g' | " % (prefixmap[pmap])
>> +            cmd += "(cd '%s' ; cpio -pd0mlL --no-preserve-owner '%s%s' 2>/dev/null)" % (pmap, dvar, prefixmap[pmap])
>>
>> +            try:
>> +                subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
>> +            except subprocess.CalledProcessError:
>> +                # Can "fail" if internal headers/transient sources are attempted
>> +                pass
>> +            # cpio seems to have a bug with -lL together and symbolic links are just copied, not dereferenced.
>> +            # Work around this by manually finding and copying any symbolic links that made it through.
>> +            cmd = "find %s%s -type l -print0 -delete | sed s#%s%s/##g | (cd '%s' ; cpio -pd0mL --no-preserve-owner '%s%s')" % \
>> +                    (dvar, prefixmap[pmap], dvar, prefixmap[pmap], pmap, dvar, prefixmap[pmap])
>> +            subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
>>
>>          # debugsources.list may be polluted from the host if we used externalsrc,
>>          # cpio uses copy-pass and may have just created a directory structure
>> --
>> 2.34.1
>>
>>
>>
>>
>
>
> --
> Christopher Larson
> chris_larson@mentor.com, chris.larson@siemens.com, kergoth@gmail.com
> Principal Software Engineer, Embedded Linux Solutions, Siemens Digital Industries Software
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#169463): https://lists.openembedded.org/g/openembedded-core/message/169463
> Mute This Topic: https://lists.openembedded.org/mt/93068145/1997914
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-08-16 22:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-16 20:57 [PATCH 1/8] package: Switch debug source handling to use prefix map Richard Purdie
2022-08-16 20:57 ` [PATCH 2/8] libgcc/gcc-runtime: Improve source reference handling Richard Purdie
2022-08-16 20:57 ` [PATCH 3/8] bitbake.conf: Handle S and B separately for debug mapping Richard Purdie
2022-08-16 20:57 ` [PATCH 4/8] python3-cython: Update code to match debug path changes Richard Purdie
2022-08-16 20:57 ` [PATCH 5/8] gcc-cross: Fix relative links Richard Purdie
2022-08-16 20:57 ` [PATCH 6/8] gcc: Resolve relative prefix-map filenames Richard Purdie
2022-08-16 20:57 ` [PATCH 7/8] gcc: Add a patch to avoid hardcoded paths in libgcc on powerpc Richard Purdie
2022-08-16 22:45   ` [OE-core] " Khem Raj
2022-08-16 20:57 ` [PATCH 8/8] skeleton/service: Ensure debug path handling works as intended Richard Purdie
2022-08-16 21:24 ` [OE-core] [PATCH 1/8] package: Switch debug source handling to use prefix map Christopher Larson
2022-08-16 22:51   ` Khem Raj

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.