Temporaries in macros need a unique prefix; WSAA*() macros to header
authorH. Peter Anvin <hpa@zytor.com>
Thu, 10 Apr 2008 21:56:09 +0000 (14:56 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Thu, 10 Apr 2008 21:56:09 +0000 (14:56 -0700)
When using temporaries in macros, given them a unique prefix to avoid
namespace collisions when using one macro inside another.

Move the WSAA*() macros from outelf32/outelf64 to a separate header
file.

Makefile.in
Mkfiles/msvc.mak
Mkfiles/netware.mak
Mkfiles/openwcom.mak
Mkfiles/owlinux.mak
nasmlib.h
output/outelf32.c
output/outelf64.c
wsaa.h [new file with mode: 0644]

index f9d4a3d..287340f 100644 (file)
@@ -271,9 +271,9 @@ output/outcoff.$(O): output/outcoff.c compiler.h config.h insnsi.h nasm.h \
 output/outdbg.$(O): output/outdbg.c compiler.h config.h insnsi.h nasm.h \
  nasmlib.h outform.h regs.h version.h
 output/outelf32.$(O): output/outelf32.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h outform.h regs.h stdscan.h version.h
+ nasmlib.h outform.h regs.h stdscan.h version.h wsaa.h
 output/outelf64.$(O): output/outelf64.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h outform.h regs.h stdscan.h version.h
+ nasmlib.h outform.h regs.h stdscan.h version.h wsaa.h
 output/outieee.$(O): output/outieee.c compiler.h config.h insnsi.h nasm.h \
  nasmlib.h outform.h regs.h version.h
 output/outmacho.$(O): output/outmacho.c compiler.h config.h insnsi.h nasm.h \
index 5d11134..bf8bc01 100644 (file)
@@ -219,9 +219,9 @@ output/outcoff.$(O): output/outcoff.c compiler.h insnsi.h nasm.h nasmlib.h \
 output/outdbg.$(O): output/outdbg.c compiler.h insnsi.h nasm.h nasmlib.h \
  outform.h regs.h version.h
 output/outelf32.$(O): output/outelf32.c compiler.h insnsi.h nasm.h nasmlib.h \
- outform.h regs.h stdscan.h version.h
+ outform.h regs.h stdscan.h version.h wsaa.h
 output/outelf64.$(O): output/outelf64.c compiler.h insnsi.h nasm.h nasmlib.h \
- outform.h regs.h stdscan.h version.h
+ outform.h regs.h stdscan.h version.h wsaa.h
 output/outieee.$(O): output/outieee.c compiler.h insnsi.h nasm.h nasmlib.h \
  outform.h regs.h version.h
 output/outmacho.$(O): output/outmacho.c compiler.h insnsi.h nasm.h nasmlib.h \
index 67bf1b3..6f6e502 100644 (file)
@@ -184,9 +184,9 @@ output/outcoff.o: output/outcoff.c compiler.h config.h insnsi.h nasm.h \
 output/outdbg.o: output/outdbg.c compiler.h config.h insnsi.h nasm.h \
  nasmlib.h outform.h regs.h version.h
 output/outelf32.o: output/outelf32.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h outform.h regs.h stdscan.h version.h
+ nasmlib.h outform.h regs.h stdscan.h version.h wsaa.h
 output/outelf64.o: output/outelf64.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h outform.h regs.h stdscan.h version.h
+ nasmlib.h outform.h regs.h stdscan.h version.h wsaa.h
 output/outieee.o: output/outieee.c compiler.h config.h insnsi.h nasm.h \
  nasmlib.h outform.h regs.h version.h
 output/outmacho.o: output/outmacho.c compiler.h config.h insnsi.h nasm.h \
index 1c5e202..dbbc198 100644 (file)
@@ -245,9 +245,9 @@ output\outcoff.$(O): output\outcoff.c compiler.h insnsi.h nasm.h nasmlib.h &
 output\outdbg.$(O): output\outdbg.c compiler.h insnsi.h nasm.h nasmlib.h &
  outform.h regs.h version.h
 output\outelf32.$(O): output\outelf32.c compiler.h insnsi.h nasm.h nasmlib.h &
- outform.h regs.h stdscan.h version.h
+ outform.h regs.h stdscan.h version.h wsaa.h
 output\outelf64.$(O): output\outelf64.c compiler.h insnsi.h nasm.h nasmlib.h &
- outform.h regs.h stdscan.h version.h
+ outform.h regs.h stdscan.h version.h wsaa.h
 output\outieee.$(O): output\outieee.c compiler.h insnsi.h nasm.h nasmlib.h &
  outform.h regs.h version.h
 output\outmacho.$(O): output\outmacho.c compiler.h insnsi.h nasm.h nasmlib.h &
index 05cd023..aed1188 100644 (file)
@@ -255,9 +255,9 @@ output/outcoff.$(O): output/outcoff.c compiler.h insnsi.h nasm.h nasmlib.h \
 output/outdbg.$(O): output/outdbg.c compiler.h insnsi.h nasm.h nasmlib.h \
  outform.h regs.h version.h
 output/outelf32.$(O): output/outelf32.c compiler.h insnsi.h nasm.h nasmlib.h \
- outform.h regs.h stdscan.h version.h
+ outform.h regs.h stdscan.h version.h wsaa.h
 output/outelf64.$(O): output/outelf64.c compiler.h insnsi.h nasm.h nasmlib.h \
- outform.h regs.h stdscan.h version.h
+ outform.h regs.h stdscan.h version.h wsaa.h
 output/outieee.$(O): output/outieee.c compiler.h insnsi.h nasm.h nasmlib.h \
  outform.h regs.h version.h
 output/outmacho.$(O): output/outmacho.c compiler.h insnsi.h nasm.h nasmlib.h \
index ed628c7..2f9f87d 100644 (file)
--- a/nasmlib.h
+++ b/nasmlib.h
@@ -206,8 +206,8 @@ void standard_extension(char *inname, char *outname, char *extension,
 
 #define WRITEADDR(p,v,s)                       \
     do {                                       \
-       uint64_t _v = (v);                      \
-       memcpy((p), &_v, (s));                  \
+       uint64_t _wa_v = (v);                   \
+       memcpy((p), &_wa_v, (s));               \
        (p) += (s);                             \
     } while (0)
 
@@ -215,54 +215,54 @@ void standard_extension(char *inname, char *outname, char *extension,
 
 #define WRITECHAR(p,v)                         \
     do {                                       \
-       uint8_t *_p = (uint8_t *)(p);           \
-       uint8_t _v = (v);                       \
-       _p[0] = _v;                             \
-       (p) = (void *)(_p + 1);                 \
+       uint8_t *_wc_p = (uint8_t *)(p);        \
+       uint8_t _wc_v = (v);                    \
+       _wc_p[0] = _wc_v;                       \
+       (p) = (void *)(_wc_p + 1);              \
     } while (0)
 
 #define WRITESHORT(p,v)                                \
     do {                                       \
-       uint8_t *_p = (uint8_t *)(p);           \
-       uint16_t _v = (v);                      \
-       _p[0] = _v;                             \
-       _p[1] = _v >> 8;                        \
-       (p) = (void *)(_p + 2);                 \
+       uint8_t *_ws_p = (uint8_t *)(p);        \
+       uint16_t _ws_v = (v);                   \
+       _ws_p[0] = _ws_v;                       \
+       _ws_p[1] = _ws_v >> 8;                  \
+       (p) = (void *)(_ws_p + 2);              \
     } while (0)
 
 #define WRITELONG(p,v)                         \
     do {                                       \
-       uint8_t *_p = (uint8_t *)(p);           \
-       uint32_t _v = (v);                      \
-       _p[0] = _v;                             \
-       _p[1] = _v >> 8;                        \
-       _p[2] = _v >> 16;                       \
-       _p[3] = _v >> 24;                       \
-       (p) = (void *)(_p + 4);                 \
+       uint8_t *_wl_p = (uint8_t *)(p);        \
+       uint32_t _wl_v = (v);                   \
+       _wl_p[0] = _wl_v;                       \
+       _wl_p[1] = _wl_v >> 8;                  \
+       _wl_p[2] = _wl_v >> 16;                 \
+       _wl_p[3] = _wl_v >> 24;                 \
+       (p) = (void *)(_wl_p + 4);              \
     } while (0)
 
 #define WRITEDLONG(p,v)                                \
     do {                                       \
-       uint8_t *_p = (uint8_t *)(p);           \
-       uint64_t _v = (v);                      \
-       _p[0] = _v;                             \
-       _p[1] = _v >> 8;                        \
-       _p[2] = _v >> 16;                       \
-       _p[3] = _v >> 24;                       \
-       _p[4] = _v >> 32;                       \
-       _p[5] = _v >> 40;                       \
-       _p[6] = _v >> 48;                       \
-       _p[7] = _v >> 56;                       \
-       (p) = (void *)(_p + 8);                 \
+       uint8_t *_wq_p = (uint8_t *)(p);        \
+       uint64_t _wq_v = (v);                   \
+       _wq_p[0] = _wq_v;                       \
+       _wq_p[1] = _wq_v >> 8;                  \
+       _wq_p[2] = _wq_v >> 16;                 \
+       _wq_p[3] = _wq_v >> 24;                 \
+       _wq_p[4] = _wq_v >> 32;                 \
+       _wq_p[5] = _wq_v >> 40;                 \
+       _wq_p[6] = _wq_v >> 48;                 \
+       _wq_p[7] = _wq_v >> 56;                 \
+       (p) = (void *)(_wq_p + 8);              \
     } while (0)
 
 #define WRITEADDR(p,v,s)                       \
     do {                                       \
-       int _s = (s);                           \
-       uint64_t _v = (v);                      \
-       while (_s--) {                          \
-           WRITECHAR(p,_v);                    \
-           _v >>= 8;                           \
+       int _wa_s = (s);                        \
+       uint64_t _wa_v = (v);                   \
+       while (_wa_s--) {                       \
+           WRITECHAR(p,_wa_v);                 \
+           _wa_v >>= 8;                        \
        }                                       \
     } while(0)
 
index 2bb6355..491b9ae 100644 (file)
@@ -19,6 +19,7 @@
 #include "nasmlib.h"
 #include "stdscan.h"
 #include "outform.h"
+#include "wsaa.h"
 
 #ifdef OF_ELF32
 
@@ -167,55 +168,7 @@ extern struct ofmt of_elf;
 #define    DW_LANG_Mips_Assembler  0x8001
 
 #define SOC(ln,aa) ln - line_base + (line_range * aa) + opcode_base
-#if X86_MEMORY
-
-#define WSAACHAR(s,p,v)                                \
-    do {                                       \
-       *(uint8_t *)(p) = (v);                  \
-       saa_wbytes(s, p, 1);                    \
-    } while (0)
-
-#define WSAASHORT(s,p,v)                       \
-    do {                                       \
-       *(uint16_t *)(p) = (v);                 \
-       saa_wbytes(s, p, 2);                    \
-    } while (0)
-
-#define WSAALONG(s,p,v)                                \
-    do {                                       \
-       *(uint32_t *)(p) = (v);                 \
-       saa_wbytes(s, p, 4);                    \
-    } while (0)
-
-#else /* !X86_MEMORY */
-
-#define WSAACHAR(s,p,v)                        \
-    do {                                       \
-       *(uint8_t *)p = (v);                    \
-       saa_wbytes(s, p, 1);                    \
-    } while (0)
-
-#define WSAASHORT(s,p,v)                       \
-    do {                                       \
-       uint16_t _v = (v);                      \
-       uint8_t *_p = (uint8_t *)(p);           \
-       _p[0] = _v;                             \
-       _p[1] = _v >> 8;                        \
-       saa_wbytes(s, _p, 2);                   \
-    } while (0)
-
-#define WSAALONG(s,p,v)                                \
-    do {                                       \
-       uint32_t _v = (v);                      \
-       uint8_t *_p = (uint8_t *)(p);           \
-       _p[0] = _v;                             \
-       _p[1] = _v >> 8;                        \
-       _p[2] = _v >> 16;                       \
-       _p[3] = _v >> 24;                       \
-       saa_wbytes(s, _p, 4);                   \
-    } while (0)
 
-#endif
 static const char align_str[SEG_ALIGN] = "";    /* ANSI will pad this with 0s */
 
 static struct ELF_SECTDATA {
@@ -1544,7 +1497,7 @@ static int elf_set_info(enum geninfo type, char **val)
     return 0;
 }
 static struct dfmt df_dwarf = {
-    "elf32 (i386) dwarf debug format for Linux",
+    "elf32 (X86_64) dwarf debug format for Linux",
     "dwarf",
     debug32_init,
     dwarf32_linenum,
index 0c57710..e7abba6 100644 (file)
@@ -18,6 +18,7 @@
 #include "nasmlib.h"
 #include "stdscan.h"
 #include "outform.h"
+#include "wsaa.h"
 
 /* Definitions in lieu of elf.h */
 #define SHT_NULL 0                     /* Inactive section header */
 #define    DW_LANG_Mips_Assembler  0x8001
 
 #define SOC(ln,aa) ln - line_base + (line_range * aa) + opcode_base
-#if X86_MEMORY
-
-#define WSAACHAR(s,p,v)                                \
-    do {                                       \
-       *(uint8_t *)(p) = (v);                  \
-       saa_wbytes(s, p, 1);                    \
-    } while (0)
-
-#define WSAASHORT(s,p,v)                       \
-    do {                                       \
-       *(uint16_t *)(p) = (v);                 \
-       saa_wbytes(s, p, 2);                    \
-    } while (0)
-
-#define WSAALONG(s,p,v)                                \
-    do {                                       \
-       *(uint32_t *)(p) = (v);                 \
-       saa_wbytes(s, p, 4);                    \
-    } while (0)
-
-#define WSAADLONG(s,p,v)                       \
-    do {                                       \
-       *(uint64_t *)(p) = (v);                 \
-       saa_wbytes(s, p, 8);                    \
-    } while (0)
-
-#else /* !X86_MEMORY */
-
-#define WSAACHAR(s,p,v)                        \
-    do {                                       \
-       *(uint8_t *)p = (v);                    \
-       saa_wbytes(s, p, 1);                    \
-    } while (0)
-
-#define WSAASHORT(s,p,v)                       \
-    do {                                       \
-       uint16_t _v = (v);                      \
-       uint8_t *_p = (uint8_t *)(p);           \
-       _p[0] = _v;                             \
-       _p[1] = _v >> 8;                        \
-       saa_wbytes(s, _p, 2);                   \
-    } while (0)
-
-#define WSAALONG(s,p,v)                                \
-    do {                                       \
-       uint32_t _v = (v);                      \
-       uint8_t *_p = (uint8_t *)(p);           \
-       _p[0] = _v;                             \
-       _p[1] = _v >> 8;                        \
-       _p[2] = _v >> 16;                       \
-       _p[3] = _v >> 24;                       \
-       saa_wbytes(s, _p, 4);                   \
-    } while (0)
-
-#define WSAADLONG(s,p,v)                       \
-    do {                                       \
-       uint64_t _v = (v);                      \
-       uint8_t *_p = (uint8_t *)(p);           \
-       _p[0] = _v;                             \
-       _p[1] = _v >> 8;                        \
-       _p[2] = _v >> 16;                       \
-       _p[3] = _v >> 24;                       \
-       _p[4] = _v >> 32;                       \
-       _p[5] = _v >> 40;                       \
-       _p[6] = _v >> 48;                       \
-       _p[7] = _v >> 56;                       \
-       saa_wbytes(s, _p, 8);                   \
-    } while (0)
-
-#endif
 
 typedef uint32_t Elf64_Word;
 typedef uint64_t Elf64_Xword;
diff --git a/wsaa.h b/wsaa.h
new file mode 100644 (file)
index 0000000..69124d6
--- /dev/null
+++ b/wsaa.h
@@ -0,0 +1,78 @@
+#ifndef NASM_WSAA_H
+#define NASM_WSAA_H
+
+#include "compiler.h"
+#include "nasmlib.h"
+
+#if X86_MEMORY
+
+#define WSAACHAR(s,p,v)                                \
+    do {                                       \
+       *(uint8_t *)(p) = (v);                  \
+       saa_wbytes(s, p, 1);                    \
+    } while (0)
+
+#define WSAASHORT(s,p,v)                       \
+    do {                                       \
+       *(uint16_t *)(p) = (v);                 \
+       saa_wbytes(s, p, 2);                    \
+    } while (0)
+
+#define WSAALONG(s,p,v)                                \
+    do {                                       \
+       *(uint32_t *)(p) = (v);                 \
+       saa_wbytes(s, p, 4);                    \
+    } while (0)
+
+#define WSAADLONG(s,p,v)                       \
+    do {                                       \
+       *(uint64_t *)(p) = (v);                 \
+       saa_wbytes(s, p, 8);                    \
+    } while (0)
+
+#else /* !X86_MEMORY */
+
+#define WSAACHAR(s,p,v)                        \
+    do {                                       \
+       *(uint8_t *)(p) = (v);                  \
+       saa_wbytes(s, p, 1);                    \
+    } while (0)
+
+#define WSAASHORT(s,p,v)                       \
+    do {                                       \
+       uint16_t _wss_v = (v);                  \
+       uint8_t *_wss_p = (uint8_t *)(p);       \
+       _wss_p[0] = _wss_v;                     \
+       _wss_p[1] = _wss_v >> 8;                \
+       saa_wbytes(s, _wss_p, 2);               \
+    } while (0)
+
+#define WSAALONG(s,p,v)                                \
+    do {                                       \
+       uint32_t _wsl_v = (v);                  \
+       uint8_t *_wsl_p = (uint8_t *)(p);       \
+       _wsl_p[0] = _wsl_v;                     \
+       _wsl_p[1] = _wsl_v >> 8;                \
+       _wsl_p[2] = _wsl_v >> 16;               \
+       _wsl_p[3] = _wsl_v >> 24;               \
+       saa_wbytes(s, _wsl_p, 4);               \
+    } while (0)
+
+#define WSAADLONG(s,p,v)                       \
+    do {                                       \
+       uint64_t _wsq_v = (v);                  \
+       uint8_t *_wsq_p = (uint8_t *)(p);       \
+       _wsq_p[0] = _wsq_v;                     \
+       _wsq_p[1] = _wsq_v >> 8;                \
+       _wsq_p[2] = _wsq_v >> 16;               \
+       _wsq_p[3] = _wsq_v >> 24;               \
+       _wsq_p[4] = _wsq_v >> 32;               \
+       _wsq_p[5] = _wsq_v >> 40;               \
+       _wsq_p[6] = _wsq_v >> 48;               \
+       _wsq_p[7] = _wsq_v >> 56;               \
+       saa_wbytes(s, _wsq_p, 8);               \
+    } while (0)
+
+#endif
+
+#endif /* NASM_WSAA_H */