Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp782186pxa; Wed, 19 Aug 2020 15:01:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyU0MJXIovtHbV8Ol9cPzIKKsohx9eRslEwlsh3KLbcwclCeg1h5nykLf0IRHW99uI4RNJl X-Received: by 2002:a17:906:6b87:: with SMTP id l7mr393305ejr.198.1597874481039; Wed, 19 Aug 2020 15:01:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597874481; cv=none; d=google.com; s=arc-20160816; b=eQHekWlhIKKMjca4uiJGMj7WZMy8tYIqGC4dPUZBpSbpFEIUhGYrhsqfklNrgoUzUl Jb9G7FKf2hMLPbpy4ucVGs3ZEsqunm5qTpY8ucyvA2is95SqIf1bT0BSbPUedQw546Ip s+QUIJVrpTw9yLwwH63mnuiQ2vLz+pqQTXh6gDfRctaTXBX4naqBFg+yjfVECgCCxCnl wg9EVzC4KxvAp5whaWvajlwTuwHYrJQVCR7g2h5+npdsrF4QwQ/EM8/7ymnbgFE5X+rP ZhIPjuzxG80wcXBhILOfZKfPmHthxvZfIzPSQvieD29cLHXuOjR7dpZtghxVHN+HvYRP RMxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to:date :cc:to:from:subject:message-id; bh=xwD3ExbHRnxQ5IJykbpBHeR6MS7K8Sbn8Nv9xLSz1s4=; b=Q1uZiU4JJaGOjiT5pDm39/8UmyWD++Co2RVquOABuA1z422qX9+e4uyOaRNmMA0R+/ 6azqLk83PH13LY7gAar2vOhTTslHBBy5Yo4r7q/0nFf2O3c92IROuwf5mWV8bXD2IH+y u2pFTC8fo/przkS0SWQ4cifCPjaWAOfFNUtwl5V8I8c86zL3K70INinVQS4H/u9Wy/PE HD3BEhuaMkIpWLDVI6XJbQ4k7KR/8huPrYka7Rn6mBu2UnREMyv2GP0S4jv9n1jY9mNN E7rfW0M+L7eeJueQ68Mj8qAucPy0qWlYxnT1jZWdcHKroZONm8S6P1Z3GODl5zrmlLUi aEOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v4si174857edl.506.2020.08.19.15.00.56; Wed, 19 Aug 2020 15:01:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727780AbgHSWAP (ORCPT + 99 others); Wed, 19 Aug 2020 18:00:15 -0400 Received: from wildebeest.demon.nl ([212.238.236.112]:53276 "EHLO gnu.wildebeest.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbgHSWAM (ORCPT ); Wed, 19 Aug 2020 18:00:12 -0400 Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id D94B4300D92B; Thu, 20 Aug 2020 00:00:09 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id BEF6E413CE8D; Thu, 20 Aug 2020 00:00:09 +0200 (CEST) Message-ID: Subject: Re: Kernel build error on BTFIDS vmlinux From: Mark Wielaard To: Jiri Olsa , Nick Clifton Cc: Jesper Dangaard Brouer , "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , sdf@google.com, andriin@fb.com Date: Thu, 20 Aug 2020 00:00:09 +0200 In-Reply-To: <20200819171820.GG177896@krava> References: <20200818105555.51fc6d62@carbon> <20200818091404.GB177896@krava> <20200818105602.GC177896@krava> <20200818134543.GD177896@krava> <20200818183318.2c3fe4a2@carbon> <0ddf7bc5-be05-cc06-05d7-2778c53d023b@redhat.com> <20200819171820.GG177896@krava> Content-Type: multipart/mixed; boundary="=-zSplKr7l+VSXfgLRPXF8" X-Mailer: Evolution 3.28.5 (3.28.5-8.el7) Mime-Version: 1.0 X-Spam-Flag: NO X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on gnu.wildebeest.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-zSplKr7l+VSXfgLRPXF8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, On Wed, 2020-08-19 at 19:18 +0200, Jiri Olsa wrote: > On Wed, Aug 19, 2020 at 04:34:30PM +0100, Nick Clifton wrote: > > > So it would be nice if binutils ld could also be fixed to write out > > > compressed sections with the correct alignment. > >=20 > > OK, I will look into doing this. > >=20 > > By any chance is there a small test case that you are using to check > > this behaviour ? If so, please may I have a copy for myself ? >=20 > so when I take empty object and compile like: >=20 > $ echo 'int main(int argc, char **argv) { return 0; }' | gcc -c -o ex.o= -g -gz=3Dzlib -x c - > $ ld -o ex --compress-debug-sections=3Dzlib ex.o >=20 > then there's .debug_info section that shows sh_addralign =3D 1 Specifically, if you extend the example code a bit so that it has a couple more interesting compressed .debug sections (like in an vmlinux image) you'll see, eu-readelf -Sz: Section Headers: [Nr] Name Type Addr Off Size E= S Flags Lk Inf Al [Compression Size Al] [37] .debug_aranges PROGBITS 0000000000000000 027ae9f0 0000b274 = 0 C 0 0 16 [ELF ZLIB (1) 00028030 16] [38] .debug_info PROGBITS 0000000000000000 027b9c64 07b1fc3d = 0 C 0 0 1 [ELF ZLIB (1) 0cb137ad 1] [39] .debug_abbrev PROGBITS 0000000000000000 0a2d98a1 00119647 = 0 C 0 0 1 [ELF ZLIB (1) 0060811f 1] [40] .debug_line PROGBITS 0000000000000000 0a3f2ee8 007086ba = 0 C 0 0 1 [ELF ZLIB (1) 01557659 1] [41] .debug_frame PROGBITS 0000000000000000 0aafb5a8 000ab7ff = 0 C 0 0 8 [ELF ZLIB (1) 002a6bf8 8] [42] .debug_str PROGBITS 0000000000000000 0aba6da7 000f86e3 = 1 MSC 0 0 1 [ELF ZLIB (1) 003a8a8e 1] [43] .debug_loc PROGBITS 0000000000000000 0ac9f48a 002e12bd = 0 C 0 0 1 [ELF ZLIB (1) 00e0c448 1] [44] .debug_ranges PROGBITS 0000000000000000 0af80750 001a9ec7 = 0 C 0 0 16 [ELF ZLIB (1) 00e84b20 16] Note that the sh_addralign of the sections is set to the same valie as ch_addralign. That is the alignment of the decompressed data, what sh_addralign would have been if it wasn't a compressed section. The sh_addralign of a compressed section however should be equal to alignment for the datastructure inside it, either 4, for 32bit: typedef struct { Elf32_Word ch_type; /* Compression format. */ Elf32_Word ch_size; /* Uncompressed data size. */ Elf32_Word ch_addralign; /* Uncompressed data alignment. */ } Elf32_Chdr; or 8, for 64bit: typedef struct { Elf64_Word ch_type; /* Compression format. */ Elf64_Word ch_reserved; Elf64_Xword ch_size; /* Uncompressed data size. */ Elf64_Xword ch_addralign; /* Uncompressed data alignment. */ } Elf64_Chdr; At least, that is what elfutils libelf expects. And which I believe is what the ELF spec implies when it says: The sh_size and sh_addralign fields of the section header for a compressed section reflect the requirements of the compressed section. The ch_size and ch_addralign fields in the compression header provide the corresponding values for the uncompressed data, thereby supplying the values that sh_size and sh_addralign would have had if the section had not been compressed. > after I open the 'ex' obejct with elf_begin and iterate sections >=20 > according to Mark that should be 8 (on 64 bits) >=20 > when I change it to 8, the elf_update call won't fail for me > on that elf file Right, I have a patch that fixes it up in libelf, see attached. That should make things work without needing a workaround. But of course I just posted it and it isn't even upstream yet. So for now the workaround will be needed and it would be nice if binutils ld could also be fixed to set the sh_addralign field correctly. Cheers, Mark --=-zSplKr7l+VSXfgLRPXF8 Content-Disposition: attachment; filename*0=0001-libelf-Fixup-SHF_COMPRESSED-sh_addralign-in-elf_upda.pat; filename*1=ch Content-Type: text/x-patch; name="0001-libelf-Fixup-SHF_COMPRESSED-sh_addralign-in-elf_upda.patch"; charset="UTF-8" Content-Transfer-Encoding: base64 RnJvbSA1NWM1YzlhNTY4ZWQ3MDdiY2VhMTM4OGJmM2E1MjUyMTJkOGNmNGI4IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBNYXJrIFdpZWxhYXJkIDxtYXJrQGtsb21wLm9yZz4KRGF0ZTog V2VkLCAxOSBBdWcgMjAyMCAyMzo0MToyNCArMDIwMApTdWJqZWN0OiBbUEFUQ0hdIGxpYmVsZjog Rml4dXAgU0hGX0NPTVBSRVNTRUQgc2hfYWRkcmFsaWduIGluIGVsZl91cGRhdGUgaWYKIG5lY2Vz c2FyeS4KCkluIGVsZl9nZXRkYXRhLmMgd2UgaGF2ZSB0aGUgZm9sbG93aW5nIHRvIGNvbXBlbnNh dGUgZm9yIHBvc3NpYmx5CmJhZCBzaF9hZGRyYWxpZ24gdmFsdWVzIG9mIGNvbXByZXNzZWQgc2Vj dGlvbnM6CgogICAgICAvKiBDb21wcmVzc2VkIGRhdGEgaGFzIGEgaGVhZGVyLCBidXQgdGhlbiBj b21wcmVzc2VkIGRhdGEuCiAgICAgICAgIE1ha2Ugc3VyZSB0byBzZXQgdGhlIGFsaWdubWVudCBv ZiB0aGUgaGVhZGVyIGV4cGxpY2l0bHksCiAgICAgICAgIGRvbid0IHRydXN0IHRoZSBmaWxlIGFs aWdubWVudCBmb3IgdGhlIHNlY3Rpb24sIGl0IGlzCiAgICAgICAgIG9mdGVuIHdyb25nLiAgKi8K ICAgICAgaWYgKChmbGFncyAmIFNIRl9DT01QUkVTU0VEKSAhPSAwKQogICAgICAgIHsKICAgICAg ICAgIGVudHNpemUgPSAxOw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