From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2049.outbound.protection.outlook.com [40.92.42.49]) by sourceware.org (Postfix) with ESMTPS id 96C523858D1E for ; Sat, 6 Jan 2024 06:55:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 96C523858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=maskray.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=maskray.me ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 96C523858D1E Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.92.42.49 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1704524119; cv=pass; b=FJTr6ifsM8gg6KsswklUVp6FKNGSIZfB5hXu0QY7NHIBsSwkhaXOsQxphrgePXoM3ldqJXz2jih8jzIioh5ATcYHP2siLJ2YKJnkz7dLTbesXiCI1gUDD8bsi7Qr+l36uaHrIyispEZz0C1+f9pPZkKRLHo9VrXjN5XSTNRPBok= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1704524119; c=relaxed/simple; bh=xIvlUdTl5wIiuOKoAZZYVcewvkgliAFejiDKcXu7EOE=; h=From:Date:Message-ID:Subject:To:MIME-Version; b=cqfC1qDiDtvQ/AarNnR9n5n1V/CXSIOAzaD0aw2TqEX0xcbU4E5lOzfqfI9tUM4csda7o/ExN6GwBQpYv5WQiRODVQTSglZuXd3e5I1B+n/yrfj1G324xVbojwkPeUa1QJ7B6A8PNs8YIiFIyAVKua69D4W7JQ2fUR0Jm8YGttQ= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MabhIIGhvyRZ1FLAGyrNy+CjATfEpS5vCpbf9On2QKacKAkXgySbYko6zUL4ivVq5egzUwzCCabb+B9W+3PFWwoCd1re4J9K5OD4ukjux/36MAulhYiNj8iYZKz3OzGmjE83oFFkCvNIMPWQ3rc7EBuquj9C67FuXKw6snxgOSSBwRxQBalm+0QjOAUibKc7XgpyQ3vD3FiBOxUSkN7o5nbCm7J4lbmzN5/LjAIdvlVH2M5/dAmsub6SdjjwW36Q0CvAv0+L3d3MLPLHTnR/tr2J4mZnoqeq3kiBxbFgoYW9f3VNkShcIbq+tTyWCh9Gbr6frz+OBUSmSA1lzzLY3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2z2VE1MyOlElJzS/QKhJxs6G7J1fpajstef5PTuGbnY=; b=GFEalVQFjz9dbLxs4NHYwYp4QHH2ITjOD+5SzKB7GR8K028dcLp1dFNn3RR1d3pRC83tA3sl7YvnocSZXmsv7ZzgCS3YXOG7hQfEdPssx92Szd7fjNObeZqBwzQk69DMXaBU2ZSXqSEm2Jt8POskG4rPayEcznc9RRc8dLu8UX/kuL7CvMsTJuka/TMJazUA8C2kAUlhrSbb0GGINnmK4WzQ71tWhoh4QabN5yQD7O4ln0/vS6szNS8Brg2WCdXUW9VaIZgA7eoljYdMVm0D9ZQqIsKoNzWPu9nRunEMoLgYCMv+IK6fGrf+BjEAf2TrdQA7OBcvKg9N+/rlnOXa7w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from DS7PR12MB5765.namprd12.prod.outlook.com (2603:10b6:8:74::19) by PH7PR12MB6857.namprd12.prod.outlook.com (2603:10b6:510:1af::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.17; Sat, 6 Jan 2024 06:55:13 +0000 Received: from DS7PR12MB5765.namprd12.prod.outlook.com ([fe80::fa25:6d58:7ae9:9c0b]) by DS7PR12MB5765.namprd12.prod.outlook.com ([fe80::fa25:6d58:7ae9:9c0b%5]) with mapi id 15.20.7159.015; Sat, 6 Jan 2024 06:55:13 +0000 X-Gm-Message-State: AOJu0YxbutPD2nePrwe5dkDI1x+wReRGbqUxeutCA6jKkrVay+UWTO4h qq8mna7Q66oXmqs1MPb28VejcNKF8NjX5yc8EpI= X-Google-Smtp-Source: AGHT+IGiGcjdV1M1gE9tZ3zjmky/Svv+j6mNlEqxcyDVuMFibQwnjS/hMQFlBx0AaGjm/WHaaQeJZDImlGR1yx8rjZ8= X-Received: by 2002:a05:6122:43:b0:4b6:c9fa:d8e0 with SMTP id q3-20020a056122004300b004b6c9fad8e0mr324928vkn.15.1704524111215; Fri, 05 Jan 2024 22:55:11 -0800 (PST) References: <6bed5ea7-c174-4ef5-a329-48a116d55d7e@redhat.com> In-Reply-To: <6bed5ea7-c174-4ef5-a329-48a116d55d7e@redhat.com> From: Fangrui Song Date: Fri, 5 Jan 2024 22:55:00 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Readelf section header printing alignment To: Pete Dietl Cc: binutils@sourceware.org, Nick Clifton Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-TMN: [c0+DkY0pCe1XKYm9+UHtX1xZvlRme0mi] X-ClientProxiedBy: BN9PR03CA0631.namprd03.prod.outlook.com (2603:10b6:408:13b::6) To DS7PR12MB5765.namprd12.prod.outlook.com (2603:10b6:8:74::19) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR12MB5765:EE_|PH7PR12MB6857:EE_ X-MS-Office365-Filtering-Correlation-Id: 37c4c8ac-6651-4908-7747-08dc0e846e1f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sMMmcpQT+k3ex7yjb0aUF4R8mb/NdFgiUYSh/fQYOL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rbmRhUDZlZ2dIbEpNei9aNUlFNTl1WlRzMm9YQnlR?= =?utf-8?B?MVJ5WGlTU1UxWjlHSGIrRTFrS25JSCszeWlsakl0c2pTTzhEQnZQb3hFRHdM?= =?utf-8?B?dWdEdXZDSGpYTzd3TTFkU3dvY0RtbE1Wc0dCeVZ2Qi9XcjZhSkFhR1VzaUta?= =?utf-8?B?VFVkU3pYR1pFTEFrUW03c0UxM1drZU9RcjdFQzlwbGE4d0FLdFh0MVZ3NlBT?= =?utf-8?B?R0ZWVUNnNkZWSXV2MVJwS0gwKy9TMEVWZTU2bkpZNHhDcWxiclVXTjYvTCtY?= =?utf-8?Q?d9CgsVVZSTtyxLbk0KeNN+Pxepzw6aJwsQg4kgVFEw3sA2?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-5183d.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 37c4c8ac-6651-4908-7747-08dc0e846e1f X-MS-Exchange-CrossTenant-AuthSource: DS7PR12MB5765.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2024 06:55:12.9614 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6857 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,KAM_INFOUSMEBIZ,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Jan 5, 2024 at 7:12=E2=80=AFAM Nick Clifton wrot= e: > > Hi Pete, > > > The section headers output from readelf with the '-W' option become ugl= y and > > unaligned when a section name is too long. > > Agreed. In hindsight it would have been better to emit the section name > as the last entry on the output line, rather than the second. > > If it helps you could try using the readelf program the elfutils project > (eu-readelf) as this appear to adjust the column positions to allow for > extra long section names. I think that this is a bad idea however as > it could end up looking very strange if just one section has an extremely > long section name. > > Changing the default output layout now would be a bad idea as there > are scripts and tools out there that depend upon the current behaviour. > > It would be possible however to add a new command line option which > would change the layout. Perhaps simply --section-name-at-end ? > Although this seems a bit, hmm, hackish. Or maybe: > > --section-listing-layout=3D[number,name,type,addr,off,size,flags,info,= align] > > Then this option could be used to just display the fields of interest > to the user, in the order that they want. So: > > --section-listing-layout=3Dtype,size,name > > would produce output like this: > > Section Headers: > Type Size Name > NULL 0 > PROGBITS 00000f .text > PROGBITS 000000 .data > NOBITS 000000 .bss > PROGBITS 00002c .comment > PROGBITS 000000 .note.GNU-stack > NOTE 000020 .note.gnu.property > > whereas: > > --section-listing-layout=3Dname,size > > would produce output like this: > > Section Headers: > Name Size > 0 > .text 00000f > .data 000000 > .bss 000000 > .comment 00002c > .note.GNU-stack 000000 > .note.gnu.property 000020 > > I am just theorizing however. I am not actually volunteering to write > the code. But, as they say, "patches welcome"... > > Cheers > Nick > > i think all of the cols can get unaligned if the content is bigger than t= he > allocated space. i wish it would autoalign/fix itself, at least when usi= ng > the -W option. Both eu-readelf and llvm-readelf simply ignore -W/--wide and do not implement the narrow output at all. Many folks like me always prefer -W since the narrow output for certain features has truncated output (e.g. -s output truncates the symbol name). If a tool reads readelf -W output and will be broken due to readelf -W changing the number of spaces, the tool is very likely broken dealing with the object file in the first place. To elaborate on what Mike mentioned, columns like (Flg,Lk,Inf,Al) have the length problem as well... Fixing it will make the code more complex, so perhaps we can recognize the problem and leave things as-is... Note: section warnings immediately follow the section row and precomputing the column size can easily change the output, though it probably doesn't matter. % readelf -S a32 There are 4 section headers, starting at offset 0x54: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk I= nf Al [ 0] NULL 00000000 000000 000000 00 0 = 0 0 readelf: Warning: [ 1]: Unexpected value (1) in info field. [ 1] .foo PROGBITS 00000002 000037 000003 06 WA 4 = 1 5 readelf: Warning: section 1: sh_link value of 4 is larger than the number of sections [ 2] .strtab STRTAB 00000000 00003a 000001 00 0 = 0 1 [ 3] .shstrtab STRTAB 00000000 00003b 000018 00 0 = 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), D (mbind), p (processor specific)