]> granicus.if.org Git - yasm/commitdiff
Add support for NASM-compatible ELF extensions to the GLOBAL and COMMON
authorPeter Johnson <peter@tortall.net>
Mon, 17 May 2004 04:20:52 +0000 (04:20 -0000)
committerPeter Johnson <peter@tortall.net>
Mon, 17 May 2004 04:20:52 +0000 (04:20 -0000)
directives.

svn path=/trunk/yasm/; revision=1118

modules/objfmts/elf/elf-objfmt.c
modules/objfmts/elf/tests/Makefile.inc
modules/objfmts/elf/tests/elfglobext.asm [new file with mode: 0644]
modules/objfmts/elf/tests/elfglobext.errwarn [new file with mode: 0644]
modules/objfmts/elf/tests/elfglobext.hex [new file with mode: 0644]

index 405f977f4b01945a2310e399e2addfc91bb6c7b4..e83a6039f9ddb519e5d61ec30f2c9da7417e0836 100644 (file)
@@ -83,15 +83,16 @@ yasm_objfmt_module yasm_elf_LTX_objfmt;
 
 static elf_symtab_entry *
 elf_objfmt_symtab_append(yasm_objfmt_elf *objfmt_elf, yasm_symrec *sym,
-                        elf_symbol_binding bind, elf_section_index sectidx,
-                        yasm_expr *size)
+                        elf_section_index sectidx, elf_symbol_binding bind,
+                        elf_symbol_type type, yasm_expr *size,
+                        elf_address value)
 {
     elf_strtab_entry *name = elf_strtab_append_str(objfmt_elf->strtab,
                                                   yasm_symrec_get_name(sym));
     elf_symtab_entry *entry = elf_symtab_entry_create(name, sym);
     elf_symtab_append_entry(objfmt_elf->elf_symtab, entry);
 
-    elf_symtab_set_nonzero(entry, NULL, sectidx, bind, STT_NOTYPE, size, 00);
+    elf_symtab_set_nonzero(entry, NULL, sectidx, bind, type, size, value);
     yasm_symrec_add_data(sym, &elf_symrec_data, entry);
 
     return entry;
@@ -782,36 +783,87 @@ elf_objfmt_extern_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/
     yasm_symrec *sym;
 
     sym = yasm_symtab_declare(objfmt_elf->symtab, name, YASM_SYM_EXTERN, line);
-    elf_objfmt_symtab_append(objfmt_elf, sym, STB_GLOBAL, SHN_UNDEF, NULL);
+    elf_objfmt_symtab_append(objfmt_elf, sym, SHN_UNDEF, STB_GLOBAL,
+                            STT_NOTYPE, NULL, 0);
 
     return sym;
 }
 
 static yasm_symrec *
-elf_objfmt_global_declare(yasm_objfmt *objfmt, const char *name, /*@unused@*/
+elf_objfmt_global_declare(yasm_objfmt *objfmt, const char *name,
                          /*@null@*/ yasm_valparamhead *objext_valparams,
                          unsigned long line)
 {
     yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt;
     yasm_symrec *sym;
+    elf_symbol_type type = STT_NOTYPE;
+    yasm_expr *size = NULL;
 
     sym = yasm_symtab_declare(objfmt_elf->symtab, name, YASM_SYM_GLOBAL, line);
-    elf_objfmt_symtab_append(objfmt_elf, sym, STB_GLOBAL, SHN_UNDEF, NULL);
+
+    if (objext_valparams) {
+       yasm_valparam *vp = yasm_vps_first(objext_valparams);
+       if (vp && vp->val) {
+           if (yasm__strcasecmp(vp->val, "function") == 0)
+               type = STT_FUNC;
+           else if (yasm__strcasecmp(vp->val, "data") == 0 ||
+                    yasm__strcasecmp(vp->val, "object") == 0)
+               type = STT_OBJECT;
+           else
+               yasm__error(line, N_("unrecognized symbol type `%s'"),
+                           vp->val);
+           vp = yasm_vps_next(vp);
+       }
+       if (vp && !vp->val && vp->param) {
+           size = vp->param;
+           vp->param = NULL;   /* to avoid deleting the expr */
+       }
+    }
+
+    elf_objfmt_symtab_append(objfmt_elf, sym, SHN_UNDEF, STB_GLOBAL,
+                            type, size, 0);
 
     return sym;
 }
 
 static yasm_symrec *
 elf_objfmt_common_declare(yasm_objfmt *objfmt, const char *name,
-                         /*@only@*/ yasm_expr *size, /*@unused@*/ /*@null@*/
+                         /*@only@*/ yasm_expr *size, /*@null@*/
                          yasm_valparamhead *objext_valparams,
                          unsigned long line)
 {
     yasm_objfmt_elf *objfmt_elf = (yasm_objfmt_elf *)objfmt;
     yasm_symrec *sym;
+    unsigned long addralign = 0;
 
     sym = yasm_symtab_declare(objfmt_elf->symtab, name, YASM_SYM_COMMON, line);
-    elf_objfmt_symtab_append(objfmt_elf, sym, STB_GLOBAL, SHN_COMMON, size);
+
+    if (objext_valparams) {
+       yasm_valparam *vp = yasm_vps_first(objext_valparams);
+       if (vp && !vp->val && vp->param) {
+            /*@dependent@*/ /*@null@*/ const yasm_intnum *align_expr;
+
+            align_expr = yasm_expr_get_intnum(&vp->param, NULL);
+            if (!align_expr) {
+                yasm__error(line,
+                            N_("alignment constraint is not a power of two"));
+                return sym;
+            }
+            addralign = yasm_intnum_get_uint(align_expr);
+
+            /* Alignments must be a power of two. */
+            if ((addralign & (addralign - 1)) != 0) {
+                yasm__error(line,
+                            N_("alignment constraint is not a power of two"));
+                return sym;
+            }
+       } else if (vp && vp->val)
+           yasm__warning(YASM_WARN_GENERAL, line,
+                         N_("Unrecognized qualifier `%s'"), vp->val);
+    }
+
+    elf_objfmt_symtab_append(objfmt_elf, sym, SHN_COMMON, STB_GLOBAL,
+                            STT_NOTYPE, size, addralign);
 
     return sym;
 }
index e39e0bc3a2f60a0aa68b765b86c87254f3c819d5..3dd0ec9517fb863b6537909c6e1fe4eacdc5a054 100644 (file)
@@ -22,6 +22,9 @@ EXTRA_DIST += modules/objfmts/elf/tests/elfreloc.hex
 EXTRA_DIST += modules/objfmts/elf/tests/elfglobal.asm
 EXTRA_DIST += modules/objfmts/elf/tests/elfglobal.errwarn
 EXTRA_DIST += modules/objfmts/elf/tests/elfglobal.hex
+EXTRA_DIST += modules/objfmts/elf/tests/elfglobext.asm
+EXTRA_DIST += modules/objfmts/elf/tests/elfglobext.errwarn
+EXTRA_DIST += modules/objfmts/elf/tests/elfglobext.hex
 EXTRA_DIST += modules/objfmts/elf/tests/elfreloc-err.asm
 EXTRA_DIST += modules/objfmts/elf/tests/elfreloc-err.errwarn
 
diff --git a/modules/objfmts/elf/tests/elfglobext.asm b/modules/objfmts/elf/tests/elfglobext.asm
new file mode 100644 (file)
index 0000000..7315b49
--- /dev/null
@@ -0,0 +1,16 @@
+[bits 32]
+
+[global hashlookup:function]
+[global hashtable2:data]
+[global hashtable:data (hashtable.end-hashtable)]
+[common dwordarray 128:4]
+
+[section .text]
+hashlookup
+
+[section .data]
+hashtable2
+       db 5
+hashtable
+       db 1,2,3
+.end
diff --git a/modules/objfmts/elf/tests/elfglobext.errwarn b/modules/objfmts/elf/tests/elfglobext.errwarn
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/modules/objfmts/elf/tests/elfglobext.hex b/modules/objfmts/elf/tests/elfglobext.hex
new file mode 100644 (file)
index 0000000..5b61a49
--- /dev/null
@@ -0,0 +1,528 @@
+7f 
+45 
+4c 
+46 
+01 
+01 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+01 
+00 
+03 
+00 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+20 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+34 
+00 
+00 
+00 
+00 
+00 
+28 
+00 
+06 
+00 
+01 
+00 
+05 
+01 
+02 
+03 
+00 
+2e 
+74 
+65 
+78 
+74 
+00 
+2e 
+64 
+61 
+74 
+61 
+00 
+2e 
+73 
+74 
+72 
+74 
+61 
+62 
+00 
+2e 
+73 
+79 
+6d 
+74 
+61 
+62 
+00 
+2e 
+73 
+68 
+73 
+74 
+72 
+74 
+61 
+62 
+00 
+00 
+00 
+2d 
+00 
+68 
+61 
+73 
+68 
+6c 
+6f 
+6f 
+6b 
+75 
+70 
+00 
+68 
+61 
+73 
+68 
+74 
+61 
+62 
+6c 
+65 
+32 
+00 
+68 
+61 
+73 
+68 
+74 
+61 
+62 
+6c 
+65 
+00 
+64 
+77 
+6f 
+72 
+64 
+61 
+72 
+72 
+61 
+79 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+04 
+00 
+f1 
+ff 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+03 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+04 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+04 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+03 
+00 
+04 
+00 
+03 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+12 
+00 
+00 
+00 
+0e 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+11 
+00 
+04 
+00 
+19 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+03 
+00 
+00 
+00 
+11 
+00 
+04 
+00 
+23 
+00 
+00 
+00 
+04 
+00 
+00 
+00 
+80 
+00 
+00 
+00 
+10 
+00 
+f2 
+ff 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+1d 
+00 
+00 
+00 
+03 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+38 
+00 
+00 
+00 
+27 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+0d 
+00 
+00 
+00 
+03 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+60 
+00 
+00 
+00 
+2e 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+15 
+00 
+00 
+00 
+02 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+90 
+00 
+00 
+00 
+90 
+00 
+00 
+00 
+02 
+00 
+00 
+00 
+05 
+00 
+00 
+00 
+04 
+00 
+00 
+00 
+10 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+06 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+10 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+07 
+00 
+00 
+00 
+01 
+00 
+00 
+00 
+03 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+34 
+00 
+00 
+00 
+04 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+00 
+04 
+00 
+00 
+00 
+00 
+00 
+00 
+00