From 9f9ba28043666e2945ca9dbee8cc3483341ab9c6 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 25 May 2016 03:11:02 -0700 Subject: [PATCH 1/8] NASM 2.12.02rc6 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 24f56abc..f700c745 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.12.02rc5 +2.12.02rc6 From 8e6feefb3bd67142777dff1e46255bd7547dc2f6 Mon Sep 17 00:00:00 2001 From: "knut st. osmundsen" Date: Mon, 30 May 2016 20:31:15 +0200 Subject: [PATCH 2/8] outobj.c: Fix for RIP relative addressing relocation. For 16-bit and 32-bit x86 code, the size and realsize() always matches as only jumps, calls and loops uses PC relative addressing and the address isn't followed by any other opcode bytes. In 64-bit mode there is RIP relative addressing which means the fixup location can be followed by an immediate value, meaning that size > realsize(). When the CPU is calculating the effective address, it takes the RIP at the end of the instruction and adds the fixed up relative address value to it. The linker's point of reference is the end of the fixup location (which is the end of the instruction for Jcc, CALL, LOOP[cc]). It is calculating distance between the target symbol and the end of the fixup location, and add this to the displacement value we are calculating here and storing at the fixup location. To get the right effect, we need to _reduce_ the displacement value by the number of bytes following the fixup. Example: data at address 0x100; REL4ADR at 0x050, 4 byte immediate, end of fixup at 0x054, end of instruction at 0x058. => size = 8. => realsize() -> 4 => CPU needs a value of: 0x100 - 0x058 = 0x0a8 => linker/loader will add: 0x100 - 0x054 = 0x0ac => We must add an addend of -4. => realsize() - size = -4. The code used to do size - realsize() at least since v0.90, probably because it wasn't needed... Signed-off-by: H. Peter Anvin --- output/outobj.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/output/outobj.c b/output/outobj.c index c82b5c26..c33339f7 100644 --- a/output/outobj.c +++ b/output/outobj.c @@ -1100,9 +1100,43 @@ static void obj_out(int32_t segto, const void *data, ldata = *(int64_t *)data; if (type != OUT_ADDRESS) { - ldata += size; - size = realsize(type, size); + /* + * For 16-bit and 32-bit x86 code, the size and realsize() always + * matches as only jumps, calls and loops uses PC relative + * addressing and the address isn't followed by any other opcode + * bytes. In 64-bit mode there is RIP relative addressing which + * means the fixup location can be followed by an immediate value, + * meaning that size > realsize(). + * + * When the CPU is calculating the effective address, it takes the + * RIP at the end of the instruction and adds the fixed up relative + * address value to it. + * + * The linker's point of reference is the end of the fixup location + * (which is the end of the instruction for Jcc, CALL, LOOP[cc]). + * It is calculating distance between the target symbol and the end + * of the fixup location, and add this to the displacement value we + * are calculating here and storing at the fixup location. + * + * To get the right effect, we need to _reduce_ the displacement + * value by the number of bytes following the fixup. + * + * Example: + * data at address 0x100; REL4ADR at 0x050, 4 byte immediate, + * end of fixup at 0x054, end of instruction at 0x058. + * => size = 8. + * => realsize() -> 4 + * => CPU needs a value of: 0x100 - 0x058 = 0x0a8 + * => linker/loader will add: 0x100 - 0x054 = 0x0ac + * => We must add an addend of -4. + * => realsize() - size = -4. + * + * The code used to do size - realsize() at least since v0.90, + * probably because it wasn't needed... + */ ldata -= size; + size = realsize(type, size); + ldata += size; } if (size > UINT_MAX) From 5e0eb0c08b1d014e9584ebea430f746f706b5d67 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Fri, 3 Jun 2016 23:57:10 -0700 Subject: [PATCH 3/8] NASM 2.12.02rc7 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index f700c745..a8739c8c 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.12.02rc6 +2.12.02rc7 From b41952986b3cd7558cb128790bb94e1f60fd088a Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 14 Jun 2016 18:01:21 -0700 Subject: [PATCH 4/8] outmacho: Fix relative relocations for 32-bit Mach-O (fix typo) This unbreaks checkin 84f6860ed53492976c9d79e9a8a0bdc60da78bc6, which was broken due to a transcription error of mine. Zenith432 was faultless in this case. This fixes bug report 3392355. Reported-by: Zenith432 Signed-off-by: H. Peter Anvin --- output/outmacho.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/output/outmacho.c b/output/outmacho.c index 6887d8f5..40df300e 100644 --- a/output/outmacho.c +++ b/output/outmacho.c @@ -465,7 +465,7 @@ static int64_t add_reloc(struct section *sect, int32_t section, r->snum = raa_read(extsyms, section); if (reltype == RL_BRANCH) r->type = X86_64_RELOC_BRANCH; - else if (reltype == GENERIC_RELOC_VANILLA) + else if (r->type == GENERIC_RELOC_VANILLA) adjust = -sect->size; } else { /* local */ From 65a8afcabafa6d477b7fd52807113bdce1defd1c Mon Sep 17 00:00:00 2001 From: Jim Kukunas Date: Mon, 13 Jun 2016 16:00:42 -0400 Subject: [PATCH 5/8] preproc: for include files, include correct path in filename The codeview backend needs to be able to open each source file passed in so that it can calculate its checksum. In order to take into account include paths, this patch updates the filename to include the path where the file was found. Signed-off-by: Jim Kukunas Signed-off-by: H. Peter Anvin [ hpa: resolved one conflict in preproc.c ] --- preproc.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/preproc.c b/preproc.c index 9dc3d88d..0cefa7d7 100644 --- a/preproc.c +++ b/preproc.c @@ -1508,7 +1508,7 @@ static bool in_list(const StrList *list, const char *str) * the end of the path. */ static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail, - bool missing_ok, const char *mode) + char **found_path, bool missing_ok, const char *mode) { FILE *fp; char *prefix = ""; @@ -1516,11 +1516,20 @@ static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail, int len = strlen(file); size_t prefix_len = 0; StrList *sl; + size_t path_len; while (1) { - sl = nasm_malloc(prefix_len+len+1+sizeof sl->next); + path_len = prefix_len + len + 1; + + sl = nasm_malloc(path_len + sizeof sl->next); memcpy(sl->str, prefix, prefix_len); memcpy(sl->str+prefix_len, file, len+1); + + if (found_path != NULL) { + *found_path = nasm_malloc(path_len); + memcpy(*found_path, sl->str, path_len); + } + fp = fopen(sl->str, mode); if (fp && dhead && !in_list(*dhead, sl->str)) { sl->next = NULL; @@ -1531,6 +1540,12 @@ static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail, } if (fp) return fp; + + if (found_path != NULL && *found_path != NULL) { + nasm_free(*found_path); + *found_path == NULL; + } + if (!ip) { if (!missing_ok) break; @@ -1569,7 +1584,7 @@ FILE *pp_input_fopen(const char *filename, const char *mode) StrList *xsl = NULL; StrList **xst = &xsl; - fp = inc_fopen(filename, &xsl, &xst, true, mode); + fp = inc_fopen(filename, &xsl, &xst, NULL, true, mode); if (xsl) nasm_free(xsl); return fp; @@ -2174,7 +2189,7 @@ static int do_directive(Token * tline) bool casesense; int k, m; int offset; - char *p, *pp; + char *p, *pp, *found_path; const char *mname; Include *inc; Context *ctx; @@ -2516,12 +2531,13 @@ static int do_directive(Token * tline) inc = nasm_malloc(sizeof(Include)); inc->next = istk; inc->conds = NULL; - inc->fp = inc_fopen(p, dephead, &deptail, pass == 0, "r"); + found_path = NULL; + inc->fp = inc_fopen(p, dephead, &deptail, &found_path, pass == 0, "r"); if (!inc->fp) { /* -MG given but file not found */ nasm_free(inc); } else { - inc->fname = src_set_fname(p); + inc->fname = src_set_fname(found_path ? found_path : p); inc->lineno = src_set_linnum(0); inc->lineinc = 1; inc->expansion = NULL; @@ -3259,7 +3275,7 @@ issue_error: if (t->type != TOK_INTERNAL_STRING) nasm_unquote(p, NULL); - fp = inc_fopen(p, &xsl, &xst, true, "r"); + fp = inc_fopen(p, &xsl, &xst, NULL, true, "r"); if (fp) { p = xsl->str; fclose(fp); /* Don't actually care about the file */ From fd2b1a6be993a07b24eebb446220ef8b236dd68e Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 16 Jun 2016 15:08:15 -0700 Subject: [PATCH 6/8] NASM 2.12.02rc8 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index a8739c8c..5cdf8c4a 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.12.02rc7 +2.12.02rc8 From f500d83ca43e214ca639da376fa20c4cf643221f Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 16 Jun 2016 15:28:09 -0700 Subject: [PATCH 7/8] preproc.c: fix assignment incorrectly coded as == Assignment is = not ==. Signed-off-by: H. Peter Anvin --- preproc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preproc.c b/preproc.c index 0cefa7d7..8400773b 100644 --- a/preproc.c +++ b/preproc.c @@ -1543,7 +1543,7 @@ static FILE *inc_fopen(const char *file, StrList **dhead, StrList ***dtail, if (found_path != NULL && *found_path != NULL) { nasm_free(*found_path); - *found_path == NULL; + *found_path = NULL; } if (!ip) { From 41d8a171952965f6a78b7e6a11cfeb9e3f5e43ad Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 16 Jun 2016 15:33:53 -0700 Subject: [PATCH 8/8] NASM 2.12.02rc9 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 5cdf8c4a..fe177f3d 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.12.02rc8 +2.12.02rc9