summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-10-27 22:19:59 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-10-27 22:19:59 -0700
commit03c4f90afa42cc8a7ed842ff0fc9d3c18a06dd2d (patch)
tree28527b6cd2b5d7978018b2eedeb2547e7ec7019d
parent67c637236a18e7ae3f3086487a88274a89608d10 (diff)
downloadnasm-03c4f90afa42cc8a7ed842ff0fc9d3c18a06dd2d.tar.gz
nasm-03c4f90afa42cc8a7ed842ff0fc9d3c18a06dd2d.tar.bz2
nasm-03c4f90afa42cc8a7ed842ff0fc9d3c18a06dd2d.zip
output: add common file outlib.c for common functions; realsize()
Add a common file, outlib.c, for output formats. Add the function realsize() instead of open-coded variants in almost every backend. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--Makefile.in6
-rw-r--r--Mkfiles/msvc.mak6
-rw-r--r--Mkfiles/netware.mak6
-rw-r--r--Mkfiles/openwcom.mak6
-rw-r--r--Mkfiles/owlinux.mak6
-rw-r--r--outlib.c23
-rw-r--r--outlib.h9
-rw-r--r--output/outaout.c7
-rw-r--r--output/outas86.c7
-rw-r--r--output/outbin.c16
-rw-r--r--output/outcoff.c7
-rw-r--r--output/outelf32.c7
-rw-r--r--output/outelf64.c16
-rw-r--r--output/outmacho.c18
-rw-r--r--output/outobj.c3
15 files changed, 67 insertions, 76 deletions
diff --git a/Makefile.in b/Makefile.in
index 3126bd1..6dd61e3 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -62,7 +62,7 @@ X = @EXEEXT@
NASM = nasm.$(O) nasmlib.$(O) raa.$(O) saa.$(O) \
float.$(O) insnsa.$(O) insnsb.$(O) \
assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
- outform.$(O) output/outbin.$(O) \
+ outform.$(O) outlib.$(O) output/outbin.$(O) \
output/outaout.$(O) output/outcoff.$(O) \
output/outelf32.$(O) output/outelf64.$(O) \
output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
@@ -279,6 +279,8 @@ ndisasm.$(O): ndisasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h version.h
outform.$(O): outform.c compiler.h config.h insnsi.h nasm.h nasmlib.h \
outform.h pptok.h preproc.h regs.h version.h
+outlib.$(O): outlib.c compiler.h config.h insnsi.h nasm.h nasmlib.h outlib.h \
+ pptok.h preproc.h regs.h version.h
output/outaout.$(O): output/outaout.c compiler.h config.h insnsi.h nasm.h \
nasmlib.h outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \
version.h
@@ -292,7 +294,7 @@ 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 pptok.h preproc.h regs.h version.h
output/outelf32.$(O): output/outelf32.c compiler.h config.h insnsi.h nasm.h \
- nasmlib.h outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \
+ nasmlib.h outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \
version.h
output/outelf64.$(O): output/outelf64.c compiler.h config.h insnsi.h nasm.h \
nasmlib.h outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h \
diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak
index 594bce6..94ac97a 100644
--- a/Mkfiles/msvc.mak
+++ b/Mkfiles/msvc.mak
@@ -37,7 +37,7 @@ X = .exe
NASM = nasm.$(O) nasmlib.$(O) raa.$(O) saa.$(O) \
float.$(O) insnsa.$(O) insnsb.$(O) \
assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
- outform.$(O) output/outbin.$(O) \
+ outform.$(O) outlib.$(O) output/outbin.$(O) \
output/outaout.$(O) output/outcoff.$(O) \
output/outelf32.$(O) output/outelf64.$(O) \
output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
@@ -218,6 +218,8 @@ ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h version.h
outform.$(O): outform.c compiler.h insnsi.h nasm.h nasmlib.h outform.h \
pptok.h preproc.h regs.h version.h
+outlib.$(O): outlib.c compiler.h insnsi.h nasm.h nasmlib.h outlib.h pptok.h \
+ preproc.h regs.h version.h
output/outaout.$(O): output/outaout.c compiler.h insnsi.h nasm.h nasmlib.h \
outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
output/outas86.$(O): output/outas86.c compiler.h insnsi.h nasm.h nasmlib.h \
@@ -230,7 +232,7 @@ 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 pptok.h preproc.h regs.h version.h
output/outelf32.$(O): output/outelf32.c compiler.h insnsi.h nasm.h nasmlib.h \
- outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
+ outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
output/outelf64.$(O): output/outelf64.c compiler.h insnsi.h nasm.h nasmlib.h \
outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
output/outieee.$(O): output/outieee.c compiler.h insnsi.h nasm.h nasmlib.h \
diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak
index 873043b..f98bd02 100644
--- a/Mkfiles/netware.mak
+++ b/Mkfiles/netware.mak
@@ -33,7 +33,7 @@ O = o
NASM = nasm.o nasmlib.o raa.o saa.o \
float.o insnsa.o insnsb.o \
assemble.o labels.o hashtbl.o crc64.o parser.o \
- outform.o outbin.o \
+ outform.o outlib.o outbin.o \
outaout.o outcoff.o \
outelf32.o outelf64.o \
outobj.o outas86.o outrdf2.o \
@@ -159,6 +159,8 @@ ndisasm.o: ndisasm.c compiler.h config.h disasm.h insns.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h version.h
outform.o: outform.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
pptok.h preproc.h regs.h version.h
+outlib.o: outlib.c compiler.h config.h insnsi.h nasm.h nasmlib.h outlib.h \
+ pptok.h preproc.h regs.h version.h
outaout.o: outaout.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
outas86.o: outas86.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
@@ -170,7 +172,7 @@ outcoff.o: outcoff.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
outdbg.o: outdbg.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
pptok.h preproc.h regs.h version.h
outelf32.o: outelf32.c compiler.h config.h insnsi.h nasm.h nasmlib.h \
- outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
+ outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
outelf64.o: outelf64.c compiler.h config.h insnsi.h nasm.h nasmlib.h \
outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
outieee.o: outieee.c compiler.h config.h insnsi.h nasm.h nasmlib.h outform.h \
diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak
index b10ceb5..7361abb 100644
--- a/Mkfiles/openwcom.mak
+++ b/Mkfiles/openwcom.mak
@@ -49,7 +49,7 @@ X = .exe
NASM = nasm.$(O) nasmlib.$(O) raa.$(O) saa.$(O) &
float.$(O) insnsa.$(O) insnsb.$(O) &
assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) &
- outform.$(O) output\outbin.$(O) &
+ outform.$(O) outlib.$(O) output\outbin.$(O) &
output\outaout.$(O) output\outcoff.$(O) &
output\outelf32.$(O) output\outelf64.$(O) &
output\outobj.$(O) output\outas86.$(O) output\outrdf2.$(O) &
@@ -247,6 +247,8 @@ ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h &
nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h version.h
outform.$(O): outform.c compiler.h insnsi.h nasm.h nasmlib.h outform.h &
pptok.h preproc.h regs.h version.h
+outlib.$(O): outlib.c compiler.h insnsi.h nasm.h nasmlib.h outlib.h pptok.h &
+ preproc.h regs.h version.h
output\outaout.$(O): output\outaout.c compiler.h insnsi.h nasm.h nasmlib.h &
outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
output\outas86.$(O): output\outas86.c compiler.h insnsi.h nasm.h nasmlib.h &
@@ -259,7 +261,7 @@ 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 pptok.h preproc.h regs.h version.h
output\outelf32.$(O): output\outelf32.c compiler.h insnsi.h nasm.h nasmlib.h &
- outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
+ outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
output\outelf64.$(O): output\outelf64.c compiler.h insnsi.h nasm.h nasmlib.h &
outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
output\outieee.$(O): output\outieee.c compiler.h insnsi.h nasm.h nasmlib.h &
diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak
index 1c7d44d..4e6c8bc 100644
--- a/Mkfiles/owlinux.mak
+++ b/Mkfiles/owlinux.mak
@@ -60,7 +60,7 @@ X = .exe
NASM = nasm.$(O) nasmlib.$(O) raa.$(O) saa.$(O) \
float.$(O) insnsa.$(O) insnsb.$(O) \
assemble.$(O) labels.$(O) hashtbl.$(O) crc64.$(O) parser.$(O) \
- outform.$(O) output/outbin.$(O) \
+ outform.$(O) outlib.$(O) output/outbin.$(O) \
output/outaout.$(O) output/outcoff.$(O) \
output/outelf32.$(O) output/outelf64.$(O) \
output/outobj.$(O) output/outas86.$(O) output/outrdf2.$(O) \
@@ -257,6 +257,8 @@ ndisasm.$(O): ndisasm.c compiler.h disasm.h insns.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h sync.h tokens.h version.h
outform.$(O): outform.c compiler.h insnsi.h nasm.h nasmlib.h outform.h \
pptok.h preproc.h regs.h version.h
+outlib.$(O): outlib.c compiler.h insnsi.h nasm.h nasmlib.h outlib.h pptok.h \
+ preproc.h regs.h version.h
output/outaout.$(O): output/outaout.c compiler.h insnsi.h nasm.h nasmlib.h \
outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
output/outas86.$(O): output/outas86.c compiler.h insnsi.h nasm.h nasmlib.h \
@@ -269,7 +271,7 @@ 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 pptok.h preproc.h regs.h version.h
output/outelf32.$(O): output/outelf32.c compiler.h insnsi.h nasm.h nasmlib.h \
- outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
+ outform.h outlib.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
output/outelf64.$(O): output/outelf64.c compiler.h insnsi.h nasm.h nasmlib.h \
outform.h pptok.h preproc.h raa.h regs.h saa.h stdscan.h version.h
output/outieee.$(O): output/outieee.c compiler.h insnsi.h nasm.h nasmlib.h \
diff --git a/outlib.c b/outlib.c
new file mode 100644
index 0000000..cf68721
--- /dev/null
+++ b/outlib.c
@@ -0,0 +1,23 @@
+/*
+ * libout.c
+ *
+ * Common routines for the output backends.
+ */
+
+#include "compiler.h"
+#include "nasm.h"
+#include "outlib.h"
+
+uint64_t realsize(enum out_type type, uint64_t size)
+{
+ switch (type) {
+ case OUT_REL2ADR:
+ return 2;
+ case OUT_REL4ADR:
+ return 4;
+ case OUT_REL8ADR:
+ return 8;
+ default:
+ return size;
+ }
+}
diff --git a/outlib.h b/outlib.h
new file mode 100644
index 0000000..03524b9
--- /dev/null
+++ b/outlib.h
@@ -0,0 +1,9 @@
+#ifndef NASM_OUTLIB_H
+#define NSAM_OUTLIB_H
+
+#include "nasm.h"
+
+uint64_t realsize(enum out_type type, uint64_t size);
+
+#endif /* LIBOUT_H */
+
diff --git a/output/outaout.c b/output/outaout.c
index 48a2cff..467b20e 100644
--- a/output/outaout.c
+++ b/output/outaout.c
@@ -21,6 +21,7 @@
#include "raa.h"
#include "stdscan.h"
#include "outform.h"
+#include "outlib.h"
#if defined OF_AOUT || defined OF_AOUTB
@@ -603,11 +604,7 @@ static void aout_out(int32_t segto, const void *data,
if (!s && type != OUT_RESERVE) {
error(ERR_WARNING, "attempt to initialize memory in the"
" BSS section: ignored");
- if (type == OUT_REL2ADR)
- size = 2;
- else if (type == OUT_REL4ADR)
- size = 4;
- sbss.len += size;
+ sbss.len += realsize(type, size);
return;
}
diff --git a/output/outas86.c b/output/outas86.c
index b59fe6b..307f10b 100644
--- a/output/outas86.c
+++ b/output/outas86.c
@@ -20,6 +20,7 @@
#include "saa.h"
#include "raa.h"
#include "outform.h"
+#include "outlib.h"
#ifdef OF_AS86
@@ -294,11 +295,7 @@ static void as86_out(int32_t segto, const void *data,
if (!s && type != OUT_RESERVE) {
error(ERR_WARNING, "attempt to initialize memory in the"
" BSS section: ignored");
- if (type == OUT_REL2ADR)
- size = 2;
- else if (type == OUT_REL4ADR)
- size = 4;
- bsslen += size;
+ bsslen += realsize(type, size);
return;
}
diff --git a/output/outbin.c b/output/outbin.c
index cfa0aa6..f6be964 100644
--- a/output/outbin.c
+++ b/output/outbin.c
@@ -59,6 +59,7 @@
#include "labels.h"
#include "eval.h"
#include "outform.h"
+#include "outlib.h"
#ifdef OF_BIN
@@ -799,20 +800,7 @@ static void bin_out(int32_t segto, const void *data,
} else if (type == OUT_REL2ADR || type == OUT_REL4ADR ||
type == OUT_REL8ADR) {
int64_t addr = *(int64_t *)data - size;
- switch (type) {
- case OUT_REL2ADR:
- size = 2;
- break;
- case OUT_REL4ADR:
- size = 4;
- break;
- case OUT_REL8ADR:
- size = 8;
- break;
- default:
- size = 0; /* Shut up warning */
- break;
- }
+ size = realsize(type, size);
if (segment != NO_SEG && !find_section_by_index(segment)) {
if (segment % 2)
error(ERR_NONFATAL, "binary output format does not support"
diff --git a/output/outcoff.c b/output/outcoff.c
index 31e5cbe..16d2719 100644
--- a/output/outcoff.c
+++ b/output/outcoff.c
@@ -21,6 +21,7 @@
#include "saa.h"
#include "raa.h"
#include "outform.h"
+#include "outlib.h"
#if defined(OF_COFF) || defined(OF_WIN32) || defined(OF_WIN64)
@@ -527,11 +528,7 @@ static void coff_out(int32_t segto, const void *data,
if (!s->data && type != OUT_RESERVE) {
error(ERR_WARNING, "attempt to initialize memory in"
" BSS section `%s': ignored", s->name);
- if (type == OUT_REL2ADR)
- size = 2;
- else if (type == OUT_REL4ADR)
- size = 4;
- s->len += size;
+ s->len += realsize(type, size);
return;
}
diff --git a/output/outelf32.c b/output/outelf32.c
index bff264a..9f424a4 100644
--- a/output/outelf32.c
+++ b/output/outelf32.c
@@ -21,6 +21,7 @@
#include "raa.h"
#include "stdscan.h"
#include "outform.h"
+#include "outlib.h"
#ifdef OF_ELF32
@@ -889,11 +890,7 @@ static void elf_out(int32_t segto, const void *data,
if (s->type == SHT_NOBITS && type != OUT_RESERVE) {
error(ERR_WARNING, "attempt to initialize memory in"
" BSS section `%s': ignored", s->name);
- if (type == OUT_REL2ADR)
- size = 2;
- else if (type == OUT_REL4ADR)
- size = 4;
- s->len += size;
+ s->len += realsize(type, size);
return;
}
diff --git a/output/outelf64.c b/output/outelf64.c
index d2bf3c4..b7caa16 100644
--- a/output/outelf64.c
+++ b/output/outelf64.c
@@ -20,6 +20,7 @@
#include "raa.h"
#include "stdscan.h"
#include "outform.h"
+#include "outlib.h"
/* Definitions in lieu of elf.h */
#define SHT_NULL 0 /* Inactive section header */
@@ -964,20 +965,7 @@ static void elf_out(int32_t segto, const void *data,
if (s->type == SHT_NOBITS && type != OUT_RESERVE) {
error(ERR_WARNING, "attempt to initialize memory in"
" BSS section `%s': ignored", s->name);
- switch (type) {
- case OUT_REL2ADR:
- size = 2;
- break;
- case OUT_REL4ADR:
- size = 4;
- break;
- case OUT_REL8ADR:
- size = 8;
- break;
- default:
- break; /* size is already set */
- }
- s->len += size;
+ s->len += realsize(type, size);
return;
}
diff --git a/output/outmacho.c b/output/outmacho.c
index 5e9ad8e..06ae8ee 100644
--- a/output/outmacho.c
+++ b/output/outmacho.c
@@ -23,7 +23,7 @@
#include "saa.h"
#include "raa.h"
#include "outform.h"
-#include "compiler.h"
+#include "outlib.h"
#if defined(OF_MACHO)
@@ -427,21 +427,7 @@ static void macho_output(int32_t secto, const void *data,
if (s == sbss && type != OUT_RESERVE) {
error(ERR_WARNING, "attempt to initialize memory in the"
" BSS section: ignored");
-
- switch (type) {
- case OUT_REL2ADR:
- size = 2;
- break;
-
- case OUT_REL4ADR:
- size = 4;
- break;
-
- default:
- break;
- }
-
- s->size += size;
+ s->size += realsize(type, size);
return;
}
diff --git a/output/outobj.c b/output/outobj.c
index e248ac3..4e18e9d 100644
--- a/output/outobj.c
+++ b/output/outobj.c
@@ -1068,8 +1068,7 @@ static void obj_out(int32_t segto, const void *data,
if (type == OUT_REL2ADR) {
ldata += (size - 2);
size = 2;
- }
- if (type == OUT_REL4ADR) {
+ } else if (type == OUT_REL4ADR) {
ldata += (size - 4);
size = 4;
}