diff mbox series

[v2,1/2] toolchain/toolchain-wrapper: explicitly set Build ID to none if BR2_REPRODUCIBLE

Message ID 20190831180113.16025-1-itsatharva@gmail.com
State Accepted
Headers show
Series [v2,1/2] toolchain/toolchain-wrapper: explicitly set Build ID to none if BR2_REPRODUCIBLE | expand

Commit Message

Atharva Lele Aug. 31, 2019, 6:01 p.m. UTC
Build ID is added to binaries at link time. Building in different output
directories causes some packages to have different Build IDs, thus resulting in
non-reproducibility.

Adding "-Wl,--build-id=none" fixes this issue by disabling setting of Build ID.

Diffoscope output for Build ID issue: https://gitlab.com/snippets/1886180/raw

After this patch, build is reproducible - i.e. diffoscope does not produce any
output.

Signed-off-by: Atharva Lele <itsatharva@gmail.com>
---
Changes v1 -> v2:
  - Handle inside toolchain-wrapper.mk instead of both .mk and .c
---
 toolchain/toolchain-wrapper.mk | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Romain Naour Sept. 7, 2019, 2:13 p.m. UTC | #1
Hi Atharva,

Le 31/08/2019 à 20:01, Atharva Lele a écrit :
> Build ID is added to binaries at link time. Building in different output
> directories causes some packages to have different Build IDs, thus resulting in
> non-reproducibility.
> 
> Adding "-Wl,--build-id=none" fixes this issue by disabling setting of Build ID.
> 
> Diffoscope output for Build ID issue: https://gitlab.com/snippets/1886180/raw
> 
> After this patch, build is reproducible - i.e. diffoscope does not produce any
> output.

--build-id option is available in binutils since 2.18 release (from 2007).
(Add a new ELF linker option, --build-id, to generate a unique per-binary
identifier embedded in a note section.) [1]

I don't think there is still toolchain using such old version with an up-to-date
Buildroot tree :)

[1] https://lwn.net/Articles/273637/

Reviewed-by: Romain Naour <romain.naour@smile.fr>

Best regards,
Romain

> 
> Signed-off-by: Atharva Lele <itsatharva@gmail.com>
> ---
> Changes v1 -> v2:
>   - Handle inside toolchain-wrapper.mk instead of both .mk and .c
> ---
>  toolchain/toolchain-wrapper.mk | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/toolchain/toolchain-wrapper.mk b/toolchain/toolchain-wrapper.mk
> index 970bde76a0..88695a5b2d 100644
> --- a/toolchain/toolchain-wrapper.mk
> +++ b/toolchain/toolchain-wrapper.mk
> @@ -21,6 +21,10 @@ TOOLCHAIN_WRAPPER_OPTS = \
>  	$(call qstrip,$(BR2_SSP_OPTION)) \
>  	$(call qstrip,$(BR2_TARGET_OPTIMIZATION))
>  
> +ifeq ($(BR2_REPRODUCIBLE),y)
> +TOOLCHAIN_WRAPPER_OPTS += -Wl,--build-id=none
> +endif
> +
>  # We create a list like '"-mfoo", "-mbar", "-mbarfoo"' so that each flag is a
>  # separate argument when used in execv() by the toolchain wrapper.
>  TOOLCHAIN_WRAPPER_ARGS += \
>
Thomas Petazzoni Oct. 26, 2019, 3:07 p.m. UTC | #2
On Sat, 31 Aug 2019 23:31:12 +0530
Atharva Lele <itsatharva@gmail.com> wrote:

> Build ID is added to binaries at link time. Building in different output
> directories causes some packages to have different Build IDs, thus resulting in
> non-reproducibility.
> 
> Adding "-Wl,--build-id=none" fixes this issue by disabling setting of Build ID.
> 
> Diffoscope output for Build ID issue: https://gitlab.com/snippets/1886180/raw
> 
> After this patch, build is reproducible - i.e. diffoscope does not produce any
> output.
> 
> Signed-off-by: Atharva Lele <itsatharva@gmail.com>
> ---
> Changes v1 -> v2:
>   - Handle inside toolchain-wrapper.mk instead of both .mk and .c
> ---
>  toolchain/toolchain-wrapper.mk | 4 ++++
>  1 file changed, 4 insertions(+)

Applied to master, thanks.

Thomas
diff mbox series

Patch

diff --git a/toolchain/toolchain-wrapper.mk b/toolchain/toolchain-wrapper.mk
index 970bde76a0..88695a5b2d 100644
--- a/toolchain/toolchain-wrapper.mk
+++ b/toolchain/toolchain-wrapper.mk
@@ -21,6 +21,10 @@  TOOLCHAIN_WRAPPER_OPTS = \
 	$(call qstrip,$(BR2_SSP_OPTION)) \
 	$(call qstrip,$(BR2_TARGET_OPTIMIZATION))
 
+ifeq ($(BR2_REPRODUCIBLE),y)
+TOOLCHAIN_WRAPPER_OPTS += -Wl,--build-id=none
+endif
+
 # We create a list like '"-mfoo", "-mbar", "-mbarfoo"' so that each flag is a
 # separate argument when used in execv() by the toolchain wrapper.
 TOOLCHAIN_WRAPPER_ARGS += \