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);