]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld: do not produce one empty output .ctf section for every input .ctf
authorNick Alcock <nick.alcock@oracle.com>
Thu, 11 Jun 2020 19:19:07 +0000 (20:19 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Wed, 22 Jul 2020 17:05:32 +0000 (18:05 +0100)
The trick we use to prevent ld doing as it does for almost all other
sections and copying the input CTF section into the output has recently
broken, causing output to be produced with a valid CTF section followed
by massive numbers of CTF sections, one per .ctf in the input (minus
one, for the one that was filled out by ctf_link).  Their size is being
forcibly set to zero, but they're still present, wasting space and
looking ridiculous.

This is not right:

ld/ld-new  :
section                     size      addr
.interp                       28   4194984
[...]
.bss                       21840   6788544
.comment                      92         0
.ctf                       87242         0
.ctf                           0         0
.ctf                           0         0
[snip 131 more empty sections]
.gnu.build.attributes       7704   6818576
.debug_aranges              6592         0
.debug_info              4488859         0
.debug_abbrev             150099         0
.debug_line               796759         0
.debug_str                237926         0
.debug_loc               2247302         0
.debug_ranges             237920         0
Total                   10865285

The fix is to exclude these unwanted input sections from being present
in the output.  We tried this before and it broke things, because if you
exclude all the .ctf sections there isn't going to be one in the output
so there is nowhere to put the deduplicated CTF. The solution to that is
really simple: set SEC_EXCLUDE on *all but one* CTF section.  We don't
care which one (they're all the same once their size has been zeroed),
so just pick the first we see.

ld/
* ldlang.c (ldlang_open_ctf): Set SEC_EXCLUDE on all but the
first input .ctf section.

ld/ChangeLog
ld/ldlang.c

index bd0c6ccd688693c68d7d6e450bdc8d90f9b057d8..c0f6eca4f62afb8b74b2ee16965fd54bb71e2b45 100644 (file)
@@ -1,3 +1,8 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ldlang.c (ldlang_open_ctf): Set SEC_EXCLUDE on all but the
+       first input .ctf section.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        * configure.ac (enable_libctf): Substitute it.
index bf29144330d5249b4a5cb16b8e6cf66247201ffa..6943adfdc31a60a5b881ae5ee46b02d9693ecc5d 100644 (file)
@@ -3700,12 +3700,15 @@ ldlang_open_ctf (void)
        }
 
       /* Prevent the contents of this section from being written, while
-        requiring the section itself to be duplicated in the output.  */
+        requiring the section itself to be duplicated in the output, but only
+        once.  */
       /* This section must exist if ctf_bfdopen() succeeded.  */
       sect = bfd_get_section_by_name (file->the_bfd, ".ctf");
       sect->size = 0;
       sect->flags |= SEC_NEVER_LOAD | SEC_HAS_CONTENTS | SEC_LINKER_CREATED;
 
+      if (any_ctf)
+       sect->flags |= SEC_EXCLUDE;
       any_ctf = 1;
     }