[PATCH] Makefile: Use relative paths for debugging symbols.

Rasmus Villemoes rasmus.villemoes at prevas.se
Fri Aug 19 11:54:14 CEST 2022


On 18/08/2022 19.31, Vagrant Cascadian wrote:
> From: Vagrant Cascadian <vagrant at reproducible-builds.org>
> 
> The KBUILD_CFLAGS and KBUILD_AFLAGS variables are adjusted to use
> -ffile-prefix-map and --debug-prefix-map, respectively, to use
> relative paths for occurrences of __FILE__ and debug paths.
> 
> This enables reproducible builds regardless of the absolute path to
> the build directory:
> 
>   https://reproducible-builds.org/docs/build-path/
> 
> Signed-off-by: Vagrant Cascadian <vagrant at reproducible-builds.org>
> 
> ---
> 
>  Makefile | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 1a66f69a4b..b40b9b2444 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -751,14 +751,18 @@ KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
>  # Enabled with W=2, disabled by default as noisy
>  KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
>  
> -# change __FILE__ to the relative path from the srctree
> -KBUILD_CFLAGS	+= $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
> +# change __FILE__ and debugging symbols to the relative path from the
> +# srctree
> +KBUILD_CFLAGS	+= $(call cc-option,-ffile-prefix-map=$(srctree)/=)

You do update the comment, but it might be worth spelling out in the
commit log that -ffile-prefix-map is a superset of -fmacro-prefix-map,
and that both options are supported in the same set of compilers (so we
don't lose the effect of -fmacro-prefix-map for some set of compilers),
namely gcc 8. For reference, from the gcc repo

commit 7365279fca30371b07e49bfa83a23ddc44cc3860
Author: Boris Kolpackov <boris at gcc.gnu.org>
Date:   Thu Jan 18 13:17:37 2018 +0000

  Add ability to remap file names in __FILE__, etc (PR other/70268)

  This commit adds the -fmacro-prefix-map option that allows remapping
of file
  names in __FILE__, __BASE_FILE__, and __builtin_FILE(), similar to how
  -fdebug-prefix-map allows to do the same for debug information.

  Additionally, it adds -ffile-prefix-map which can be used to specify both
  mappings with a single option (and, should we need to add more
-f*-prefix-map
  options in the future, those as well).

>  KBUILD_CFLAGS	+= -g
>  # $(KBUILD_AFLAGS) sets -g, which causes gcc to pass a suitable -g<format>
>  # option to the assembler.
>  KBUILD_AFLAGS	+= -g
>  
> +# Use relative paths in debugging symbols
> +KBUILD_AFLAGS   += --debug-prefix-map=$(srctree)/=
> +

Hm, ok, it seems this has been supported in binutils since ~2007, so I
don't suppose this needs some equivalent to the cc-option guard.

Acked-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>


More information about the U-Boot mailing list