summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/ovmf/ovmf/0006-reproducible.patch
blob: 343c21b541c14d951448f47f2e3d9d6b6667c25b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
From 27ed9962f5cb3afcc44d6c96c53277132a999712 Mon Sep 17 00:00:00 2001
From: Alexander Kanavin <alex.kanavin@gmail.com>
Date: Mon, 14 Jun 2021 19:57:30 +0200
Subject: [PATCH 6/6] reproducible

This patch fixes various things which make the build more reproducible. Some changes
here only change intermediate artefacts but that means when you have two build trees
giving differing results, the differences can be isolated more easily. The issues here
usually become apparent with longer paths.

This was all debugged with:
TMPDIR = "${TOPDIR}/tmp"
vs.
TMPDIR = "${TOPDIR}/tmp-inital-mylongpath-mylongpath-mylongpath-mylongpath-mylongpath-mylongpath-mylongpath-mylongpath-mylongpath"

The patch specifically:

 * Sorts output in GNUmakefile
 * Always generates indirect flags files used to avoid pathlength issues else the
   compile commands suddenly change when using longer paths
 * Sorts the AutoGenTimeStamp file contents
 * Makes the TargetDescBlock objects from BuildEngine sortable to allow the makefile fix
 * Fix ElfConvert within GenFw so that only the basename of the binary being converted
   is used, else the output from "GenFw XXX.bin" differs from "GenFw /long/path/XXX.bin"
   with sufficiently long paths

Upstream-Status: Pending [At least some of this might be interesting to upstream]
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
---
 BaseTools/Source/C/GenFw/Elf64Convert.c       |  8 ++++---
 .../Source/Python/AutoGen/BuildEngine.py      |  3 +++
 BaseTools/Source/Python/AutoGen/GenMake.py    | 24 +++++++++----------
 .../Source/Python/AutoGen/ModuleAutoGen.py    |  5 +++-
 4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c
index d097db8632..a87ae6f3d0 100644
--- a/BaseTools/Source/C/GenFw/Elf64Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
@@ -14,6 +14,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #ifndef __GNUC__
 #include <windows.h>
 #include <io.h>
+#else
+#define _GNU_SOURCE
 #endif
 #include <assert.h>
 #include <stdio.h>
@@ -769,7 +771,7 @@ ScanSections64 (
   }
   mCoffOffset = mDebugOffset + sizeof(EFI_IMAGE_DEBUG_DIRECTORY_ENTRY) +
                 sizeof(EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY) +
-                strlen(mInImageName) + 1;
+                strlen(basename(mInImageName)) + 1;
 
   mCoffOffset = CoffAlign(mCoffOffset);
   if (SectionCount == 0) {
@@ -1608,7 +1610,7 @@ WriteDebug64 (
   EFI_IMAGE_DEBUG_DIRECTORY_ENTRY     *Dir;
   EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY *Nb10;
 
-  Len = strlen(mInImageName) + 1;
+  Len = strlen(basename(mInImageName)) + 1;
 
   Dir = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY*)(mCoffFile + mDebugOffset);
   Dir->Type = EFI_IMAGE_DEBUG_TYPE_CODEVIEW;
@@ -1618,7 +1620,7 @@ WriteDebug64 (
 
   Nb10 = (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY*)(Dir + 1);
   Nb10->Signature = CODEVIEW_SIGNATURE_NB10;
-  strcpy ((char *)(Nb10 + 1), mInImageName);
+  strcpy ((char *)(Nb10 + 1), basename(mInImageName));
 
 
   NtHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)(mCoffFile + mNtHdrOffset);
diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py b/BaseTools/Source/Python/AutoGen/BuildEngine.py
index 722fead75a..8f1c236970 100644
--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
@@ -70,6 +70,9 @@ class TargetDescBlock(object):
         else:
             return str(Other) == self.Target.Path
 
+    def __lt__(self, other):
+        return str(self) < str(other)
+
     def AddInput(self, Input):
         if Input not in self.Inputs:
             self.Inputs.append(Input)
diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py
index 961b2ab1c3..23c1592025 100755
--- a/BaseTools/Source/Python/AutoGen/GenMake.py
+++ b/BaseTools/Source/Python/AutoGen/GenMake.py
@@ -575,7 +575,7 @@ cleanlib:
                 os.remove(RespFileList)
 
         # convert source files and binary files to build targets
-        self.ResultFileList = [str(T.Target) for T in MyAgo.CodaTargetList]
+        self.ResultFileList = sorted([str(T.Target) for T in MyAgo.CodaTargetList])
         if len(self.ResultFileList) == 0 and len(MyAgo.SourceFileList) != 0:
             EdkLogger.error("build", AUTOGEN_ERROR, "Nothing to build",
                             ExtraData="[%s]" % str(MyAgo))
@@ -726,7 +726,7 @@ cleanlib:
         OutputFile = ''
         DepsFileList = []
 
-        for Cmd in self.GenFfsList:
+        for Cmd in sorted(self.GenFfsList):
             if Cmd[2]:
                 for CopyCmd in Cmd[2]:
                     Src, Dst = CopyCmd
@@ -759,7 +759,7 @@ cleanlib:
             self.BuildTargetList.append('\t%s' % CmdString)
 
             self.ParseSecCmd(DepsFileList, Cmd[1])
-            for SecOutputFile, SecDepsFile, SecCmd in self.FfsOutputFileList :
+            for SecOutputFile, SecDepsFile, SecCmd in sorted(self.FfsOutputFileList):
                 self.BuildTargetList.append('%s : %s' % (self.ReplaceMacro(SecOutputFile), self.ReplaceMacro(SecDepsFile)))
                 self.BuildTargetList.append('\t%s' % self.ReplaceMacro(SecCmd))
             self.FfsOutputFileList = []
@@ -798,13 +798,13 @@ cleanlib:
 
     def CommandExceedLimit(self):
         FlagDict = {
-                    'CC'    :  { 'Macro' : '$(CC_FLAGS)',    'Value' : False},
-                    'PP'    :  { 'Macro' : '$(PP_FLAGS)',    'Value' : False},
-                    'APP'   :  { 'Macro' : '$(APP_FLAGS)',   'Value' : False},
-                    'ASLPP' :  { 'Macro' : '$(ASLPP_FLAGS)', 'Value' : False},
-                    'VFRPP' :  { 'Macro' : '$(VFRPP_FLAGS)', 'Value' : False},
-                    'ASM'   :  { 'Macro' : '$(ASM_FLAGS)',   'Value' : False},
-                    'ASLCC' :  { 'Macro' : '$(ASLCC_FLAGS)', 'Value' : False},
+                    'CC'    :  { 'Macro' : '$(CC_FLAGS)',    'Value' : True},
+                    'PP'    :  { 'Macro' : '$(PP_FLAGS)',    'Value' : True},
+                    'APP'   :  { 'Macro' : '$(APP_FLAGS)',   'Value' : True},
+                    'ASLPP' :  { 'Macro' : '$(ASLPP_FLAGS)', 'Value' : True},
+                    'VFRPP' :  { 'Macro' : '$(VFRPP_FLAGS)', 'Value' : True},
+                    'ASM'   :  { 'Macro' : '$(ASM_FLAGS)',   'Value' : True},
+                    'ASLCC' :  { 'Macro' : '$(ASLCC_FLAGS)', 'Value' : True},
                    }
 
         RespDict = {}
@@ -1007,9 +1007,9 @@ cleanlib:
                 if not self.ObjTargetDict.get(T.Target.SubDir):
                     self.ObjTargetDict[T.Target.SubDir] = set()
                 self.ObjTargetDict[T.Target.SubDir].add(NewFile)
-        for Type in self._AutoGenObject.Targets:
+        for Type in sorted(self._AutoGenObject.Targets):
             resp_file_number = 0
-            for T in self._AutoGenObject.Targets[Type]:
+            for T in sorted(self._AutoGenObject.Targets[Type]):
                 # Generate related macros if needed
                 if T.GenFileListMacro and T.FileListMacro not in self.FileListMacros:
                     self.FileListMacros[T.FileListMacro] = []
diff --git a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py
index d70b0d7ae8..25dca9a6df 100755
--- a/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/ModuleAutoGen.py
@@ -1484,6 +1484,9 @@ class ModuleAutoGen(AutoGen):
             for File in Files:
                 if File.lower().endswith('.pdb'):
                     AsBuiltInfDict['binary_item'].append('DISPOSABLE|' + File)
+
+        AsBuiltInfDict['binary_item'] = sorted(AsBuiltInfDict['binary_item'])
+
         HeaderComments = self.Module.HeaderComments
         StartPos = 0
         for Index in range(len(HeaderComments)):
@@ -1759,7 +1762,7 @@ class ModuleAutoGen(AutoGen):
             if os.path.exists (self.TimeStampPath):
                 os.remove (self.TimeStampPath)
 
-            SaveFileOnChange(self.TimeStampPath, "\n".join(FileSet), False)
+            SaveFileOnChange(self.TimeStampPath, "\n".join(sorted(FileSet)), False)
 
         # Ignore generating makefile when it is a binary module
         if self.IsBinaryModule:
-- 
2.32.0