@@ -1383,7 +1383,8 @@ void obj_mach_o_frob_label (struct symbol *sp)
13831383
13841384 s = (bfd_mach_o_asymbol * ) symbol_get_bfdsym (sp );
13851385 /* Leave debug symbols alone. */
1386- if ((s -> n_type & BFD_MACH_O_N_STAB ) != 0 )
1386+ if ((s -> n_type & BFD_MACH_O_N_STAB ) != 0
1387+ || (s -> symbol .section -> flags & SEC_DEBUGGING ) != 0 )
13871388 return ;
13881389
13891390 /* This is the base symbol type, that we mask in. */
@@ -1433,7 +1434,8 @@ obj_mach_o_frob_symbol (struct symbol *sp)
14331434
14341435 s = (bfd_mach_o_asymbol * ) symbol_get_bfdsym (sp );
14351436 /* Leave debug symbols alone. */
1436- if ((s -> n_type & BFD_MACH_O_N_STAB ) != 0 )
1437+ if ((s -> n_type & BFD_MACH_O_N_STAB ) != 0
1438+ || (s -> symbol .section -> flags & SEC_DEBUGGING ) != 0 )
14371439 return 0 ;
14381440
14391441 base_type = obj_mach_o_type_for_symbol (s );
@@ -1554,68 +1556,6 @@ obj_mach_o_process_stab (int what, const char *string,
15541556 s -> symbol .udata .i = SYM_MACHO_FIELDS_NOT_VALIDATED ;
15551557}
15561558
1557- /* This is a place to check for any errors that we can't detect until we know
1558- what remains undefined at the end of assembly. */
1559-
1560- static void
1561- obj_mach_o_check_before_writing (bfd * abfd ATTRIBUTE_UNUSED ,
1562- asection * sec ,
1563- void * unused ATTRIBUTE_UNUSED )
1564- {
1565- fixS * fixP ;
1566- struct frchain * frchp ;
1567- segment_info_type * seginfo = seg_info (sec );
1568-
1569- if (seginfo == NULL )
1570- return ;
1571-
1572- /* We are not allowed subtractions where either of the operands is
1573- undefined. So look through the frags for any fixes to check. */
1574- for (frchp = seginfo -> frchainP ; frchp != NULL ; frchp = frchp -> frch_next )
1575- for (fixP = frchp -> fix_root ; fixP != NULL ; fixP = fixP -> fx_next )
1576- {
1577- if (fixP -> fx_addsy != NULL
1578- && fixP -> fx_subsy != NULL
1579- && (! S_IS_DEFINED (fixP -> fx_addsy )
1580- || ! S_IS_DEFINED (fixP -> fx_subsy )))
1581- {
1582- segT add_symbol_segment = S_GET_SEGMENT (fixP -> fx_addsy );
1583- segT sub_symbol_segment = S_GET_SEGMENT (fixP -> fx_subsy );
1584-
1585- if (! S_IS_DEFINED (fixP -> fx_addsy )
1586- && S_IS_DEFINED (fixP -> fx_subsy ))
1587- {
1588- as_bad_where (fixP -> fx_file , fixP -> fx_line ,
1589- _ ("`%s' can't be undefined in `%s' - `%s' {%s section}" ),
1590- S_GET_NAME (fixP -> fx_addsy ), S_GET_NAME (fixP -> fx_addsy ),
1591- S_GET_NAME (fixP -> fx_subsy ), segment_name (sub_symbol_segment ));
1592- }
1593- else if (! S_IS_DEFINED (fixP -> fx_subsy )
1594- && S_IS_DEFINED (fixP -> fx_addsy ))
1595- {
1596- as_bad_where (fixP -> fx_file , fixP -> fx_line ,
1597- _ ("`%s' can't be undefined in `%s' {%s section} - `%s'" ),
1598- S_GET_NAME (fixP -> fx_subsy ), S_GET_NAME (fixP -> fx_addsy ),
1599- segment_name (add_symbol_segment ), S_GET_NAME (fixP -> fx_subsy ));
1600- }
1601- else
1602- {
1603- as_bad_where (fixP -> fx_file , fixP -> fx_line ,
1604- _ ("`%s' and `%s' can't be undefined in `%s' - `%s'" ),
1605- S_GET_NAME (fixP -> fx_addsy ), S_GET_NAME (fixP -> fx_subsy ),
1606- S_GET_NAME (fixP -> fx_addsy ), S_GET_NAME (fixP -> fx_subsy ));
1607- }
1608- }
1609- }
1610- }
1611-
1612- /* Do any checks that we can't complete without knowing what's undefined. */
1613- void
1614- obj_mach_o_pre_output_hook (void )
1615- {
1616- bfd_map_over_sections (stdoutput , obj_mach_o_check_before_writing , NULL );
1617- }
1618-
16191559/* Here we count up frags in each subsection (where a sub-section is defined
16201560 as starting with a non-local symbol).
16211561 Note that, if there are no non-local symbols in a section, all the frags will
@@ -1632,6 +1572,10 @@ obj_mach_o_set_subsections (bfd *abfd ATTRIBUTE_UNUSED,
16321572 fragS * frag ;
16331573 frchainS * chain ;
16341574
1575+ /* Don't waste time on debug sections. */
1576+ if ((sec -> flags & SEC_DEBUGGING ) != 0 )
1577+ return ;
1578+
16351579 /* Protect against sections not created by gas. */
16361580 if (seginfo == NULL )
16371581 return ;
@@ -1925,8 +1869,9 @@ obj_mach_o_allow_local_subtract (expressionS * left ATTRIBUTE_UNUSED,
19251869 return obj_mach_o_is_frame_section (seg );
19261870}
19271871
1928- int
1929- obj_mach_o_in_different_subsection (symbolS * a , symbolS * b )
1872+ static bool
1873+ obj_mach_o_in_different_subsection (symbolS * a , segT aseg , valueT offset ,
1874+ symbolS * b )
19301875{
19311876 fragS * fa ;
19321877 fragS * fb ;
@@ -1936,55 +1881,72 @@ obj_mach_o_in_different_subsection (symbolS *a, symbolS *b)
19361881 || !S_IS_DEFINED (b ))
19371882 {
19381883 /* Not in the same segment, or undefined symbol. */
1939- return 1 ;
1884+ return true ;
19401885 }
19411886
1942- fa = symbol_get_frag (a );
1887+ if (symbol_section_p (a ) && aseg != NULL )
1888+ fa = get_frag_for_address (NULL , seg_info (aseg ), offset );
1889+ else
1890+ fa = symbol_get_frag (a );
19431891 fb = symbol_get_frag (b );
19441892 if (fa == NULL || fb == NULL )
19451893 {
19461894 /* One of the symbols is not in a subsection. */
1947- return 1 ;
1895+ return true ;
19481896 }
19491897
19501898 return fa -> obj_frag_data .subsection != fb -> obj_frag_data .subsection ;
19511899}
19521900
1953- int
1954- obj_mach_o_force_reloc_sub_same (fixS * fix , segT seg )
1901+ bool
1902+ obj_mach_o_force_reloc_sub_same (segT seg , fixS * fix , segT addsymseg )
19551903{
1956- if (! SEG_NORMAL (seg ))
1957- return 1 ;
1958- return obj_mach_o_in_different_subsection (fix -> fx_addsy , fix -> fx_subsy );
1904+ if (!SEG_NORMAL (addsymseg ))
1905+ return true;
1906+ if ((seg -> flags & SEC_DEBUGGING ) != 0 )
1907+ return false;
1908+ return obj_mach_o_in_different_subsection (fix -> fx_addsy , addsymseg ,
1909+ fix -> fx_offset , fix -> fx_subsy );
19591910}
19601911
1961- int
1962- obj_mach_o_force_reloc_sub_local (fixS * fix , segT seg ATTRIBUTE_UNUSED )
1912+ bool
1913+ obj_mach_o_force_reloc_sub_local (segT seg , fixS * fix ,
1914+ segT addsymseg ATTRIBUTE_UNUSED )
19631915{
1964- return obj_mach_o_in_different_subsection (fix -> fx_addsy , fix -> fx_subsy );
1916+ if ((seg -> flags & SEC_DEBUGGING ) != 0 )
1917+ return false;
1918+ symbolS * fragsym = fix -> fx_frag -> obj_frag_data .subsection ;
1919+ if (fragsym == NULL )
1920+ return false;
1921+ return obj_mach_o_in_different_subsection (fix -> fx_subsy , NULL , 0 , fragsym );
19651922}
19661923
1967- int
1968- obj_mach_o_force_reloc (fixS * fix )
1924+ bool
1925+ obj_mach_o_force_reloc (segT seg , fixS * fix )
19691926{
19701927 if (generic_force_reloc (fix ))
1971- return 1 ;
1928+ return true;
1929+
1930+ if ((seg -> flags & SEC_DEBUGGING ) != 0 )
1931+ return false;
19721932
19731933 /* Force a reloc if the target is not in the same subsection.
19741934 FIXME: handle (a - b) where a and b belongs to the same subsection ? */
19751935 if (fix -> fx_addsy != NULL )
19761936 {
19771937 symbolS * subsec = fix -> fx_frag -> obj_frag_data .subsection ;
1978- symbolS * targ = fix -> fx_addsy ;
19791938
19801939 /* There might be no subsections at all. */
19811940 if (subsec == NULL )
1982- return 0 ;
1941+ return false ;
19831942
1984- if (S_GET_SEGMENT (targ ) == absolute_section )
1985- return 0 ;
1943+ symbolS * targ = fix -> fx_addsy ;
1944+ segT targseg = S_GET_SEGMENT (targ );
1945+ if (targseg == absolute_section )
1946+ return false;
19861947
1987- return obj_mach_o_in_different_subsection (targ , subsec );
1948+ return obj_mach_o_in_different_subsection (targ , targseg ,
1949+ fix -> fx_offset , subsec );
19881950 }
1989- return 0 ;
1951+ return false ;
19901952}
0 commit comments