summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/nasm
diff options
context:
space:
mode:
authorJoshua Watt <jpewhacker@gmail.com>2019-12-08 22:03:11 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-12-15 09:10:46 +0000
commita14457c7967c6883344b8c3994fe3415129cfed0 (patch)
tree78669a109f9584efbf4959c420e6aac65cff3244 /meta/recipes-devtools/nasm
parent0b468662b8b67f5ad355a0d9ece422b3d7a7d091 (diff)
downloadpoky-a14457c7967c6883344b8c3994fe3415129cfed0.tar.gz
nasm: Add debug-prefix-map option
Adds an option to nasm to change the prefix for file paths encoded in the object files. This allows builds to be reproducible regardless of the build directory. (From OE-Core rev: ad5c914933c7b38296dcb8bba3c36aed45aacc32) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/nasm')
-rw-r--r--meta/recipes-devtools/nasm/nasm/0001-stdlib-Add-strlcat.patch117
-rw-r--r--meta/recipes-devtools/nasm/nasm/0002-Add-debug-prefix-map-option.patch325
-rw-r--r--meta/recipes-devtools/nasm/nasm_2.14.02.bb2
3 files changed, 444 insertions, 0 deletions
diff --git a/meta/recipes-devtools/nasm/nasm/0001-stdlib-Add-strlcat.patch b/meta/recipes-devtools/nasm/nasm/0001-stdlib-Add-strlcat.patch
new file mode 100644
index 0000000000..d94fd3290e
--- /dev/null
+++ b/meta/recipes-devtools/nasm/nasm/0001-stdlib-Add-strlcat.patch
@@ -0,0 +1,117 @@
1From 8a204171004fa0d7d21389530c744d215e99efb0 Mon Sep 17 00:00:00 2001
2From: Joshua Watt <JPEWhacker@gmail.com>
3Date: Tue, 19 Nov 2019 12:47:30 -0600
4Subject: [PATCH 1/2] stdlib: Add strlcat
5
6Adds strlcat which can be used to safely concatenate strings
7
8Upstream-Status: Submitted [https://bugzilla.nasm.us/show_bug.cgi?id=3392635]
9Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
10---
11 Makefile.in | 2 +-
12 configure.ac | 2 ++
13 include/compiler.h | 4 ++++
14 stdlib/strlcat.c | 43 +++++++++++++++++++++++++++++++++++++++++++
15 4 files changed, 50 insertions(+), 1 deletion(-)
16 create mode 100644 stdlib/strlcat.c
17
18diff --git a/Makefile.in b/Makefile.in
19index 32ef3d91..ff7eb447 100644
20--- a/Makefile.in
21+++ b/Makefile.in
22@@ -93,7 +93,7 @@ NASM = asm/nasm.$(O)
23 NDISASM = disasm/ndisasm.$(O)
24
25 LIBOBJ = stdlib/snprintf.$(O) stdlib/vsnprintf.$(O) stdlib/strlcpy.$(O) \
26- stdlib/strnlen.$(O) stdlib/strrchrnul.$(O) \
27+ stdlib/strnlen.$(O) stdlib/strrchrnul.$(O) stdlib/strlcat.$(O) \
28 \
29 nasmlib/ver.$(O) \
30 nasmlib/crc64.$(O) nasmlib/malloc.$(O) nasmlib/errfile.$(O) \
31diff --git a/configure.ac b/configure.ac
32index 38b3b596..b4e88778 100644
33--- a/configure.ac
34+++ b/configure.ac
35@@ -152,6 +152,7 @@ AC_CHECK_FUNCS([vsnprintf _vsnprintf])
36 AC_CHECK_FUNCS([snprintf _snprintf])
37 AC_CHECK_FUNCS([strlcpy])
38 AC_CHECK_FUNCS([strrchrnul])
39+AC_CHECK_FUNCS([strlcat])
40
41 dnl These types are POSIX-specific, and Windows does it differently...
42 AC_CHECK_TYPES([struct _stati64])
43@@ -170,6 +171,7 @@ AC_CHECK_DECLS(strsep)
44 AC_CHECK_DECLS(strlcpy)
45 AC_CHECK_DECLS(strnlen)
46 AC_CHECK_DECLS(strrchrnul)
47+AC_CHECK_DECLS(strlcat)
48
49 dnl Check for missing types
50 AC_TYPE_UINTPTR_T
51diff --git a/include/compiler.h b/include/compiler.h
52index 4178c98e..8153d297 100644
53--- a/include/compiler.h
54+++ b/include/compiler.h
55@@ -159,6 +159,10 @@ size_t strlcpy(char *, const char *, size_t);
56 char *strrchrnul(const char *, int);
57 #endif
58
59+#if !defined(HAVE_STRLCAT) || !HAVE_DECL_STRLCAT
60+size_t strlcat(char *, const char *, size_t);
61+#endif
62+
63 #ifndef __cplusplus /* C++ has false, true, bool as keywords */
64 # ifdef HAVE_STDBOOL_H
65 # include <stdbool.h>
66diff --git a/stdlib/strlcat.c b/stdlib/strlcat.c
67new file mode 100644
68index 00000000..7084d460
69--- /dev/null
70+++ b/stdlib/strlcat.c
71@@ -0,0 +1,43 @@
72+/*
73+ * Copyright (c) 2019 Garmin Ltd. or its subsidiaries
74+ *
75+ * Permission to use, copy, modify, and distribute this software for any
76+ * purpose with or without fee is hereby granted, provided that the above
77+ * copyright notice and this permission notice appear in all copies.
78+ *
79+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
80+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
81+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
82+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
83+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
84+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
85+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
86+ */
87+
88+#include "compiler.h"
89+
90+/*
91+ * Concatenate src string to dest of size size. The destination buffer will
92+ * have no more than size-1 character when the operation finishes. Always NUL
93+ * terminates, unless size == 0 or dest has no NUL terminator. Returns
94+ * strlen(initial dest) + strlen(src); if retval >= size, truncation occurred.
95+ */
96+#ifndef HAVE_STRLCAT
97+
98+size_t strlcat(char *dest, const char *src, size_t size)
99+{
100+ size_t n;
101+
102+ /* find the NULL terminator in dest */
103+ for (n = 0; i < size && dest[n] != '\0'; n++)
104+ ;
105+
106+ /* destination was not NULL terminated. Return the initial size */
107+ if (n == size)
108+ return size;
109+
110+ return strlcpy(&dest[n], src, size - n) + n;
111+}
112+
113+#endif
114+
115--
1162.23.0
117
diff --git a/meta/recipes-devtools/nasm/nasm/0002-Add-debug-prefix-map-option.patch b/meta/recipes-devtools/nasm/nasm/0002-Add-debug-prefix-map-option.patch
new file mode 100644
index 0000000000..bbfae2e8a5
--- /dev/null
+++ b/meta/recipes-devtools/nasm/nasm/0002-Add-debug-prefix-map-option.patch
@@ -0,0 +1,325 @@
1From fa677c1caf6b8192971920cf5c1aa8cb33c74605 Mon Sep 17 00:00:00 2001
2From: Joshua Watt <JPEWhacker@gmail.com>
3Date: Tue, 19 Nov 2019 13:12:17 -0600
4Subject: [PATCH 2/2] Add --debug-prefix-map option
5
6Adds an option to remap file prefixes in output object files. This is
7analogous to the "-fdebug-prefix-map" option in GCC, and allows files to
8be built in a reproducible manner regardless of the build directory.
9
10Upstream-Status: Submitted [https://bugzilla.nasm.us/show_bug.cgi?id=3392635]
11Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
12---
13 asm/nasm.c | 28 ++++++++++++++++++++++++++--
14 include/nasmlib.h | 9 +++++++++
15 nasm.txt | 4 ++++
16 nasmlib/filename.c | 20 ++++++++++++++++++++
17 output/outas86.c | 4 +++-
18 output/outcoff.c | 4 ++--
19 output/outelf.c | 8 ++++----
20 output/outieee.c | 2 +-
21 output/outobj.c | 2 +-
22 stdlib/strlcat.c | 2 +-
23 test/elfdebugprefix.asm | 6 ++++++
24 test/performtest.pl | 12 ++++++++++--
25 12 files changed, 87 insertions(+), 14 deletions(-)
26 create mode 100644 test/elfdebugprefix.asm
27
28diff --git a/asm/nasm.c b/asm/nasm.c
29index 1c5a5fc5..5d45103c 100644
30--- a/asm/nasm.c
31+++ b/asm/nasm.c
32@@ -841,7 +841,8 @@ enum text_options {
33 OPT_BEFORE,
34 OPT_LIMIT,
35 OPT_KEEP_ALL,
36- OPT_NO_LINE
37+ OPT_NO_LINE,
38+ OPT_DEBUG_PREFIX_MAP
39 };
40 struct textargs {
41 const char *label;
42@@ -866,6 +867,7 @@ static const struct textargs textopts[] = {
43 {"limit-", OPT_LIMIT, true, 0},
44 {"keep-all", OPT_KEEP_ALL, false, 0},
45 {"no-line", OPT_NO_LINE, false, 0},
46+ {"debug-prefix-map", OPT_DEBUG_PREFIX_MAP, true, 0},
47 {NULL, OPT_BOGUS, false, 0}
48 };
49
50@@ -1217,6 +1219,26 @@ static bool process_arg(char *p, char *q, int pass)
51 case OPT_NO_LINE:
52 pp_noline = true;
53 break;
54+ case OPT_DEBUG_PREFIX_MAP: {
55+ struct debug_prefix_list *d;
56+ char *c;
57+ c = strchr(param, '=');
58+
59+ if (!c) {
60+ nasm_error(ERR_NONFATAL | ERR_NOFILE | ERR_USAGE,
61+ "option `--%s' must be of the form `BASE=DEST'", p);
62+ break;
63+ }
64+
65+ *c = '\0';
66+ d = nasm_malloc(sizeof(*d));
67+ d->next = debug_prefixes;
68+ d->base = nasm_strdup(param);
69+ d->dest = nasm_strdup(c + 1);
70+ debug_prefixes = d;
71+ *c = '=';
72+ }
73+ break;
74 case OPT_HELP:
75 help(0);
76 exit(0);
77@@ -2010,7 +2032,9 @@ static void help(const char xopt)
78 " --lpostfix str append the given string to all other symbols\n"
79 " --keep-all output files will not be removed even if an error happens\n"
80 " --no-line ignore %%line directives in input\n"
81- " --limit-X val set execution limit X\n");
82+ " --limit-X val set execution limit X\n"
83+ " --debug-prefix-map base=dest\n"
84+ " remap paths starting with 'base' to 'dest' in output files\n");
85
86 for (i = 0; i <= LIMIT_MAX; i++) {
87 printf(" %-15s %s (default ",
88diff --git a/include/nasmlib.h b/include/nasmlib.h
89index e57d0e6d..cf921547 100644
90--- a/include/nasmlib.h
91+++ b/include/nasmlib.h
92@@ -195,10 +195,19 @@ int64_t readstrnum(char *str, int length, bool *warn);
93 */
94 int32_t seg_alloc(void);
95
96+struct debug_prefix_list {
97+ struct debug_prefix_list *next;
98+ char *base;
99+ char *dest;
100+};
101+
102+extern struct debug_prefix_list *debug_prefixes;
103+
104 /*
105 * Add/replace or remove an extension to the end of a filename
106 */
107 const char *filename_set_extension(const char *inname, const char *extension);
108+char *filename_debug_remap(char *dest, char const *inname, size_t len);
109
110 /*
111 * Utility macros...
112diff --git a/nasm.txt b/nasm.txt
113index a28202f9..443c06b2 100644
114--- a/nasm.txt
115+++ b/nasm.txt
116@@ -147,6 +147,10 @@ OPTIONS
117 Prepend or append (respectively) the given argument to all global or
118 extern variables.
119
120+--debug-prefix-map 'BASE=DEST'::
121+ Map file names beginning with 'BASE' to 'DEST' when encoding them in
122+ output object files.
123+
124 SYNTAX
125 ------
126 This man page does not fully describe the syntax of *nasm*'s assembly language,
127diff --git a/nasmlib/filename.c b/nasmlib/filename.c
128index 172ae0bc..fda2be41 100644
129--- a/nasmlib/filename.c
130+++ b/nasmlib/filename.c
131@@ -39,6 +39,8 @@
132 #include "nasmlib.h"
133 #include "error.h"
134
135+struct debug_prefix_list *debug_prefixes = NULL;
136+
137 /*
138 * Add/modify a filename extension, assumed to be a period-delimited
139 * field at the very end of the filename. Returns a newly allocated
140@@ -61,3 +63,21 @@ const char *filename_set_extension(const char *inname, const char *extension)
141
142 return p;
143 }
144+
145+char *filename_debug_remap(char *dest, char const *in, size_t len)
146+{
147+ struct debug_prefix_list *d;
148+ size_t n;
149+
150+ for (d = debug_prefixes; d != NULL; d = d->next) {
151+ n = strlen(d->base);
152+ if (strncmp(in, d->base, n) == 0) {
153+ strlcpy(dest, d->dest, len);
154+ strlcat(dest, &in[n], len);
155+ return dest;
156+ }
157+ }
158+
159+ strlcpy(dest, in, len);
160+ return dest;
161+}
162diff --git a/output/outas86.c b/output/outas86.c
163index 3f9867b9..d5f4f966 100644
164--- a/output/outas86.c
165+++ b/output/outas86.c
166@@ -113,6 +113,8 @@ static void as86_sect_write(struct Section *, const uint8_t *,
167
168 static void as86_init(void)
169 {
170+ char filename[FILENAME_MAX];
171+
172 stext.data = saa_init(1L);
173 stext.datalen = 0L;
174 stext.head = stext.last = NULL;
175@@ -134,7 +136,7 @@ static void as86_init(void)
176 strslen = 0;
177
178 /* as86 module name = input file minus extension */
179- as86_add_string(filename_set_extension(inname, ""));
180+ as86_add_string(filename_debug_remap(filename, filename_set_extension(inname, ""), sizeof(filename)));
181 }
182
183 static void as86_cleanup(void)
184diff --git a/output/outcoff.c b/output/outcoff.c
185index a2fd302c..bcf576fb 100644
186--- a/output/outcoff.c
187+++ b/output/outcoff.c
188@@ -1070,14 +1070,14 @@ static void coff_symbol(char *name, int32_t strpos, int32_t value,
189
190 static void coff_write_symbols(void)
191 {
192- char filename[18];
193+ char filename[19];
194 uint32_t i;
195
196 /*
197 * The `.file' record, and the file name auxiliary record.
198 */
199 coff_symbol(".file", 0L, 0L, -2, 0, 0x67, 1);
200- strncpy(filename, inname, 18);
201+ filename_debug_remap(filename, inname, 19);
202 nasm_write(filename, 18, ofile);
203
204 /*
205diff --git a/output/outelf.c b/output/outelf.c
206index de99d076..203b5dc0 100644
207--- a/output/outelf.c
208+++ b/output/outelf.c
209@@ -1,5 +1,5 @@
210 /* ----------------------------------------------------------------------- *
211- *
212+ *
213 * Copyright 1996-2017 The NASM Authors - All Rights Reserved
214 * See the file AUTHORS included with the NASM distribution for
215 * the specific copyright holders.
216@@ -14,7 +14,7 @@
217 * copyright notice, this list of conditions and the following
218 * disclaimer in the documentation and/or other materials provided
219 * with the distribution.
220- *
221+ *
222 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
223 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
224 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
225@@ -315,7 +315,7 @@ elf_directive(enum directive directive, char *value, int pass)
226
227 static void elf_init(void)
228 {
229- strlcpy(elf_module, inname, sizeof(elf_module));
230+ filename_debug_remap(elf_module, inname, sizeof(elf_module));
231 sects = NULL;
232 nsects = sectlen = 0;
233 syms = saa_init((int32_t)sizeof(struct elf_symbol));
234@@ -868,7 +868,7 @@ static void elf32_out(int32_t segto, const void *data,
235 " segment base references");
236 } else {
237 if (wrt == NO_SEG) {
238- /*
239+ /*
240 * The if() is a hack to deal with compilers which
241 * don't handle switch() statements with 64-bit
242 * expressions.
243diff --git a/output/outieee.c b/output/outieee.c
244index 3a28942d..f61824e4 100644
245--- a/output/outieee.c
246+++ b/output/outieee.c
247@@ -209,7 +209,7 @@ static void ieee_unqualified_name(char *, char *);
248 */
249 static void ieee_init(void)
250 {
251- strlcpy(ieee_infile, inname, sizeof(ieee_infile));
252+ filename_debug_remap(ieee_infile, inname, sizeof(ieee_infile));
253 any_segs = false;
254 fpubhead = NULL;
255 fpubtail = &fpubhead;
256diff --git a/output/outobj.c b/output/outobj.c
257index b4f2c499..55bba4a1 100644
258--- a/output/outobj.c
259+++ b/output/outobj.c
260@@ -640,7 +640,7 @@ static enum directive_result obj_directive(enum directive, char *, int);
261
262 static void obj_init(void)
263 {
264- strlcpy(obj_infile, inname, sizeof(obj_infile));
265+ filename_debug_remap(obj_infile, inname, sizeof(obj_infile));
266 first_seg = seg_alloc();
267 any_segs = false;
268 fpubhead = NULL;
269diff --git a/stdlib/strlcat.c b/stdlib/strlcat.c
270index 7084d460..ee93dea3 100644
271--- a/stdlib/strlcat.c
272+++ b/stdlib/strlcat.c
273@@ -29,7 +29,7 @@ size_t strlcat(char *dest, const char *src, size_t size)
274 size_t n;
275
276 /* find the NULL terminator in dest */
277- for (n = 0; i < size && dest[n] != '\0'; n++)
278+ for (n = 0; n < size && dest[n] != '\0'; n++)
279 ;
280
281 /* destination was not NULL terminated. Return the initial size */
282diff --git a/test/elfdebugprefix.asm b/test/elfdebugprefix.asm
283new file mode 100644
284index 00000000..a67ba29c
285--- /dev/null
286+++ b/test/elfdebugprefix.asm
287@@ -0,0 +1,6 @@
288+;Testname=unoptimized; Arguments=-O0 --debug-prefix-map elf=ELF -felf -oelfdebugprefix.o; Files=stdout stderr elfdebugprefix.o; Validate=readelf --wide --symbols elfdebugprefix.o | grep 'FILE.*ELFdebugprefix.asm'
289+
290+ SECTION .text
291+test: ; [1]
292+ ret
293+
294diff --git a/test/performtest.pl b/test/performtest.pl
295index f7865b39..096f9604 100755
296--- a/test/performtest.pl
297+++ b/test/performtest.pl
298@@ -42,14 +42,22 @@ sub perform {
299 TEST:
300 while(<TESTFILE>) {
301 #See if there is a test case
302- last unless /Testname=(.*);\s*Arguments=(.*);\s*Files=(.*)/;
303- my ($subname, $arguments, $files) = ($1, $2, $3);
304+ last unless /Testname=(.*);\s*Arguments=(.*);\s*Files=([^;]*)(?:;\s*Validate=(.*))?/;
305+ my ($subname, $arguments, $files, $validate) = ($1, $2, $3, $4);
306+ chomp $files;
307 debugprint("$subname | $arguments | $files");
308
309 #Call nasm with this test case
310 system("$nasm $arguments $testpath > $stdoutfile 2> $stderrfile");
311 debugprint("$nasm $arguments $testpath > $stdoutfile 2> $stderrfile ----> $?");
312
313+ if($validate) {
314+ if(system("$validate >> $stdoutfile 2>> $stderrfile") != 0) {
315+ print "Test $testname/$subname validation failed\n";
316+ $globalresult = 1;
317+ }
318+ }
319+
320 #Move the output to the test dir
321 mkpath("$outputdir/$testname/$subname");
322 foreach(split / /,$files) {
323--
3242.23.0
325
diff --git a/meta/recipes-devtools/nasm/nasm_2.14.02.bb b/meta/recipes-devtools/nasm/nasm_2.14.02.bb
index bd4ecea8b6..f8a8d76e99 100644
--- a/meta/recipes-devtools/nasm/nasm_2.14.02.bb
+++ b/meta/recipes-devtools/nasm/nasm_2.14.02.bb
@@ -6,6 +6,8 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=90904486f8fbf1861cf42752e1a39efe"
6SRC_URI = "http://www.nasm.us/pub/nasm/releasebuilds/${PV}/nasm-${PV}.tar.bz2 \ 6SRC_URI = "http://www.nasm.us/pub/nasm/releasebuilds/${PV}/nasm-${PV}.tar.bz2 \
7 file://CVE-2018-19755.patch \ 7 file://CVE-2018-19755.patch \
8 file://CVE-2019-14248.patch \ 8 file://CVE-2019-14248.patch \
9 file://0001-stdlib-Add-strlcat.patch \
10 file://0002-Add-debug-prefix-map-option.patch \
9 " 11 "
10 12
11SRC_URI[md5sum] = "3f489aa48ad2aa1f967dc5e293bbd06f" 13SRC_URI[md5sum] = "3f489aa48ad2aa1f967dc5e293bbd06f"