Skip to contentSkip to conversation

Makefile: Add flag for reprodubility compiler flags

PATCH Applied Khem Raj 2 participants 2 messages May 15, 2025 – Jun 15, 2025 Kbuild

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 Makefile: Add flag for reprodubility compiler flags

Provides mechanism to remove absolute paths from binaries using -ffile-prefix-map

It will help distros (e.g. yocto based ones ) which want to ship the .elf files but need to scrub absolute paths in objects

---
 Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
Makefile +7 -0
index e90836c7..22d4ecff 100644
@@ -174,6 +174,11 @@ else
 USE_LD_FLAG	=	-fuse-ld=bfd
 endif
 
+REPRODUCIBLE ?= n
+ifeq ($(REPRODUCIBLE),y)
+REPRODUCIBLE_FLAGS		+=	-ffile-prefix-map=$(src_dir)=
+endif
+
 # Check whether the linker supports creating PIEs
 OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
 
@@ -362,6 +367,7 @@ GENFLAGS	+=	$(firmware-genflags-y)
 
 CFLAGS		=	-g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-sections
 CFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls
+CFLAGS		+=	$(REPRODUCIBLE_FLAGS)
 # Optionally supported flags
 ifeq ($(CC_SUPPORT_VECTOR),y)
 CFLAGS		+=	-DOPENSBI_CC_SUPPORT_VECTOR
@@ -387,6 +393,7 @@ CPPFLAGS	+=	$(firmware-cppflags-y)
 ASFLAGS		=	-g -Wall -nostdlib
 ASFLAGS		+=	-fno-omit-frame-pointer -fno-optimize-sibling-calls
 ASFLAGS		+=	-fPIE
+ASFLAGS		+=	$(REPRODUCIBLE_FLAGS)
 # Optionally supported flags
 ifeq ($(CC_SUPPORT_SAVE_RESTORE),y)
 ASFLAGS		+=	-mno-save-restore
Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Reviewed-by on v1 1/1 Applied
#1 lore raw
Quoted 8 lines · Khem Raj

Provides mechanism to remove absolute paths from binaries using -ffile-prefix-map

It will help distros (e.g. yocto based ones ) which want to ship the .elf files but need to scrub absolute paths in objects

LGTM.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 41 lines
---
 Makefile | 7 +++++++
 1 file changed, 7 insertions(+)
Makefile +7 -1
index e90836c7..22d4ecff 100644
@@ -174,6 +174,11 @@ else
 USE_LD_FLAG    =       -fuse-ld=bfd
 endif
 
+REPRODUCIBLE ?= n
+ifeq ($(REPRODUCIBLE),y)
+REPRODUCIBLE_FLAGS             +=      -ffile-prefix-map=$(src_dir)=
+endif
+
 # Check whether the linker supports creating PIEs
 OPENSBI_LD_PIE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_FLAG) -fPIE -nostdlib -Wl,-pie -x c /dev/null -o /dev/null >/dev/null 2>&1 && echo y || echo n)
 
@@ -362,6 +367,7 @@ GENFLAGS    +=      $(firmware-genflags-y)
 
 CFLAGS         =       -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-sections
 CFLAGS         +=      -fno-omit-frame-pointer -fno-optimize-sibling-calls
+CFLAGS         +=      $(REPRODUCIBLE_FLAGS)
 # Optionally supported flags
 ifeq ($(CC_SUPPORT_VECTOR),y)
 CFLAGS         +=      -DOPENSBI_CC_SUPPORT_VECTOR
@@ -387,6 +393,7 @@ CPPFLAGS    +=      $(firmware-cppflags-y)
 ASFLAGS                =       -g -Wall -nostdlib
 ASFLAGS                +=      -fno-omit-frame-pointer -fno-optimize-sibling-calls
 ASFLAGS                +=      -fPIE
+ASFLAGS                +=      $(REPRODUCIBLE_FLAGS)
 # Optionally supported flags
 ifeq ($(CC_SUPPORT_SAVE_RESTORE),y)
 ASFLAGS                +=      -mno-save-restore
 
--

opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi