[PATCH] Prevent local labels from showing on the symbol table in arm coff targets.

Pedro Alves pedro_alves@portugalmail.pt
Mon Oct 23 02:14:00 GMT 2006

Hi guys,

(Sorry for the big message, ChangeLog at the end.)

All arm coff based targets are currently putting local labels in the
symbol table,
provided there is a reloc against them.

Ex, arm-coff (local label prefix == ""):

$cat local_label.s
         .word   Lused_label

$arm-unknown-coff-as local_label.s -o local_label.o

$arm-unknown-coff-nm local_label.o
00000000 b .bss
00000000 d .data
00000000 t .text
00000000 t Lused_label

The problem is that when gas attempts to convert symbol relocs into
section symbol relocs, in write.c:adjust_reloc_syms,
arm_fix_adjustable in tc-arm.c for coff is too restrictive:

#ifdef OBJ_COFF
arm_fix_adjustable (fixS * fixP)

   /* This is a little hack to help the gas/arm/adrl.s test.  It prevents
      local labels from being added to the output symbol table when they
      are used with the ADRL pseudo op.  The ADRL relocation should always
      be resolved before the binbary is emitted, so it is safe to say that
      it is adjustable.  */
   if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
     return 1;

   /* This is a hack for the gas/all/redef2.s test.  This test causes 
      to be cloned, and without this test relocs would still be generated
      against the original, pre-cloned symbol.  Such symbols would not 
      in the symbol table however, and so a valid reloc could not be
      generated.  So check to see if the fixup is against a symbol which has
      been removed from the symbol chain, and if it is, then allow it to be
      adjusted into a reloc against a section symbol. */
   if (fixP->fx_addsy != NULL
       && ! S_IS_LOCAL (fixP->fx_addsy)
       && symbol_next (fixP->fx_addsy) == NULL
       && symbol_next (fixP->fx_addsy) == symbol_previous (fixP->fx_addsy))
     return 1;

   return 0;

If I disable those two hacks that return 1, and just return 0 always, I
don't see
the failures the comments mention, in arm-coff, arm-pe, arm-wince-pe,
and arm-epoc-pe, so presumably, something must have removed the need for
those hacks.

The elf version of arm_fix_adjustable takes the reverse approach. It
returns 1
for all but a few cases:

arm_fix_adjustable (fixS * fixP)
   if (fixP->fx_addsy == NULL)
     return 1;

   /* Preserve relocations against symbols with function type.  */
   if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
     return 0;

   if (THUMB_IS_FUNC (fixP->fx_addsy)
       && fixP->fx_subsy == NULL)
     return 0;

   /* We need the symbol name for the VTABLE entries.  */
   if (     fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
       || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
     return 0;

   /* Don't allow symbols to be discarded on GOT related relocs.     */
   if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
       || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
       || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
       || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
       || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
       || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
       || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
       || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
       || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
     return 0;

   /* Similarly for group relocations.  */
   if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
        && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
       || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
     return 0;

   return 1;

The attached proposed patch makes coff use the elf version too. I tested on
arm-coff, arm-pe, arm-wince-pe, arm-epoc-pe, and arm-none-eabi, and built a
ratter big app (c++) that uses dlls on wince with a fully rebuilt
arm-wince toolchain.
I don't use thumb, though.

No regressions showed up, and it fixes the problem of local labels
the symbol table. Eg, after patch applied:

$arm-unknown-coff-nm local_label.o
00000000 b .bss
00000000 d .data
00000000 t .text

I didn't wrap the got related relocs and the group relocation relocs
in OBJ_ELF, as I have the impression that binutils is moving in the
direction of moving away from conditionally compiled code to runtime checks.

The separate test for Windows CE, is because local labels are prefixed
with "."
like on elf (if my previous patch is committed), but the section symbols
are left
on the symbol table, unlike elf.

Please review and commit.

Pedro Alves


2006-10-22  Pedro Alves <pedro_alves@portugalmail.pt>

	* config/tc-arm.c (arm_fix_adjustable) [OBJ_COFF]: Delete.
	(arm_fix_adjustable) [OBJ_ELF]: Use it on coff targets too.


2006-10-22  Pedro Alves <pedro_alves@portugalmail.pt>

	* gas/arm/local_label_coff.s: New test.
	* gas/arm/local_label_coff.d: New test.
	* gas/arm/local_label_elf.s: New test.
	* gas/arm/local_label_elf.d: New test.
	* gas/arm/local_label_wince.s: New test.
	* gas/arm/local_label_wince.d: New test.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gas.diff
URL: <https://sourceware.org/pipermail/binutils/attachments/20061023/c2659461/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: testsuite.diff
URL: <https://sourceware.org/pipermail/binutils/attachments/20061023/c2659461/attachment-0001.ksh>

More information about the Binutils mailing list