commit 748c08ed265010a52893183920edf958f7e9c987
parent c7d9514e1617396ea5fa36788cc84f5ff0874142
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 17 Jan 2025 15:05:54 +0100
libmach/coff32: Add storclass.h and union auxent
This mimic the SystemV structure and avoids many unneeded
definitions in syms.h for many different applications. Also,
using the standard definition of auxent is not so bad, while
we don't use it directly to read/write from disk.
Diffstat:
4 files changed, 131 insertions(+), 115 deletions(-)
diff --git a/include/bits/scc/coff32/aouthdr.h b/include/bits/scc/coff32/aouthdr.h
@@ -12,7 +12,7 @@ struct aouthdr {
};
#define AOUTHDR struct aouthdr
-#define AOUTSZ sizeof(AOUTHDR)
+#define AOUTSZ 28
#define QMAGIC 0314
#define STMAGIC 0401
diff --git a/include/bits/scc/coff32/storclass.h b/include/bits/scc/coff32/storclass.h
@@ -0,0 +1,32 @@
+/* storage class */
+
+#define C_EFCN -1 /* physical end of function */
+#define C_NULL 0
+#define C_AUTO 1 /* automatic variable */
+#define C_EXT 2 /* external symbol */
+#define C_STAT 3 /* static */
+#define C_REG 4 /* register variable */
+#define C_EXTDEF 5 /* external definition */
+#define C_LABEL 6 /* label */
+#define C_ULABEL 7 /* undefined label */
+#define C_MOS 8 /* member of structure */
+#define C_ARG 9 /* function argument */
+#define C_STRTAG 10 /* structure tag */
+#define C_MOU 11 /* member of union */
+#define C_UNTAG 12 /* union tag */
+#define C_TPDEF 13 /* type definition */
+#define C_USTATIC 14 /* undefined static */
+#define C_ENTAG 15 /* enumeration tag */
+#define C_MOE 16 /* member of enumeration */
+#define C_REGPARM 17 /* register parameter */
+#define C_FIELD 18 /* bit field */
+#define C_AUTOARG 19 /* auto argument */
+#define C_LASTENT 20 /* dummy entry (end of block) */
+#define C_BLOCK 100 /* ".bb" or ".eb" */
+#define C_FCN 101 /* ".bf" or ".ef" */
+#define C_EOS 102 /* end of structure */
+#define C_FILE 103 /* file name */
+#define C_LINE 104 /* used only by utility programs (STS) */
+#define C_ALIAS 105 /* duplicate tag */
+#define C_HIDDEN 106 /* like static, used to avoid name conflicts */
+#define C_WEAKEXT 127 /* used for weak references */
diff --git a/include/bits/scc/coff32/syms.h b/include/bits/scc/coff32/syms.h
@@ -4,7 +4,40 @@
* - the book "UNIX System V 386 R3.2 Programmers guide, Vol 2"
*/
+/* Special n_scnum values */
+#define N_TV -3
+#define N_DEBUG -2
+#define N_ABS -1
+#define N_UNDEF 0
+#define N_SCNUM(x) ((x) > 0)
+
+/* basic types */
+#define T_NULL 0
+#define T_VOID 1
+#define T_CHAR 2
+#define T_SHORT 3
+#define T_INT 4
+#define T_LONG 5
+#define T_FLOAT 6
+#define T_DOUBLE 7
+#define T_STRUCT 8
+#define T_UNION 9
+#define T_ENUM 10
+#define T_MOE 11
+#define T_UCHAR 12
+#define T_USHORT 13
+#define T_UINT 14
+#define T_ULONG 15
+#define T_LNGDBL 16
+
+/* derivated types */
+#define DT_NON 0
+#define DT_PTR 1
+#define DT_FCN 2
+#define DT_ARY 3
+
#define SYMNMLEN 8
+#define FILNMLEN 14
#define SYMENT struct syment
#define SYMESZ 18
@@ -17,8 +50,8 @@
#define n_offset _n._n_n._n_offset
#define n_nptr _n._n_nptr[1]
-#define FILNMLEN 14
-#define EFILNMLEN 20
+#define E_FILNMLEN 18
+#define DIMNUM 4
struct syment {
union {
@@ -36,121 +69,71 @@ struct syment {
char n_numaux; /* number of aux. entries */
};
-struct x_file {
+#define x_fname _x_file._x_fname
+#define x_zeroes _x_file._x_n._x_zeroes
+#define x_offset _x_file._x_n._x_offset
+#define x_tagndx _x_sym._x_tagndx
+#define x_lnno _x_sym._x_misc._x_lnsz._x_lnno
+#define x_size _x_sym._x_misc._x_lnsz._x_size
+#define x_fsize _x_sym._x_misc._x_fsize
+#define x_lnnoptr _x_sym._x_fcnary._x_fcn._x_lnnoptr
+#define x_endndx _x_sym._x_fcnary._x_fcn._x_endndx
+#define x_dimen _x_sym._x_fcnary._x_ary._x_dimen
+#define x_tvndx _x_sym._x_tvndx
+#define x_scnlen _x_scn._x_scnlen
+#define x_nreloc _x_scn._x_nreloc
+#define x_nlinno _x_scn._x_nlinno
+#define x_checksum _x_scn._x_checksum
+#define x_associated _x_scn._x_associated
+#define x_comdat _x_scn._x_comdat
+#define x_tvfill _x_tv._x_tvfill
+#define x_tvlen _x_tv._x_tvlen
+#define x_tvran _x_tv._x_tvran
+
+union auxent {
union {
- char _x_fname[EFILNMLEN]; /* file name */
+ char _x_fname[E_FILNMLEN]; /* file name */
struct {
- long x_zeroes; /* if _x_fname[0-3] == 0 */
- long x_offset; /* offset into string table */
+ long _x_zeroes; /* if _x_fname[0-3] == 0 */
+ long _x_offset; /* offset into string table */
} _x_n;
} _x_file;
-};
-
-struct x_tag {
- char zeroes0[6];
- unsigned short x_size; /* size of struct, union or enum */
- char zeroes1[4];
- long x_endndx; /* index of next entry for the tag */
-};
-
-struct x_etag {
- long xtagndx; /* tag index */
- char zeroes[2];
- unsigned short x_size; /* size of struct, union or enum */
-};
-struct x_scn {
- long x_scnlen; /* section length */
- unsigned short x_nreloc; /* num reloc entries */
- unsigned short x_nlinno; /* num line numbers */
- unsigned long x_checksum; /* section COMDAT checksum for PE */
- unsigned short x_associated; /* COMDAT associated section index for PE */
- unsigned char x_comdat; /* COMDAT selection number for PE */
+ struct {
+ long _x_tagndx; /* str, un, or enum tag indx */
+ union {
+ struct {
+ unsigned short _x_lnno; /* declaration line number */
+ unsigned short _x_size; /* str, union, array size */
+ } _x_lnsz;
+ long _x_fsize; /* size of function */
+ } _x_misc;
+
+ union {
+ struct { /* if ISFCN, tag, or .bb */
+ long _x_lnnoptr; /* ptr to fcn line # */
+ long _x_endndx; /* entry ndx past block end */
+ } _x_fcn;
+ struct { /* if ISARY, up to 4 dimen. */
+ unsigned short _x_dimen[DIMNUM];
+ } _x_ary;
+ } _x_fcnary;
+
+ unsigned short _x_tvndx; /* tv index */
+ } _x_sym;
+
+ struct {
+ long _x_scnlen; /* section length */
+ unsigned short _x_nreloc; /* number of relocation entries */
+ unsigned short _x_nlinno; /* number of line numbers */
+ unsigned long _x_checksum; /* section COMDAT checksum */
+ unsigned short _x_associated; /* COMDAT associated section index */
+ unsigned char _x_comdat; /* COMDAT selection number */
+ } _x_scn;
+
+ struct { /* info about .tv section (in auxent of symbol .tv)) */
+ long _x_tvfill; /* tv fill value */
+ unsigned short _x_tvlen; /* length of .tv */
+ unsigned short _x_tvran[2]; /* tv range */
+ } _x_tv;
};
-
-struct x_fun {
- long x_tagndx; /* tag index */
- long x_fsize; /* size in bytes */
- long x_lnnoptr; /* file pointer to line info */
- long x_endndx; /* index to next entry */
- unsigned short x_tvndx; /* index of function in vector table */
-};
-
-struct x_ary {
- long x_tagndx; /* tag index */
- unsigned short x_lnno; /* line number of declaration */
- unsigned short x_size; /* size of array */
- unsigned short x_dimen[4]; /* until 4 dimensions */
-};
-
-union auxent {
- struct x_fun x_fun;
- struct x_ary x_ary;
- struct x_scn x_scn;
- struct x_tag x_tag;
- struct x_etag x_etag;
- struct x_file x_file;
-};
-
-/* Special n_scnum values */
-#define N_DEBUG -2
-#define N_ABS -1
-#define N_UNDEF 0
-#define N_SCNUM(x) ((x) > 0)
-
-/* basic types */
-#define T_NULL 0
-#define T_VOID 1
-#define T_CHAR 2
-#define T_SHORT 3
-#define T_INT 4
-#define T_LONG 5
-#define T_FLOAT 6
-#define T_DOUBLE 7
-#define T_STRUCT 8
-#define T_UNION 9
-#define T_ENUM 10
-#define T_MOE 11
-#define T_UCHAR 12
-#define T_USHORT 13
-#define T_UINT 14
-#define T_ULONG 15
-#define T_LNGDBL 16
-
-/* derivated types */
-#define DT_NON 0
-#define DT_PTR 1
-#define DT_FCN 2
-#define DT_ARY 3
-
-/* storage class */
-#define C_NULL 0
-#define C_AUTO 1
-#define C_EXT 2
-#define C_STAT 3
-#define C_REG 4
-#define C_EXTDEF 5
-#define C_LABEL 6
-#define C_ULABEL 7
-#define C_MOS 8
-#define C_ARG 9
-#define C_STRTAG 10
-#define C_MOU 11
-#define C_UNTAG 12
-#define C_TPDEF 13
-#define C_USTATIC 14
-#define C_ENTAG 15
-#define C_MOE 16
-#define C_REGPARM 17
-#define C_FIELD 18
-#define C_AUTOARG 19
-#define C_LASTENT 20
-#define C_BLOCK 100
-#define C_FCN 101
-#define C_EOS 102
-#define C_FILE 103
-#define C_LINE 104
-#define C_ALIAS 105
-#define C_HIDDEN 106
-#define C_WEAKEXT 127
-#define C_EFCN 255
diff --git a/src/libmach/coff32/coff32.h b/src/libmach/coff32/coff32.h
@@ -4,6 +4,7 @@
#include <scc/coff32/syms.h>
#include <scc/coff32/reloc.h>
#include <scc/coff32/linenum.h>
+#include <scc/coff32/storclass.h>
typedef struct coff32 Coff32;