From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5585 invoked by alias); 2 Apr 2019 20:17:23 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 5558 invoked by uid 89); 2 Apr 2019 20:17:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: NAM03-BY2-obe.outbound.protection.outlook.com Received: from mail-eopbgr780102.outbound.protection.outlook.com (HELO NAM03-BY2-obe.outbound.protection.outlook.com) (40.107.78.102) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 02 Apr 2019 20:17:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavesemi.onmicrosoft.com; s=selector1-wavecomp-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NTLi3jTEdDj8qzhPyFftIG2OQddmnsIXBhrgpUlW7Zw=; b=METpwyLHD57C3VDRRlB3ZtKmfEhYi/RGvzYL68neyn31MGLOOG09VBRqhcAXQc92are9iAKGoFdM/ChquFMc91GzNQkSpRts3hcrhW7yd56DrxoqP0v9lU33NpCmUJYuDE/OUff/I0Jqlj7h5/L14NoeydyOtQ5vegleO/Xi3p4= Received: from DM5PR22MB0683.namprd22.prod.outlook.com (10.172.190.23) by DM5PR22MB0409.namprd22.prod.outlook.com (10.173.175.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.15; Tue, 2 Apr 2019 20:17:16 +0000 Received: from DM5PR22MB0683.namprd22.prod.outlook.com ([fe80::b8c2:1185:8761:efde]) by DM5PR22MB0683.namprd22.prod.outlook.com ([fe80::b8c2:1185:8761:efde%10]) with mapi id 15.20.1750.014; Tue, 2 Apr 2019 20:17:16 +0000 From: Faraz Shahbazker To: "nickc@redhat.com" , "binutils@sourceware.org" CC: Faraz Shahbazker Subject: [PATCH v3] ld: Add --no-print-map-discarded option Date: Tue, 02 Apr 2019 20:17:00 -0000 Message-ID: <20190402201735.285064-1-fshahbazker@wavecomp.com> References: <1532707360-31871-1-git-send-email-fshahbazker@wavecomp.com> <8360927c-2020-05a9-7c96-0682f0aa812d@redhat.com> In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=fshahbazker@wavecomp.com; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-SW-Source: 2019-04/txt/msg00009.txt.bz2 Add a new option to disable the listing of discarded sections in map file output. The use case stems from a large application built with -ffunction-sections --gc-sections where the list of discarded sections blows up the map file output. The default behaviour remains to print discarded sections, but the new option allows us to disable it. ld/ * NEWS: Mention new option --no-print-map-discarded. * ld.h (ld_config_type) : New field. * ldlang.c (lang_map): Conditionally output discarded sections in map files based on configuration option. * ldlex.h (option_values) : New. * ldmain.c (main): Enabled print_map_discarded by default. * lexsup.c (ld_options): Add new command-line options. (parse_args) : New cases. * ld.texi: Document new options. * testsuite/ld-gc/gc.exp: Add new test. * testsuite/ld-gc/skip-map-discarded.s: New file. * testsuite/ld-gc/skip-map-discarded.d: New file. * testsuite/ld-gc/skip-map-discarded.map: New file. --- This is corrected version 3 of a patch posted for review few months back, but not committed due to pending copyright assignment. Somehow managed to reverse the previous version before posting. ld/NEWS | 2 ++ ld/ld.h | 3 +++ ld/ld.texi | 8 ++++++++ ld/ldlang.c | 25 +++++++++++++------------ ld/ldlex.h | 2 ++ ld/ldmain.c | 1 + ld/lexsup.c | 14 ++++++++++++++ ld/testsuite/ld-gc/gc.exp | 2 ++ ld/testsuite/ld-gc/skip-map-discarded.d | 3 +++ ld/testsuite/ld-gc/skip-map-discarded.map | 5 +++++ ld/testsuite/ld-gc/skip-map-discarded.s | 5 +++++ 11 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 ld/testsuite/ld-gc/skip-map-discarded.d create mode 100644 ld/testsuite/ld-gc/skip-map-discarded.map create mode 100644 ld/testsuite/ld-gc/skip-map-discarded.s diff --git a/ld/NEWS b/ld/NEWS index 597845a..de2cd16 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -1,5 +1,7 @@ -*- text -*- =20 +* Add command-line option --no-print-map-discarded. + Changes in 2.33: =20 * Add target handlers for AArch64 for ELF GNU program properties. diff --git a/ld/ld.h b/ld/ld.h index b97d977..55078a9 100644 --- a/ld/ld.h +++ b/ld/ld.h @@ -318,6 +318,9 @@ typedef struct =20 /* The common page size for ELF. */ bfd_vma commonpagesize; + + /* If set, print discarded sections in map file output. */ + bfd_boolean print_map_discarded; } ld_config_type; =20 extern ld_config_type config; diff --git a/ld/ld.texi b/ld/ld.texi index 0bcbec4..d88bdb4 100644 --- a/ld/ld.texi +++ b/ld/ld.texi @@ -783,6 +783,14 @@ when merging properties in @file{foo.o}, whose 0xc001= 0001 property value is 0x1, and @file{bar.o}, whose 0xc0010001 property value is 0x1. @end itemize =20 +@cindex link map discarded +@kindex --print-map-discarded +@kindex --no-print-map-discarded +@item --print-map-discarded +@itemx --no-print-map-discarded +Print (or do not print) the list of discarded and garbage collected sectio= ns +in the link map. Enabled by default. + @kindex -n @cindex read-only text @cindex NMAGIC diff --git a/ld/ldlang.c b/ld/ldlang.c index 1952d4a..898735e 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -2251,19 +2251,20 @@ lang_map (void) || file->flags.just_syms) continue; =20 - for (s =3D file->the_bfd->sections; s !=3D NULL; s =3D s->next) - if ((s->output_section =3D=3D NULL - || s->output_section->owner !=3D link_info.output_bfd) - && (s->flags & (SEC_LINKER_CREATED | SEC_KEEP)) =3D=3D 0) - { - if (!dis_header_printed) - { - fprintf (config.map_file, _("\nDiscarded input sections\n\n")); - dis_header_printed =3D TRUE; - } + if (config.print_map_discarded) + for (s =3D file->the_bfd->sections; s !=3D NULL; s =3D s->next) + if ((s->output_section =3D=3D NULL + || s->output_section->owner !=3D link_info.output_bfd) + && (s->flags & (SEC_LINKER_CREATED | SEC_KEEP)) =3D=3D 0) + { + if (! dis_header_printed) + { + fprintf (config.map_file, _("\nDiscarded input sections\n\n")); + dis_header_printed =3D TRUE; + } =20 - print_input_section (s, TRUE); - } + print_input_section (s, TRUE); + } } =20 minfo (_("\nMemory Configuration\n\n")); diff --git a/ld/ldlex.h b/ld/ldlex.h index 32853de..32a7a64 100644 --- a/ld/ldlex.h +++ b/ld/ldlex.h @@ -148,6 +148,8 @@ enum option_values OPTION_REQUIRE_DEFINED_SYMBOL, OPTION_ORPHAN_HANDLING, OPTION_FORCE_GROUP_ALLOCATION, + OPTION_PRINT_MAP_DISCARDED, + OPTION_NO_PRINT_MAP_DISCARDED, }; =20 /* The initial parser states. */ diff --git a/ld/ldmain.c b/ld/ldmain.c index 77cdbd0..da1c6a7 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -264,6 +264,7 @@ main (int argc, char **argv) config.make_executable =3D TRUE; config.magic_demand_paged =3D TRUE; config.text_read_only =3D TRUE; + config.print_map_discarded =3D TRUE; link_info.disable_target_specific_optimizations =3D -1; =20 command_line.warn_mismatch =3D TRUE; diff --git a/ld/lexsup.c b/ld/lexsup.c index 88e85c7..dacb962 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -543,6 +543,12 @@ static const struct ld_option ld_options[] =3D { {"orphan-handling", required_argument, NULL, OPTION_ORPHAN_HANDLING}, '\0', N_("=3DMODE"), N_("Control how orphan sections are handled."), TWO_DASHES }, + { {"print-map-discarded", no_argument, NULL, OPTION_PRINT_MAP_DISCARDED}, + '\0', NULL, N_("Show discarded sections in map file output (default)"), + TWO_DASHES }, + { {"no-print-map-discarded", no_argument, NULL, OPTION_NO_PRINT_MAP_DISC= ARDED}, + '\0', NULL, N_("Do not show discarded sections in map file output"), + TWO_DASHES }, }; =20 #define OPTION_COUNT ARRAY_SIZE (ld_options) @@ -1577,6 +1583,14 @@ parse_args (unsigned argc, char **argv) einfo (_("%F%P: invalid argument to option" " \"--orphan-handling\"\n")); break; + + case OPTION_NO_PRINT_MAP_DISCARDED: + config.print_map_discarded =3D FALSE; + break; + + case OPTION_PRINT_MAP_DISCARDED: + config.print_map_discarded =3D TRUE; + break; } } =20 diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp index 536356c..13968cc 100644 --- a/ld/testsuite/ld-gc/gc.exp +++ b/ld/testsuite/ld-gc/gc.exp @@ -171,3 +171,5 @@ if { [is_elf_format] && [check_shared_lib_support] \ ] run_dump_test "pr20306" } + +run_dump_test "skip-map-discarded" diff --git a/ld/testsuite/ld-gc/skip-map-discarded.d b/ld/testsuite/ld-gc/s= kip-map-discarded.d new file mode 100644 index 0000000..2e79f0b --- /dev/null +++ b/ld/testsuite/ld-gc/skip-map-discarded.d @@ -0,0 +1,3 @@ +#name: Check --no-print-map-discarded linker option +#ld: -e 0 --gc-sections --no-print-map-discarded +#map: skip-map-discarded.map diff --git a/ld/testsuite/ld-gc/skip-map-discarded.map b/ld/testsuite/ld-gc= /skip-map-discarded.map new file mode 100644 index 0000000..ca4818e --- /dev/null +++ b/ld/testsuite/ld-gc/skip-map-discarded.map @@ -0,0 +1,5 @@ +#failif +Discarded input sections +#... + _foo.* +#... diff --git a/ld/testsuite/ld-gc/skip-map-discarded.s b/ld/testsuite/ld-gc/s= kip-map-discarded.s new file mode 100644 index 0000000..630aab0 --- /dev/null +++ b/ld/testsuite/ld-gc/skip-map-discarded.s @@ -0,0 +1,5 @@ +.globl __start +__start: + .section _foo +foo: + .long 1 --=20 2.9.5