From patchwork Wed Jul 19 10:54:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Klose X-Patchwork-Id: 122541 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2348232vqt; Wed, 19 Jul 2023 03:55:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlEzRTfw+BdkdGKvun7fYM3uUSldQl82s73Lki2n8j/ceD4flYL6PFQ8kNE1wxUYfom7BH/i X-Received: by 2002:aa7:c65a:0:b0:51e:2974:f471 with SMTP id z26-20020aa7c65a000000b0051e2974f471mr1666329edr.42.1689764112996; Wed, 19 Jul 2023 03:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689764112; cv=none; d=google.com; s=arc-20160816; b=WdCqftGUyDIInalC0hV4ti1q3ytYgRS3UY5ED/qHBRZyxyulDP2j8jIeclTpKOGgfU 0BuWKSGXOevag1gBsUE41CemvZSU3CyexE88LYINaHp7+d9QGDg8ML6RqlBgCdjuD1Zu 8kQdLJlR+g2bZLv+WHQNvmSbmR2A2NGL8xpAZc+anmk/h0JJaTVr2W9Ept9Nf6muyTiq zHkCDlRBj9dXqH4fTmnQTwlZTFq5YPrVUfGbCZVtI9+MD3okaPgdcJ9cQMielvl08UO0 q/wm6PaD1DAp+ep9BEArwzBC7b5qM3XV7QPs9xsojCERTD9tbSOxxmaqitHL7hN6bP27 Xvgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :subject:from:to:content-language:user-agent:mime-version:date :message-id:dmarc-filter:delivered-to; bh=9gvtQz8Ie0C1uNMCRfKVjW4KKs3tWHrWCj32+iRUS1Y=; fh=xKHSUulzAO2LZfYFYJ2b5JsgqaVychsThdfC+8ac9mc=; b=t7mQAvNhDIMr4iVePO0nEV9wBjPSZiCTIWWlllgrlJEnR+YDERq2ZO1Bwwsoi3p0wd s8HbM6fnTCb9zfOn0bWh9iB4ndSzAv2cVgECqgSIjVVC8SbuYpjjs8e5h5hVg24Pk9Td SfrXR/km+/knqTn0ws8YMM1UoSAbMmVxBUS3M8albJyN2sEfS+TR3mPWnf7S3l363ecW yidgOUCeS5usswwfYXfiWOxyDG6UFEg2I6JlqoUzmdXUzhw7Hucr3GliP+A6mz9+UYFS b8ES+4HhsLyS0MUhM43Dq4s9tYqIitw1/drSKNpFfSt5EJW55+VBkjRXNEX8eolXgkx1 fPKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id r4-20020aa7cb84000000b0051de510240esi2905290edt.554.2023.07.19.03.55.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 03:55:12 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 868373857348 for ; Wed, 19 Jul 2023 10:55:07 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from einhorn-mail-out.in-berlin.de (einhorn.in-berlin.de [192.109.42.8]) by sourceware.org (Postfix) with ESMTPS id C5FE33858C66 for ; Wed, 19 Jul 2023 10:55:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5FE33858C66 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=debian.org X-Envelope-From: doko@debian.org X-Envelope-To: Received: from authenticated.user (localhost [127.0.0.1]) by einhorn.in-berlin.de with ESMTPSA id 36JAswP73309911 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Wed, 19 Jul 2023 12:54:58 +0200 Message-ID: <0c22e147-aa0c-12ae-24e0-4f770948054d@debian.org> Date: Wed, 19 Jul 2023 12:54:58 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: binutils From: Matthias Klose Subject: [patch] objcopy embeds the current time and ignores SOURCE_DATE_EPOCH making the output unreproducible X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771846094711568273 X-GMAIL-MSGID: 1771846094711568273 This is forwarded from https://bugs.debian.org/1040450 is this suitable upstream, or should it be kept as a local patch? SOURCE_DATE_EPOCH is also respected in GCC upstream. Hi, steps to reproduce the unreproducibility: $ objcopy /usr/lib/systemd/boot/efi/linuxaa64.efi.stub bootaa64_1 $ objcopy /usr/lib/systemd/boot/efi/linuxaa64.efi.stub bootaa64_2 $ cmp bootaa64_1 bootaa64_2 bootaa64_1 bootaa64_2 differ: byte 137, line 1 The resulting bootaa64.efi will have the local time embedded which makes it unreproducible unless faketime is used. Setting SOURCE_DATE_EPOCH or adding --enable-deterministic-archives does not make a difference. I identified the part of the code that generates this timestamp and pasted a preliminary patch fixing this issue to the end of this email. With that patch, setting SOURCE_DATE_EPOCH=0 results in a file with: $ objdump -x bootaa64.efi [...] Time/Date Thu Jan 1 01:00:00 1970 Since building binutils takes 7.4 hours on my machine and since I have never interacted with binutils upstream before, I'd appreciate if you could take it from here and see that this problem gets fixed in binutils upstream the way that its developers like to see this fixed. Thanks! cheers, josch --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -847,9 +847,17 @@ _bfd_XXi_only_swap_filehdr_out (bfd * ab /* Use a real timestamp by default, unless the no-insert-timestamp option was chosen. */ - if ((pe_data (abfd)->timestamp) == -1) - H_PUT_32 (abfd, time (0), filehdr_out->f_timdat); - else + if ((pe_data (abfd)->timestamp) == -1) { + time_t now; + char *source_date_epoch; + source_date_epoch = getenv("SOURCE_DATE_EPOCH"); + if (source_date_epoch) { + now = (time_t)strtoll(source_date_epoch, NULL, 10); + } else { + now = time(NULL); + } + H_PUT_32 (abfd, now, filehdr_out->f_timdat); + } else H_PUT_32 (abfd, pe_data (abfd)->timestamp, filehdr_out->f_timdat); PUT_FILEHDR_SYMPTR (abfd, filehdr_in->f_symptr,