summaryrefslogtreecommitdiff
path: root/output
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2010-04-09 13:24:35 +0400
committerCyrill Gorcunov <gorcunov@gmail.com>2010-04-10 00:02:38 +0400
commit572dd0021c250fa371e525260787e382701586fa (patch)
tree2316b9be1ffd83ff16cc7f53918b9a92f3a602f4 /output
parentbb0745f432fcbebd7866f55ea246bae7a484504b (diff)
downloadnasm-572dd0021c250fa371e525260787e382701586fa.tar.gz
Elf: Introduce section_attrib helper
In a sake of removing code duplication. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Diffstat (limited to 'output')
-rw-r--r--output/outelf.c57
-rw-r--r--output/outelf.h4
-rw-r--r--output/outelf32.c51
-rw-r--r--output/outelf64.c49
4 files changed, 65 insertions, 96 deletions
diff --git a/output/outelf.c b/output/outelf.c
index e80d9139..9ac39a60 100644
--- a/output/outelf.c
+++ b/output/outelf.c
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
- * Copyright 1996-2009 The NASM Authors - All Rights Reserved
+ * Copyright 1996-2010 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@@ -64,4 +64,59 @@ const struct elf_known_section elf_known_sections[] = {
{ NULL, SHT_PROGBITS, SHF_ALLOC, 1 } /* default */
};
+/* parse section attributes */
+void section_attrib(char *name, char *attr, int pass,
+ uint32_t *flags_and, uint32_t *flags_or,
+ uint64_t *align, int *type)
+{
+ char *p, *q, *v;
+
+ p = nasm_skip_spaces(attr);
+ if (!p || !*p)
+ return;
+
+ while ((p = nasm_opt_val(p, &q, &v))) {
+ if (!nasm_stricmp(q, "align")) {
+ *align = atoi(v);
+ if (*align == 0) {
+ *align = 1;
+ } else if (!is_power2(*align)) {
+ nasm_error(ERR_NONFATAL,
+ "section alignment %"PRId64" is not a power of two",
+ *align);
+ *align = 1;
+ }
+ } else if (!nasm_stricmp(q, "alloc")) {
+ *flags_and |= SHF_ALLOC;
+ *flags_or |= SHF_ALLOC;
+ } else if (!nasm_stricmp(q, "noalloc")) {
+ *flags_and |= SHF_ALLOC;
+ *flags_or &= ~SHF_ALLOC;
+ } else if (!nasm_stricmp(q, "exec")) {
+ *flags_and |= SHF_EXECINSTR;
+ *flags_or |= SHF_EXECINSTR;
+ } else if (!nasm_stricmp(q, "noexec")) {
+ *flags_and |= SHF_EXECINSTR;
+ *flags_or &= ~SHF_EXECINSTR;
+ } else if (!nasm_stricmp(q, "write")) {
+ *flags_and |= SHF_WRITE;
+ *flags_or |= SHF_WRITE;
+ } else if (!nasm_stricmp(q, "tls")) {
+ *flags_and |= SHF_TLS;
+ *flags_or |= SHF_TLS;
+ } else if (!nasm_stricmp(q, "nowrite")) {
+ *flags_and |= SHF_WRITE;
+ *flags_or &= ~SHF_WRITE;
+ } else if (!nasm_stricmp(q, "progbits")) {
+ *type = SHT_PROGBITS;
+ } else if (!nasm_stricmp(q, "nobits")) {
+ *type = SHT_NOBITS;
+ } else if (pass == 1) {
+ nasm_error(ERR_WARNING,
+ "Unknown section attribute '%s' ignored on"
+ " declaration of section `%s'", q, name);
+ }
+ }
+}
+
#endif /* defined(OF_ELF32) || defined(OF_ELF64) */
diff --git a/output/outelf.h b/output/outelf.h
index 1efa2d06..fad01a25 100644
--- a/output/outelf.h
+++ b/output/outelf.h
@@ -91,4 +91,8 @@ extern const struct elf_known_section elf_known_sections[];
#define sec_debug_frame (nsections-2)
#define sec_debug_loc (nsections-1)
+void section_attrib(char *name, char *attr, int pass,
+ uint32_t *flags_and, uint32_t *flags_or,
+ uint64_t *align, int *type);
+
#endif /* OUTPUT_OUTELF_H */
diff --git a/output/outelf32.c b/output/outelf32.c
index 0a2bbba6..8f8e7075 100644
--- a/output/outelf32.c
+++ b/output/outelf32.c
@@ -348,7 +348,7 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
{
char *p;
uint32_t flags, flags_and, flags_or;
- uint32_t align;
+ uint64_t align;
int type, i;
/*
@@ -364,53 +364,8 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
*p++ = '\0';
flags_and = flags_or = type = align = 0;
- p = nasm_skip_spaces(p);
- while (*p) {
- char *q = p;
- p = nasm_skip_word(p);
- if (*p)
- *p++ = '\0';
- p = nasm_skip_spaces(p);
-
- if (!nasm_strnicmp(q, "align=", 6)) {
- align = atoi(q + 6);
- if (align == 0)
- align = 1;
- if ((align - 1) & align) { /* means it's not a power of two */
- nasm_error(ERR_NONFATAL, "section alignment %d is not"
- " a power of two", align);
- align = 1;
- }
- } else if (!nasm_stricmp(q, "alloc")) {
- flags_and |= SHF_ALLOC;
- flags_or |= SHF_ALLOC;
- } else if (!nasm_stricmp(q, "noalloc")) {
- flags_and |= SHF_ALLOC;
- flags_or &= ~SHF_ALLOC;
- } else if (!nasm_stricmp(q, "exec")) {
- flags_and |= SHF_EXECINSTR;
- flags_or |= SHF_EXECINSTR;
- } else if (!nasm_stricmp(q, "noexec")) {
- flags_and |= SHF_EXECINSTR;
- flags_or &= ~SHF_EXECINSTR;
- } else if (!nasm_stricmp(q, "write")) {
- flags_and |= SHF_WRITE;
- flags_or |= SHF_WRITE;
- } else if (!nasm_stricmp(q, "tls")) {
- flags_and |= SHF_TLS;
- flags_or |= SHF_TLS;
- } else if (!nasm_stricmp(q, "nowrite")) {
- flags_and |= SHF_WRITE;
- flags_or &= ~SHF_WRITE;
- } else if (!nasm_stricmp(q, "progbits")) {
- type = SHT_PROGBITS;
- } else if (!nasm_stricmp(q, "nobits")) {
- type = SHT_NOBITS;
- } else if (pass == 1) {
- nasm_error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
- " declaration of section `%s'", q, name);
- }
- }
+ section_attrib(name, p, pass, &flags_and,
+ &flags_or, &align, &type);
if (!strcmp(name, ".shstrtab") ||
!strcmp(name, ".symtab") ||
diff --git a/output/outelf64.c b/output/outelf64.c
index bf5f80e8..810845a1 100644
--- a/output/outelf64.c
+++ b/output/outelf64.c
@@ -362,53 +362,8 @@ static int32_t elf_section_names(char *name, int pass, int *bits)
*p++ = '\0';
flags_and = flags_or = type = align = 0;
- p = nasm_skip_spaces(p);
- while (*p) {
- char *q = p;
- p = nasm_skip_word(p);
- if (*p)
- *p++ = '\0';
- p = nasm_skip_spaces(p);
-
- if (!nasm_strnicmp(q, "align=", 6)) {
- align = atoi(q + 6);
- if (align == 0)
- align = 1;
- if ((align - 1) & align) { /* means it's not a power of two */
- nasm_error(ERR_NONFATAL, "section alignment %"PRId64" is not"
- " a power of two", align);
- align = 1;
- }
- } else if (!nasm_stricmp(q, "alloc")) {
- flags_and |= SHF_ALLOC;
- flags_or |= SHF_ALLOC;
- } else if (!nasm_stricmp(q, "noalloc")) {
- flags_and |= SHF_ALLOC;
- flags_or &= ~SHF_ALLOC;
- } else if (!nasm_stricmp(q, "exec")) {
- flags_and |= SHF_EXECINSTR;
- flags_or |= SHF_EXECINSTR;
- } else if (!nasm_stricmp(q, "noexec")) {
- flags_and |= SHF_EXECINSTR;
- flags_or &= ~SHF_EXECINSTR;
- } else if (!nasm_stricmp(q, "write")) {
- flags_and |= SHF_WRITE;
- flags_or |= SHF_WRITE;
- } else if (!nasm_stricmp(q, "tls")) {
- flags_and |= SHF_TLS;
- flags_or |= SHF_TLS;
- } else if (!nasm_stricmp(q, "nowrite")) {
- flags_and |= SHF_WRITE;
- flags_or &= ~SHF_WRITE;
- } else if (!nasm_stricmp(q, "progbits")) {
- type = SHT_PROGBITS;
- } else if (!nasm_stricmp(q, "nobits")) {
- type = SHT_NOBITS;
- } else if (pass == 1) {
- nasm_error(ERR_WARNING, "Unknown section attribute '%s' ignored on"
- " declaration of section `%s'", q, name);
- }
- }
+ section_attrib(name, p, pass, &flags_and,
+ &flags_or, &align, &type);
if (!strcmp(name, ".shstrtab") ||
!strcmp(name, ".symtab") ||