mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-01-30 16:41:05 +08:00
Support setting OSABI value in ELF header.
This commit is contained in:
parent
c68ec01277
commit
dbb1828ad5
@ -4392,8 +4392,15 @@ Format} Object Files
|
||||
|
||||
The \c{elf32} and \c{elf64} output formats generate \c{ELF32 and ELF64} (Executable and Linkable Format) object files, as used by Linux as well as \i{Unix System V},
|
||||
including \i{Solaris x86}, \i{UnixWare} and \i{SCO Unix}. \c{elf}
|
||||
provides a default output file-name extension of \c{.o}. \c{elf} is a synonym for \c{elf32}.
|
||||
provides a default output file-name extension of \c{.o}.
|
||||
\c{elf} is a synonym for \c{elf32}.
|
||||
|
||||
\S{abisect} ELF specific directive \i\c{osabi}
|
||||
|
||||
The ELF header specifies the application binary interface for the target operating system (OSABI).
|
||||
This field can be set by using the \c{osabi} directive with the numeric value (0-255) of the target
|
||||
system. If this directive is not used, the default value will be "UNIX System V ABI" (0) which will work on
|
||||
most systems which support ELF.
|
||||
|
||||
\S{elfsect} \c{elf} Extensions to the \c{SECTION}
|
||||
Directive\I{SECTION, elf extensions to}
|
||||
|
@ -110,6 +110,9 @@ 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;
|
||||
extern struct ofmt of_elf;
|
||||
|
||||
@ -998,7 +1001,10 @@ static void elf_write(void)
|
||||
/*
|
||||
* Output the ELF header.
|
||||
*/
|
||||
fwrite("\177ELF\1\1\1\0\0\0\0\0\0\0\0\0", 16, 1, elffp);
|
||||
fwrite("\177ELF\1\1\1", 7, 1, elffp);
|
||||
fputc(elf_osabi, elffp);
|
||||
fputc(elf_abiver, elffp);
|
||||
fwrite("\0\0\0\0\0\0\0", 7, 1, elffp);
|
||||
fwriteint16_t(1, elffp); /* ET_REL relocatable file */
|
||||
fwriteint16_t(3, elffp); /* EM_386 processor ID */
|
||||
fwriteint32_t(1L, elffp); /* EV_CURRENT file format version */
|
||||
@ -1265,9 +1271,39 @@ static int32_t elf_segbase(int32_t segment)
|
||||
|
||||
static int elf_directive(char *directive, char *value, int pass)
|
||||
{
|
||||
(void)directive;
|
||||
(void)value;
|
||||
(void)pass;
|
||||
bool err;
|
||||
int64_t n;
|
||||
char *p;
|
||||
|
||||
if (!strcmp(directive, "osabi")) {
|
||||
if (pass == 2)
|
||||
return 1; /* ignore in pass 2 */
|
||||
|
||||
n = readnum(value, &err);
|
||||
if (err) {
|
||||
error(ERR_NONFATAL, "`osabi' directive requires a parameter");
|
||||
return 1;
|
||||
}
|
||||
if (n < 0 || n > 255) {
|
||||
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) {
|
||||
error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
elf_abiver = n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1282,6 +1318,9 @@ static const char *elf_stdmac[] = {
|
||||
"%macro __NASM_CDecl__ 1",
|
||||
"%define $_%1 $%1",
|
||||
"%endmacro",
|
||||
"%macro osabi 1+.nolist",
|
||||
"[osabi %1]",
|
||||
"%endmacro",
|
||||
NULL
|
||||
};
|
||||
static int elf_set_info(enum geninfo type, char **val)
|
||||
|
@ -134,6 +134,9 @@ 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;
|
||||
|
||||
#define SHN_UNDEF 0
|
||||
@ -1033,7 +1036,10 @@ static void elf_write(void)
|
||||
/*
|
||||
* Output the ELF header.
|
||||
*/
|
||||
fwrite("\177ELF\2\1\1\0\0\0\0\0\0\0\0\0", 16, 1, elffp);
|
||||
fwrite("\177ELF\2\1\1", 7, 1, elffp);
|
||||
fputc(elf_osabi, elffp);
|
||||
fputc(elf_abiver, elffp);
|
||||
fwrite("\0\0\0\0\0\0\0", 7, 1, elffp);
|
||||
fwriteint16_t(ET_REL, elffp); /* relocatable file */
|
||||
fwriteint16_t(EM_X86_64, elffp); /* processor ID */
|
||||
fwriteint32_t(1L, elffp); /* EV_CURRENT file format version */
|
||||
@ -1298,9 +1304,39 @@ static int32_t elf_segbase(int32_t segment)
|
||||
|
||||
static int elf_directive(char *directive, char *value, int pass)
|
||||
{
|
||||
(void)directive;
|
||||
(void)value;
|
||||
(void)pass;
|
||||
bool err;
|
||||
int64_t n;
|
||||
char *p;
|
||||
|
||||
if (!strcmp(directive, "osabi")) {
|
||||
if (pass == 2)
|
||||
return 1; /* ignore in pass 2 */
|
||||
|
||||
n = readnum(value, &err);
|
||||
if (err) {
|
||||
error(ERR_NONFATAL, "`osabi' directive requires a parameter");
|
||||
return 1;
|
||||
}
|
||||
if (n < 0 || n > 255) {
|
||||
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) {
|
||||
error(ERR_NONFATAL, "invalid ABI version number (valid: 0 to 255)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
elf_abiver = n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1315,6 +1351,9 @@ static const char *elf_stdmac[] = {
|
||||
"%macro __NASM_CDecl__ 1",
|
||||
"%define $_%1 $%1",
|
||||
"%endmacro",
|
||||
"%macro osabi 1+.nolist",
|
||||
"[osabi %1]",
|
||||
"%endmacro",
|
||||
NULL
|
||||
};
|
||||
static int elf_set_info(enum geninfo type, char **val)
|
||||
|
Loading…
Reference in New Issue
Block a user