Bug 21809 - gas outputs data symbol markers "$d" in .debug_frame
Summary: gas outputs data symbol markers "$d" in .debug_frame
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-21 10:06 UTC by Mark Wielaard
Modified: 2017-07-24 10:37 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Proposed patch (605 bytes, patch)
2017-07-21 12:05 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Wielaard 2017-07-21 10:06:13 UTC
On arm and aarch64:

$ echo "int main() { return 1; }" | gcc -g -xc -
$ eu-readelf -S ./a.out | grep debug_frame
[31] .debug_frame         PROGBITS     00000000 0007c0 000030  0        0   0  4
$ eu-readelf -s ./a.out | grep '$d' | grep 31
   67: 00000010      0 NOTYPE  LOCAL  DEFAULT       31 $d

Note that theoretically it is allowed to have a data marker symbol at the start of the section if the whole section contains data. But it is redundant and optional. Also this symbol doesn't point to the start of the section but some way in.

This is caused by the use of frag_align () in gas/dw2gencfi.c.
It is similar to an issue fixed with .debug_aranges:

commit d025d5e5b57fb59c56aa4d57b7fc138720a8e454
Author: Mark Wielaard <mjw@redhat.com>
Date:   Sat Jun 13 17:47:41 2015 -0400

    gas: Don't use frag_align but use plain padding to align .debug_aranges.
    
    out_debug_aranges uses frag_align to make sure the addresses start
    out aligned. Using frag_align will call frag_var[_init], which will
    end up calling TC_FRAG_INIT. On arm and aarch64 TC_FRAG_INIT will
    generate a $d mapping symbol for the .debug_aranges to show that at
    that point a sequence of data items starts.
    
    Such a symbol pointing into a non-allocated debug section will confuse
    eu-strip -g. And it seems inefficient and wrong in general to have
    additional mapping symbols for debug sections, which won't contain
    actual code in the first place.
    
    Just keep track of the aranges header size and use plain padding to
    align the addresses which avoids generating any mapping symbols on
    aarch64 and arm.
    
    Includes a testcase for aarch64 that PASS with this patch and shows
    the extra $d mapping symbol in .debug_aranges before.
    
    gas/ChangeLog
    
           * dwarf2dbg.c (out_header): Document EXPR->X_add_number value,
           out_debug_aranges depends on it.
           (out_debug_aranges): Track size of header to properly pad header
           for address alignment.
    
    gas/testsuite/ChangeLog
    
           * gas/aarch64/dwarf.d: New.
           * gas/aarch64/dwarf.s: New.

It is however not as to remove all uses of frag_align () and replace them with simple padding in dw2gencfi.c.

It would best if aarch64_init_frag and arm_init_frag could be changed to not emit marker symbols if the frag is associated with a data only section (like SEC_DEBUGGING).
Comment 1 Nick Clifton 2017-07-21 12:05:38 UTC
Created attachment 10280 [details]
Proposed patch

Hi Mark,

  Something like this ?

  Please give it a try and let me know if it works for you.

Cheers
  Nick
Comment 2 Mark Wielaard 2017-07-21 15:22:28 UTC
(In reply to Nick Clifton from comment #1)
> Created attachment 10280 [details]
>   Something like this ?
> 
>   Please give it a try and let me know if it works for you.

It seems to work on an armv7l setup. Haven't tested aarch64.
.debug_frame won't get any markers. eh_frame does get one.
But at least that one is at the start of the section
(which is allowed, though unnecessary).
Comment 3 Sourceware Commits 2017-07-24 10:34:17 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e8d84ca1b46f899b0b140fdd146fc7b14515267b

commit e8d84ca1b46f899b0b140fdd146fc7b14515267b
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Jul 24 11:32:57 2017 +0100

    Stop the generation of mapping symbols in the debug sections of ARM and AArch64 binaries.
    
    	PR 21809
    	* config/tc-aarch64.c (aarch64_init_frag): Do not set a mapping
    	state for frags in debug sections.
    	* config/tc-arm.c (arm_init_frag): Likewise.
Comment 4 Nick Clifton 2017-07-24 10:37:36 UTC
Hi Mark,

  OK - I have gone ahead and applied the patch.  If it turns out to be a
  problem for ARM debugging I can always revert it later.

Cheers
  Nick