summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2014-08-29 20:30:57 +0400
committerCyrill Gorcunov <gorcunov@gmail.com>2014-08-29 20:30:57 +0400
commit500dd5461cbce5e645039ac7472a3c7e772af726 (patch)
tree83b821c7c37d78fb3862ad68c7a4672f1a28342f
parent9b76c802ae6f7e85c1e0b1b15696149297ae243d (diff)
downloadnasm-500dd5461cbce5e645039ac7472a3c7e772af726.tar.gz
output: elf -- Move elf_directive into single instance
For all Elf32/32x/64 this routine is the same. So lets merge it into one instance. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r--output/outelf.c46
-rw-r--r--output/outelf.h4
-rw-r--r--output/outelf32.c43
-rw-r--r--output/outelf64.c43
-rw-r--r--output/outelfx32.c43
5 files changed, 50 insertions, 129 deletions
diff --git a/output/outelf.c b/output/outelf.c
index 19fc99fb..a8e23478 100644
--- a/output/outelf.c
+++ b/output/outelf.c
@@ -50,6 +50,9 @@
#if defined(OF_ELF32) || defined(OF_ELF64) || defined(OF_ELFX32)
+uint8_t elf_osabi = 0; /* Default OSABI = 0 (System V or Linux) */
+uint8_t elf_abiver = 0; /* Current ABI version */
+
const struct elf_known_section elf_known_sections[] = {
{ ".text", SHT_PROGBITS, SHF_ALLOC|SHF_EXECINSTR, 16 },
{ ".rodata", SHT_PROGBITS, SHF_ALLOC, 4 },
@@ -125,4 +128,47 @@ void elf_section_attrib(char *name, char *attr, int pass,
}
}
+int elf_directive(enum directives directive, char *value, int pass)
+{
+ int64_t n;
+ bool err;
+ char *p;
+
+ switch (directive) {
+ case D_OSABI:
+ if (pass == 2)
+ return 1; /* ignore in pass 2 */
+
+ n = readnum(value, &err);
+ if (err) {
+ nasm_error(ERR_NONFATAL, "`osabi' directive requires a parameter");
+ return 1;
+ }
+
+ if (n < 0 || n > 255) {
+ nasm_error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
+ return 1;
+ }
+
+ elf_osabi = n;
+ elf_abiver = 0;
+
+ p = strchr(value,',');
+ if (!p)
+ return 1;
+
+ n = readnum(p + 1, &err);
+ if (err || n < 0 || n > 255) {
+ nasm_error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
+ return 1;
+ }
+
+ elf_abiver = n;
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
#endif /* defined(OF_ELF32) || defined(OF_ELF64) || defined(OF_ELFX32) */
diff --git a/output/outelf.h b/output/outelf.h
index fbf23fba..62677215 100644
--- a/output/outelf.h
+++ b/output/outelf.h
@@ -101,6 +101,10 @@ struct stabentry {
#define sec_debug_frame (nsections-2)
#define sec_debug_loc (nsections-1)
+extern uint8_t elf_osabi;
+extern uint8_t elf_abiver;
+
+int elf_directive(enum directives directive, char *value, int pass);
void elf_section_attrib(char *name, char *attr, int pass,
uint32_t *flags_and, uint32_t *flags_or,
uint64_t *align, int *type);
diff --git a/output/outelf32.c b/output/outelf32.c
index 83aedb0d..462e5bcb 100644
--- a/output/outelf32.c
+++ b/output/outelf32.c
@@ -119,9 +119,6 @@ static struct Symbol *fwds;
static char elf_module[FILENAME_MAX];
-static uint8_t elf_osabi = 0; /* Default OSABI = 0 (System V or Linux) */
-static uint8_t elf_abiver = 0; /* Current ABI version */
-
extern struct ofmt of_elf32;
static struct ELF_SECTDATA {
@@ -1360,46 +1357,6 @@ static int32_t elf_segbase(int32_t segment)
return segment;
}
-static int elf_directive(enum directives directive, char *value, int pass)
-{
- bool err;
- int64_t n;
- char *p;
-
- switch (directive) {
- case D_OSABI:
- if (pass == 2)
- return 1; /* ignore in pass 2 */
-
- n = readnum(value, &err);
- if (err) {
- nasm_error(ERR_NONFATAL, "`osabi' directive requires a parameter");
- return 1;
- }
- if (n < 0 || n > 255) {
- nasm_error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
- return 1;
- }
- elf_osabi = n;
- elf_abiver = 0;
-
- if ((p = strchr(value,',')) == NULL)
- return 1;
-
- n = readnum(p+1, &err);
- if (err || n < 0 || n > 255) {
- nasm_error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
- return 1;
- }
-
- elf_abiver = n;
- return 1;
-
- default:
- return 0;
- }
-}
-
static void elf_filename(char *inname, char *outname)
{
strcpy(elf_module, inname);
diff --git a/output/outelf64.c b/output/outelf64.c
index 40d5f1eb..537d3a5b 100644
--- a/output/outelf64.c
+++ b/output/outelf64.c
@@ -120,9 +120,6 @@ static struct Symbol *fwds;
static char elf_module[FILENAME_MAX];
-static uint8_t elf_osabi = 0; /* Default OSABI = 0 (System V or Linux) */
-static uint8_t elf_abiver = 0; /* Current ABI version */
-
extern struct ofmt of_elf64;
static struct ELF_SECTDATA {
@@ -1455,46 +1452,6 @@ static int32_t elf_segbase(int32_t segment)
return segment;
}
-static int elf_directive(enum directives directive, char *value, int pass)
-{
- bool err;
- int64_t n;
- char *p;
-
- switch (directive) {
- case D_OSABI:
- if (pass == 2)
- return 1; /* ignore in pass 2 */
-
- n = readnum(value, &err);
- if (err) {
- nasm_error(ERR_NONFATAL, "`osabi' directive requires a parameter");
- return 1;
- }
- if (n < 0 || n > 255) {
- nasm_error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
- return 1;
- }
- elf_osabi = n;
- elf_abiver = 0;
-
- if ((p = strchr(value,',')) == NULL)
- return 1;
-
- n = readnum(p+1, &err);
- if (err || n < 0 || n > 255) {
- nasm_error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
- return 1;
- }
-
- elf_abiver = n;
- return 1;
-
- default:
- return 0;
- }
-}
-
static void elf_filename(char *inname, char *outname)
{
strcpy(elf_module, inname);
diff --git a/output/outelfx32.c b/output/outelfx32.c
index 1f1ed4d7..ccb022db 100644
--- a/output/outelfx32.c
+++ b/output/outelfx32.c
@@ -119,9 +119,6 @@ static struct Symbol *fwds;
static char elf_module[FILENAME_MAX];
-static uint8_t elf_osabi = 0; /* Default OSABI = 0 (System V or Linux) */
-static uint8_t elf_abiver = 0; /* Current ABI version */
-
extern struct ofmt of_elfx32;
static struct ELF_SECTDATA {
@@ -1413,46 +1410,6 @@ static int32_t elf_segbase(int32_t segment)
return segment;
}
-static int elf_directive(enum directives directive, char *value, int pass)
-{
- bool err;
- int64_t n;
- char *p;
-
- switch (directive) {
- case D_OSABI:
- if (pass == 2)
- return 1; /* ignore in pass 2 */
-
- n = readnum(value, &err);
- if (err) {
- nasm_error(ERR_NONFATAL, "`osabi' directive requires a parameter");
- return 1;
- }
- if (n < 0 || n > 255) {
- nasm_error(ERR_NONFATAL, "valid osabi numbers are 0 to 255");
- return 1;
- }
- elf_osabi = n;
- elf_abiver = 0;
-
- if ((p = strchr(value,',')) == NULL)
- return 1;
-
- n = readnum(p+1, &err);
- if (err || n < 0 || n > 255) {
- nasm_error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
- return 1;
- }
-
- elf_abiver = n;
- return 1;
-
- default:
- return 0;
- }
-}
-
static void elf_filename(char *inname, char *outname)
{
strcpy(elf_module, inname);