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>
This commit is contained in:
Cyrill Gorcunov 2014-08-29 20:30:57 +04:00
parent 9b76c802ae
commit 500dd5461c
5 changed files with 50 additions and 129 deletions

@ -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) */

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

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

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

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