From: loic@adesign.uucp (Loic Dachary) Newsgroups: alt.sources Subject: gas-1.36 patches for COFF generation Message-ID: Date: 16 Oct 90 08:35:56 GMT *** struc-symbol.h Fri May 12 19:45:21 1989 --- /lasvegas/spare/usenet/port/gas-1.36/struc-symbol.h Mon Oct 15 08:41:38 1990 *************** *** 17,31 **** along with GAS; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ - #ifndef VMS - #include "a.out.h" /* Needed to define struct nlist. Sigh. */ - #else - #include "a_out.h" - #endif - struct symbol /* our version of an nlist node */ { ! struct nlist sy_nlist; /* what we write in .o file (if permitted) */ long unsigned sy_name_offset; /* 4-origin position of sy_name in symbols */ /* part of object file. */ /* 0 for (nameless) .stabd symbols. */ --- 17,25 ---- along with GAS; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ struct symbol /* our version of an nlist node */ { ! symbol_type sy_symbol; /* what we write in .o file (if permitted) */ long unsigned sy_name_offset; /* 4-origin position of sy_name in symbols */ /* part of object file. */ /* 0 for (nameless) .stabd symbols. */ *************** *** 34,54 **** /* Symbol numbers start at 0 and are */ /* unsigned. */ struct symbol * sy_next; /* forward chain, or NULL */ struct frag * sy_frag; /* NULL or -> frag this symbol attaches to. */ struct symbol *sy_forward; /* value is really that of this other symbol */ }; typedef struct symbol symbolS; ! #define sy_name sy_nlist .n_un. n_name /* Name field always points to a string. */ /* 0 means .stabd-like anonymous symbol. */ ! #define sy_type sy_nlist. n_type ! #define sy_other sy_nlist. n_other ! #define sy_desc sy_nlist. n_desc ! #define sy_value sy_nlist. n_value /* Value of symbol is this value + object */ /* file address of sy_frag. */ typedef unsigned valueT; /* The type of n_value. Helps casting. */ --- 28,71 ---- /* Symbol numbers start at 0 and are */ /* unsigned. */ struct symbol * sy_next; /* forward chain, or NULL */ + #ifdef coff + struct symbol * sy_previous; /* backward chain, or NULL */ + #endif /* coff */ struct frag * sy_frag; /* NULL or -> frag this symbol attaches to. */ struct symbol *sy_forward; /* value is really that of this other symbol */ + #ifdef coff + unsigned int sy_flags; /* Internal use only flags (see coff.h) */ + AUXENT sy_auxent; /* Auxiliary entry. */ + #endif /* coff */ }; typedef struct symbol symbolS; ! #ifdef coff ! ! #define sy_name sy_symbol.n_name /* Symbol name */ ! #define sy_zeroes sy_symbol.n_zeroes /* All 0 if pointer to str. */ ! #define sy_offset sy_symbol.n_offset /* Offset in string table */ ! #define sy_value sy_symbol.n_value /* Symbol 0 or ptr in file */ ! #define sy_scnum sy_symbol.n_scnum /* Section number */ ! #define sy_type sy_symbol.n_type /* Type and derived type */ ! #define sy_sclass sy_symbol.n_sclass /* Storage class */ ! #define sy_numaux sy_symbol.n_numaux /* Number of aux. entries */ ! ! #else /* coff */ ! ! #define sy_name sy_symbol.n_un.n_name /* Name field always points to a string. */ /* 0 means .stabd-like anonymous symbol. */ ! #define sy_strx sy_symbol.n_un.n_strx ! #define sy_type sy_symbol.n_type ! #define sy_other sy_symbol.n_other ! #define sy_desc sy_symbol.n_desc ! #define sy_value sy_symbol.n_value /* Value of symbol is this value + object */ /* file address of sy_frag. */ + + #endif /* coff */ typedef unsigned valueT; /* The type of n_value. Helps casting. */ *** subsegs.c Wed Mar 1 23:48:46 1989 --- /lasvegas/spare/usenet/port/gas-1.36/subsegs.c Wed Sep 12 09:28:57 1990 *************** *** 21,26 **** --- 21,27 ---- * Segments & sub-segments. */ + #include "oformat.h" #include "as.h" #include "subsegs.h" #include "obstack.h" *************** *** 33,40 **** --- 34,95 ---- * data0_frchainP; + #ifdef coff int /* in: segT out: N_TYPE bits */ seg_N_TYPE[] = { + C_ABS_SECTION, + C_TEXT_SECTION, + C_DATA_SECTION, + C_BSS_SECTION, + C_UNDEF_SECTION, /* SEG_UNKNOWN */ + C_UNDEF_SECTION, /* SEG_NONE */ + C_UNDEF_SECTION, /* SEG_PASS1 */ + C_UNDEF_SECTION, /* SEG_GOOF */ + C_UNDEF_SECTION, /* SEG_BIG */ + C_UNDEF_SECTION, /* SEG_DIFFERENCE */ + C_DEBUG_SECTION, /* SEG_DEBUG */ + C_NTV_SECTION, /* SEG_NTV */ + C_PTV_SECTION, /* SEG_PTV */ + }; + + + char * /* in: segT out: char* */ + seg_name[] = { + "absolute", + "text", + "data", + "bss", + "unknown", + "absent", + "pass1", + "ASSEMBLER-INTERNAL-LOGIC-ERROR!", + "bignum/flonum", + "difference", + "debug", + "transfert vector preload", + "transfert vector postload", + "" + }; /* Used by error reporters, dumpers etc. */ + + /* Add 4 to the real value to get the index and compensate the negatives */ + + segT N_TYPE_seg [32] = + { + SEG_PTV, /* C_PTV_SECTION == -4 */ + SEG_NTV, /* C_NTV_SECTION == -3 */ + SEG_DEBUG, /* C_DEBUG_SECTION == -2 */ + SEG_ABSOLUTE, /* C_ABS_SECTION == -1 */ + SEG_UNKNOWN, /* C_UNDEF_SECTION == 0 */ + SEG_TEXT, /* C_TEXT_SECTION == 1 */ + SEG_DATA, /* C_DATA_SECTION == 2 */ + SEG_BSS, /* C_BSS_SECTION == 3 */ + SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF, + SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF, + SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF,SEG_GOOF + }; + #else /* coff */ + int /* in: segT out: N_TYPE bits */ + seg_N_TYPE[] = { N_ABS, N_TEXT, N_DATA, *************** *** 78,83 **** --- 133,139 ---- SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF }; + #endif /* coff */ void subsegs_begin() *** symbols.c Fri Apr 6 17:51:22 1990 --- /lasvegas/spare/usenet/port/gas-1.36/symbols.c Mon Oct 15 10:30:08 1990 *************** *** 18,23 **** --- 18,24 ---- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ + #include "oformat.h" #include "as.h" #include "hash.h" #include "obstack.h" /* For "symbols.h" */ *************** *** 38,43 **** --- 39,49 ---- symbolS * symbol_rootP; symbolS * symbol_lastP; symbolS abs_symbol; + + symbolS* dot_text_symbol; + symbolS* dot_data_symbol; + symbolS* dot_bss_symbol; + struct obstack notes; *************** *** 84,90 **** symbol_rootP = NULL; /* In case we have 0 symbols (!!) */ sy_hash = hash_new(); bzero ((char *)(& abs_symbol), sizeof(abs_symbol)); ! abs_symbol . sy_type = N_ABS; /* Can't initialise a union. Sigh. */ bzero ((char *)(local_label_counter), sizeof(local_label_counter) ); local_bss_counter = 0; } --- 90,96 ---- symbol_rootP = NULL; /* In case we have 0 symbols (!!) */ sy_hash = hash_new(); bzero ((char *)(& abs_symbol), sizeof(abs_symbol)); ! S_SET_ABS(&abs_symbol); /* Can't initialise a union. Sigh. */ bzero ((char *)(local_label_counter), sizeof(local_label_counter) ); local_bss_counter = 0; } *************** *** 157,162 **** --- 163,237 ---- * Changes since 1985: Symbol names may not contain '\0'. Sigh. */ + #ifdef coff + + symbolS * + symbol_new (name, segment, value, sclass, frag) + char* name; /* It is copied, the caller can destroy/modify */ + segT segment;/* Segment identifier (SEG_) */ + long value; /* Symbol value */ + short sclass; /* Symbol storage class */ + fragS* frag; /* Associated fragment */ + { + register unsigned int name_length; + register char* name_copy; + register symbolS* symbolP; + register char underscore = 0; /* Symbol has leading _ */ + + #if STRIP_UNDERSCORE + /* Remove leading underscore at the beginning of the symbol. + * This is to be compatible with the standard librairies. + */ + if(*name == '_') { + underscore = 1; + name++; + } else + underscore = 0; + #endif /* STRIP_UNDERSCORE */ + name_length = strlen(name) + 1; /* +1 for \0 */ + obstack_grow(¬es, name, name_length); + name_copy = obstack_finish(¬es); + symbolP = (symbolS *)obstack_alloc(¬es, sizeof(symbolS)); + + /* Effective symbol */ + /* Store the pointer in the offset. */ + symbolP->sy_offset = (long unsigned)name_copy; + symbolP->sy_zeroes = 0L; + symbolP->sy_value = value; + symbolP->sy_scnum = seg_SEG(segment); + symbolP->sy_type = T_NULL; + symbolP->sy_sclass = sclass; + symbolP->sy_numaux = 0; + /* Additional information */ + symbolP->sy_next = NULL; + symbolP->sy_frag = frag; + symbolP->sy_forward = NULL; + symbolP->sy_name_offset = ~0; + symbolP->sy_number = ~0; + symbolP->sy_flags = 0; + /* Auxiliary entries */ + memset((char*)&symbolP->sy_auxent, '\0', AUXESZ); + + if(S_IS_STRING(symbolP)) + SF_SET_STRING(symbolP); + if(!underscore && S_IS_LOCAL(symbolP)) + SF_SET_LOCAL(symbolP); + /* + * Link to end of symbol chain . + */ + if (symbol_lastP) { + symbol_lastP->sy_next = symbolP; + symbolP->sy_previous = symbol_lastP; + } else { + symbol_rootP = symbolP; + } + symbol_lastP = symbolP; + + return (symbolP); + } + + #else /* coff */ + symbolS * symbol_new (name, type, other, desc, value, frag) char * name; /* We copy this: OK to alter your copy. */ *************** *** 165,171 **** short int desc; /* As in . */ valueT value; /* As in , often an address. */ /* Often used as offset from frag address. */ ! struct frag * frag; /* For sy_frag. */ { register symbolS * symbolP; register char * preserved_copy_of_name; --- 240,246 ---- short int desc; /* As in . */ valueT value; /* As in , often an address. */ /* Often used as offset from frag address. */ ! fragS* frag; /* For sy_frag. */ { register symbolS * symbolP; register char * preserved_copy_of_name; *************** *** 177,184 **** p=obstack_finish(¬es); /* obstack_1done( ¬es, name, name_length, &p ); */ preserved_copy_of_name = p; ! p=obstack_alloc(¬es,sizeof(struct symbol)); ! /* obstack_1blank( ¬es, sizeof(struct symbol), &p ); */ symbolP = (symbolS *) p; symbolP -> sy_name = preserved_copy_of_name; symbolP -> sy_type = type; --- 252,259 ---- p=obstack_finish(¬es); /* obstack_1done( ¬es, name, name_length, &p ); */ preserved_copy_of_name = p; ! p=obstack_alloc(¬es,sizeof(symbolS)); ! /* obstack_1blank( ¬es, sizeof(symbolS), &p ); */ symbolP = (symbolS *) p; symbolP -> sy_name = preserved_copy_of_name; symbolP -> sy_type = type; *************** *** 207,212 **** --- 282,289 ---- return (symbolP); } + + #endif /* coff */ /* * colon() *************** *** 222,228 **** register char * sym_name; /* symbol name, as a cannonical string */ /* We copy this string: OK to alter later. */ { ! register struct symbol * symbolP; /* symbol we are working with */ #ifdef SUN_ASM_SYNTAX /* Sun local labes go out of scope whenever a non-local symbol is --- 299,305 ---- register char * sym_name; /* symbol name, as a cannonical string */ /* We copy this string: OK to alter later. */ { ! register symbolS * symbolP; /* symbol we are working with */ #ifdef SUN_ASM_SYNTAX /* Sun local labes go out of scope whenever a non-local symbol is *************** *** 264,270 **** * If the new symbol is .comm AND it has a size of zero, * we ignore it (i.e. the old symbol overrides it) */ ! if ((seg_N_TYPE [(int) now_seg] == (N_UNDF | N_EXT)) && ((obstack_next_free(& frags) - frag_now -> fr_literal) == 0)) return; /* --- 341,347 ---- * If the new symbol is .comm AND it has a size of zero, * we ignore it (i.e. the old symbol overrides it) */ ! if ((seg_SEG((int) now_seg) == (N_UNDF | N_EXT)) && ((obstack_next_free(& frags) - frag_now -> fr_literal) == 0)) return; /* *************** *** 275,281 **** (symbolP->sy_value == 0)) { symbolP -> sy_frag = frag_now; symbolP -> sy_value = obstack_next_free(& frags) - frag_now -> fr_literal; ! symbolP -> sy_type |= seg_N_TYPE [(int) now_seg]; /* keep N_EXT bit */ return; } #endif /* VMS */ --- 352,358 ---- (symbolP->sy_value == 0)) { symbolP -> sy_frag = frag_now; symbolP -> sy_value = obstack_next_free(& frags) - frag_now -> fr_literal; ! symbolP -> sy_type |= seg_SEG((int) now_seg); /* keep N_EXT bit */ return; } #endif /* VMS */ *************** *** 282,297 **** /* * Now check for undefined symbols */ ! if ((symbolP -> sy_type & N_TYPE) == N_UNDF) { ! if( symbolP -> sy_other == 0 ! && symbolP -> sy_desc == 0 ! && symbolP -> sy_value == 0) { symbolP -> sy_frag = frag_now; ! symbolP -> sy_value = obstack_next_free(& frags) - frag_now -> fr_literal; ! know( N_UNDF == 0 ); ! symbolP -> sy_type |= seg_N_TYPE [(int) now_seg]; /* keep N_EXT bit */ } else { --- 359,382 ---- /* * Now check for undefined symbols */ ! if (!S_IS_DEFINED(symbolP)) { ! if( ! #ifdef aout ! S_GET_OTHER(symbolP) == 0 && ! S_GET_DESC(symbolP) == 0 && ! #endif /* aout */ ! S_GET_VALUE(symbolP) == 0) { symbolP -> sy_frag = frag_now; ! S_SET_VALUE(symbolP, obstack_next_free(& frags) - ! frag_now -> fr_literal); ! switch(now_seg) { ! case SEG_TEXT: S_SET_TEXT(symbolP); break; ! case SEG_DATA: S_SET_DATA(symbolP); break; ! case SEG_BSS: S_SET_BSS(symbolP); break; ! case SEG_ABSOLUTE: S_SET_ABS(symbolP); break; ! } } else { *************** *** 303,309 **** * A .comm/.lcomm symbol being redefined with * a larger size is also OK */ ! char New_Type = seg_N_TYPE [(int) now_seg]; if (((symbolP->sy_type == (N_UNDF | N_EXT)) || (symbolP->sy_type == N_BSS)) && (((New_Type & ~N_EXT) == N_DATA) || --- 388,394 ---- * A .comm/.lcomm symbol being redefined with * a larger size is also OK */ ! char New_Type = seg_SEG((int) now_seg); if (((symbolP->sy_type == (N_UNDF | N_EXT)) || (symbolP->sy_type == N_BSS)) && (((New_Type & ~N_EXT) == N_DATA) || *************** *** 331,345 **** */ symbolP -> sy_frag = frag_now; symbolP -> sy_value = obstack_next_free(& frags) - frag_now -> fr_literal; ! symbolP -> sy_type |= seg_N_TYPE [(int) now_seg]; /* keep N_EXT bit */ } } else { #endif /* VMS */ as_fatal( "Symbol \"%s\" is already defined as \"%s\"/%d.%d.%d.", sym_name, ! seg_name [(int) N_TYPE_seg [symbolP -> sy_type & N_TYPE]], ! symbolP -> sy_other, symbolP -> sy_desc, ! symbolP -> sy_value); #ifdef VMS } #endif /* VMS */ --- 416,437 ---- */ symbolP -> sy_frag = frag_now; symbolP -> sy_value = obstack_next_free(& frags) - frag_now -> fr_literal; ! symbolP -> sy_type |= seg_SEG((int) now_seg); /* keep N_EXT bit */ } } else { #endif /* VMS */ + #ifdef coff + as_fatal( "Symbol \"%s\" is already defined as \"%s\"/%d.", + sym_name, + segment_name((int)SEG_seg(S_GET_SEGMENT(symbolP))), + S_GET_VALUE(symbolP)); + #else /* coff */ as_fatal( "Symbol \"%s\" is already defined as \"%s\"/%d.%d.%d.", sym_name, ! segment_name((int)SEG_seg(S_GET_SEGMENT(symbolP))), ! S_GET_OTHER(symbolP), S_GET_DESC(symbolP), ! S_GET_VALUE(symbolP)); ! #endif /* coff */ #ifdef VMS } #endif /* VMS */ *************** *** 352,363 **** } else { symbolP = symbol_new (sym_name, ! (unsigned char)(seg_N_TYPE [(int) now_seg]), 0, 0, (valueT)(obstack_next_free(&frags)-frag_now->fr_literal), frag_now); symbol_table_insert (symbolP); } } --- 444,461 ---- } else { + #ifdef coff + symbolP = symbol_new (sym_name, now_seg, + (valueT)(obstack_next_free(&frags)-frag_now->fr_literal), + 0, frag_now); + #else /* coff */ symbolP = symbol_new (sym_name, ! (unsigned char)(seg_SEG((int) now_seg)), 0, 0, (valueT)(obstack_next_free(&frags)-frag_now->fr_literal), frag_now); + #endif /* coff */ symbol_table_insert (symbolP); } } *************** *** 372,387 **** void symbol_table_insert (symbolP) ! struct symbol * symbolP; { register char * error_string; ! know( symbolP ); ! know( symbolP -> sy_name ); ! if ( * (error_string = hash_jam (sy_hash, symbolP -> sy_name, (char *)symbolP))) { as_fatal( "Inserting \"%s\" into symbol table failed: %s", ! symbolP -> sy_name, error_string); } } --- 470,487 ---- void symbol_table_insert (symbolP) ! symbolS * symbolP; { register char * error_string; ! know(symbolP); ! know(S_GET_NAME(symbolP)); ! ! if ( * (error_string = hash_jam (sy_hash, S_GET_NAME(symbolP), ! (char *)symbolP))) { as_fatal( "Inserting \"%s\" into symbol table failed: %s", ! S_GET_NAME(symbolP), error_string); } } *************** *** 392,409 **** * it into the symbol table. Return a pointer to it. */ symbolS * ! symbol_find_or_make (name) ! char * name; { ! register symbolS * symbolP; ! symbolP = symbol_table_lookup (name); ! if (symbolP == NULL) ! { ! symbolP = symbol_new (name, N_UNDF, 0, 0, 0, & zero_address_frag); ! symbol_table_insert (symbolP); ! } ! return (symbolP); } /* --- 492,514 ---- * it into the symbol table. Return a pointer to it. */ symbolS * ! symbol_find_or_make (name) ! char * name; { ! register symbolS * symbolP; ! symbolP = symbol_table_lookup (name); ! ! if (symbolP == NULL) ! { ! #ifdef coff ! symbolP = symbol_new (name, SEG_UNKNOWN, 0, 0, &zero_address_frag); ! #else /* coff */ ! symbolP = symbol_new (name, N_UNDF, 0, 0, 0, & zero_address_frag); ! #endif /* coff */ ! symbol_table_insert (symbolP); ! } ! return (symbolP); } /* *************** *** 417,426 **** symbolS * symbol_find (name) ! char * name; { ! return ( (symbolS *) hash_find( sy_hash, name )); } /* end: symbols.c */ --- 522,539 ---- symbolS * symbol_find (name) ! char* name; { ! return symbol_find_base(name, STRIP_UNDERSCORE); } + symbolS * + symbol_find_base (name, strip_underscore) + char * name; + int strip_underscore; + { + if(strip_underscore && *name == '_') name++; + return ( (symbolS *) hash_find( sy_hash, name )); + } /* end: symbols.c */ *** symbols.h Wed Mar 1 23:48:43 1989 --- /lasvegas/spare/usenet/port/gas-1.36/symbols.h Mon Oct 15 10:29:43 1990 *************** *** 30,36 **** --- 30,41 ---- extern symbolS abs_symbol; + extern symbolS* dot_text_symbol; + extern symbolS* dot_data_symbol; + extern symbolS* dot_bss_symbol; + symbolS * symbol_find(); + symbolS * symbol_find_base(); void symbol_begin(); char * local_label_name(); void local_colon(); -- Loic Dachary loic@adesign.uucp or loic@afp.uucp Voice +33 1 40 35 20 20