extern void AsNumLabelEmit( uint_32 label_num, owl_section_handle section, owl_offset offset, owl_sym_type type ) { //***************************************************************************************************************** // These symbols are used for matching l^ & h^ garbage. sym_handle new_fw_sym; // forward char *new_fw_name; sym_reloc reloc; int_32 numlabel_ref; new_fw_name = AsNumLabelMakeName( label_num ); new_fw_sym = SymLookup( new_fw_name ); if( new_fw_sym ) { // check if it still has some unemitted relocs if( new_fw_sym->hi_relocs ) { Error( UNMATCHED_HIGH_RELOC, "<numeric reference>" ); while( new_fw_sym->hi_relocs ) { SymDestroyReloc( new_fw_sym, new_fw_sym->hi_relocs ); } } if( new_fw_sym->lo_relocs ) { _DBGMSG1( "emitting all the unemitted l^relocs\n" ); while( ( reloc = new_fw_sym->lo_relocs ) != NULL ) { numlabel_ref = AsNumLabelGetNum( SymName( new_fw_sym ) ); #ifdef _STANDALONE_ ObjDirectEmitReloc( reloc->location.section, #else ObjDirectEmitReloc( #endif reloc->location.offset, &numlabel_ref, OWL_RELOC_HALF_LO, FALSE ); SymDestroyReloc( new_fw_sym, reloc ); reloc = new_fw_sym->lo_relocs; } } assert( new_fw_sym->hi_relocs == NULL && new_fw_sym->lo_relocs == NULL ); } else {
void ObjRelocsFini( void ) { //************************** // If the parse was successful, we need to check whether there're any unmatched // relocs still hanging around. If there're unmatched h^relocs, we issue an // error. If there're unmatched l^relocs, we should be able to emit them. sym_reloc reloc; sym_handle sym; int_32 numlabel_ref; reloc = SymGetReloc( TRUE, &sym ); while( reloc != NULL ) { if( reloc->named ) { Error( UNMATCHED_HIGH_RELOC, SymName( sym ) ); } else { // TODO: actually show the numref (eg. 2f) Error( UNMATCHED_HIGH_RELOC, "<numeric reference>" ); } SymDestroyReloc( sym, reloc ); reloc = SymGetReloc( TRUE, &sym ); } reloc = SymGetReloc( FALSE, &sym ); while( reloc != NULL ) { if( reloc->named ) { doEmitReloc( reloc->location.section, reloc->location.offset, SymName( sym ), OWL_RELOC_HALF_LO, TRUE ); } else { numlabel_ref = AsNumLabelGetNum( SymName( sym ) ); doEmitReloc( reloc->location.section, reloc->location.offset, &numlabel_ref, OWL_RELOC_HALF_LO, FALSE ); } SymDestroyReloc( sym, reloc ); reloc = SymGetReloc( FALSE, &sym ); } #ifdef AS_DEBUG_DUMP (void)SymRelocIsClean( TRUE ); #endif ObjFlushLabels(); // In case there're still pending labels AsNumLabelFini(); // resolve all numeric label relocs }
extern void ObjRelocsFini( void ) { //********************************* // After all lines have been parsed, we need to check whether there're any // unmatched relocs still hanging around. If there're unmatched h^relocs, // we issue an error. If there're unmatched l^relocs, we should be able // to emit them. sym_reloc reloc; sym_handle sym; int_32 numlabel_ref; reloc = SymGetReloc( TRUE, &sym ); while( reloc != NULL ) { if( reloc->named ) { Error( UNMATCHED_HIGH_RELOC, SymName( sym ) ); } else { Error( UNMATCHED_HIGH_RELOC, "<numeric reference>" ); } SymDestroyReloc( sym, reloc ); reloc = SymGetReloc( TRUE, &sym ); } reloc = SymGetReloc( FALSE, &sym ); while( reloc != NULL ) { if( reloc->named ) { doEmitReloc( reloc->location.offset, SymName( sym ), OWL_RELOC_HALF_LO, TRUE ); } else { numlabel_ref = AsNumLabelGetNum( SymName( sym ) ); doEmitReloc( reloc->location.offset, &numlabel_ref, OWL_RELOC_HALF_LO, FALSE ); } SymDestroyReloc( sym, reloc ); reloc = SymGetReloc( FALSE, &sym ); } #ifdef AS_DEBUG_DUMP (void)SymRelocIsClean( TRUE ); #endif AsNumLabelFini(); // resolve all numeric label relocs resolveRelativeRelocs(); }
void ObjEmitReloc( owl_section_handle section, void *target, owl_reloc_type type, bool align, bool named_sym ) { //************************************************************************************************************** // Should be called before emitting the data that has the reloc. // (named_sym == TRUE) iff the target is a named label owl_offset offset; if( align ) { // If data is aligned, we should also align this reloc offset! offset = ObjAlign( section, CurrAlignment ); } else { offset = OWLTellOffset( section ); } ObjFlushLabels(); #ifdef AS_PPC doEmitReloc( section, offset, target, type, named_sym ); #else { sym_reloc reloc; bool match_high; owl_offset offset_hi, offset_lo; sym_handle (*lookup_func)( void * ); if( type != OWL_RELOC_HALF_HI && type != OWL_RELOC_HALF_LO ) { doEmitReloc( section, offset, target, type, named_sym ); } else { lookup_func = named_sym ? (sym_handle (*)(void *))SymLookup : (sym_handle (*)(void *))AsNumLabelSymLookup; match_high = ( type == OWL_RELOC_HALF_LO ); // hi match lo etc. reloc = SymMatchReloc( match_high, lookup_func( target ), section ); if( reloc ) { // got a match if( match_high ) { offset_hi = reloc->location.offset; offset_lo = offset; } else { offset_hi = offset; offset_lo = reloc->location.offset; } doEmitReloc( section, offset_hi, target, OWL_RELOC_HALF_HI, named_sym ); doEmitReloc( section, offset_lo, target, OWL_RELOC_PAIR, named_sym ); doEmitReloc( section, offset_lo, target, OWL_RELOC_HALF_LO, named_sym ); SymDestroyReloc( lookup_func( target ), reloc ); } else { // no match; stack it up with the (aligned) offset! SymStackReloc( !match_high, lookup_func( target ), section, offset, named_sym ); } } } #endif }