From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 58BA4386483B for ; Wed, 26 Jan 2022 17:11:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 58BA4386483B Received: by mail-oi1-x22e.google.com with SMTP id y23so743245oia.13 for ; Wed, 26 Jan 2022 09:11:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=csk4lSM22Qd0eYZ3WwzdsCopz6xvcdUcJF9lkTCn/IE=; b=kJYlSCfsvsoiIxn5ETPd/g4GPNisduW9QywE91EHjItRxYY4UnkwEZVsWJUzi+fCOI 45hWX6qaBBD8wastnuWWRPoyIYejSfLk8TqifeOOf36WXczH06lB+bkSaloNXQfH/4ZZ sKNsLWOiImNv3hbNtGs16102u2ceUfjMs7SXOOTpp89wCogG0gB8aUWkJ7w46/h0qCJe juxLTPKV1Rbg1Y3VjJNQF1YFnYNQbE0P6IuX5y74S3l6uIltlh7CXSFK/RhIMmTgcCx9 n/FkzvaPCQ7B20ylBuOOjNk3ehN5ZvZ3WmBt8qkU3KLYvFzF+QepOVn6rKysu389/uD1 WwGg== X-Gm-Message-State: AOAM532qzYr/DVay9qkWSykcLZXpFuujeaMK6oeOyqOLawswDoeRPQv9 1glrVqVptBfAWXCJqqnxmwqIdGeRTIlbCg== X-Google-Smtp-Source: ABdhPJwmT/t8pGez0sTFeSVe8hlIyL63BHzeQqtP/5Jh3robI0NBdZRABToRuirhxTrh3TZabZzEUw== X-Received: by 2002:a05:6808:2012:: with SMTP id q18mr4202264oiw.246.1643217109662; Wed, 26 Jan 2022 09:11:49 -0800 (PST) Received: from ?IPV6:2804:431:c7cb:27f8:9b70:219c:7964:43d? ([2804:431:c7cb:27f8:9b70:219c:7964:43d]) by smtp.gmail.com with ESMTPSA id n66sm7997805oif.35.2022.01.26.09.11.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Jan 2022 09:11:49 -0800 (PST) Message-ID: <6fbe227d-d1cf-884e-e233-b7a80df67a58@linaro.org> Date: Wed, 26 Jan 2022 14:11:46 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] elf: Replace tst-p_alignmod1-editX with a python script Content-Language: en-US To: "H.J. Lu" Cc: Florian Weimer , Adhemerval Zanella via Libc-alpha , Carlos O'Donell , Joseph Myers References: <20220125170523.952874-1-adhemerval.zanella@linaro.org> <877damvmen.fsf@oldenburg.str.redhat.com> <4ff7e613-2f51-cd9f-1466-68388f6a2a3a@linaro.org> <93520ad8-93d7-a29b-d145-467f3a913525@linaro.org> <38575072-69d4-872c-1397-84b65f840604@linaro.org> From: Adhemerval Zanella In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jan 2022 17:11:52 -0000 On 26/01/2022 13:11, H.J. Lu wrote: > On Wed, Jan 26, 2022 at 7:54 AM Adhemerval Zanella > wrote: >> >> >> >> On 26/01/2022 12:46, H.J. Lu wrote: >>> On Wed, Jan 26, 2022 at 7:45 AM Adhemerval Zanella >>> wrote: >>>> >>>> >>>> >>>> On 26/01/2022 12:35, H.J. Lu wrote: >>>>> On Wed, Jan 26, 2022 at 4:10 AM Adhemerval Zanella >>>>> wrote: >>>>>> >>>>>> >>>>>> >>>>>> On 26/01/2022 07:09, Florian Weimer wrote: >>>>>>> * Adhemerval Zanella via Libc-alpha: >>>>>>> >>>>>>>> diff --git a/scripts/tst-elf-edit.py b/scripts/tst-elf-edit.py >>>>>>>> new file mode 100644 >>>>>>>> index 0000000000..1fb9b8e0fe >>>>>>>> --- /dev/null >>>>>>>> +++ b/scripts/tst-elf-edit.py >>>>>>>> @@ -0,0 +1,206 @@ >>>>>>> >>>>>>>> +class Elf_Ehdr: >>>>>>>> + def __init__(self, e_ident): >>>>>>>> + endian, addr, off = elf_types_fmts(e_ident) >>>>>>>> + self.fmt = '{0}HHI{1}{2}{2}IHHHHHH'.format(endian, addr, off) >>>>>>>> + self.len = struct.calcsize(self.fmt) >>>>>>>> + >>>>>>>> + def read(self, f): >>>>>>>> + buf = f.read(self.len) >>>>>>>> + if not buf: >>>>>>>> + error('{}: header too small'.format(f.name)) >>>>>>> >>>>>>> I think you need to check len(buf) < self.len. >>>>>> >>>>>> Ack. >>>>>> >>>>>>> >>>>>>>> +class Elf_Phdr: >>>>>>>> + def __init__(self, e_ident): >>>>>>>> + endian, addr, off = elf_types_fmts(e_ident) >>>>>>>> + self.ei_class = e_ident[EI_CLASS] >>>>>>>> + if self.ei_class == ELFCLASS32: >>>>>>>> + self.fmt = '{0}I{2}{1}{1}IIII'.format(endian, addr, off) >>>>>>>> + else: >>>>>>>> + self.fmt = '{0}II{2}{1}{1}QQQ'.format(endian, addr, off) >>>>>>>> + self.len = struct.calcsize(self.fmt) >>>>>>>> + >>>>>>>> + def read(self, f): >>>>>>>> + buf = f.read(self.len) >>>>>>>> + if not buf: >>>>>>>> + error('{}: program header too small'.format(f.name)) >>>>>>> >>>>>>> Here as well. >>>>>> >>>>>> Ack. >>>>>> >>>>>>> >>>>>>> Rest looks okay. >>>>>> >>>>>> Thanks, I push it upstream with the above fixes installed. >>>>> >>>>> I got >>>>> >>>>> FAIL: elf/tst-p_align3 >>>>> >>>>> [hjl@gnu-tgl-2 build-x86_64-linux]$ cat elf/tst-p_align3.out >>>>> /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/tst-p_align3: >>>>> error while loading shared libraries: >>>>> /export/build/gnu/tools-build/glibc-cet-gitlab/build-x86_64-linux/elf/tst-p_alignmod3.so: >>>>> cannot change memory protections >>>>> [hjl@gnu-tgl-2 build-x86_64-linux]$ >>>>> >>>>> Only p_align should be changed to 0x100. But I saw >>>> >>>> I am not sure if this is related because tst-p_align3 and tst-alignmod3.so uses >>>> LDFLAGS instead: >>>> >>>> 1644 $(objpfx)tst-align3: $(objpfx)tst-alignmod3.so >>>> 1645 ifeq (yes,$(have-fpie)) >>>> 1646 CFLAGS-tst-align3.c += $(PIE-ccflag) >>>> 1647 endif >>>> 1648 LDFLAGS-tst-align3 += -Wl,-z,max-page-size=0x200000 >>>> 1649 LDFLAGS-tst-alignmod3.so += -Wl,-z,max-page-size=0x200000 >>>> 1650 $(objpfx)tst-alignmod3.so: $(libsupport) >>>> >>>> And the patch only changed the way tst-p_align1 and tst-p_align2 modules were >>>> changed. >>> >>> It is tst-p_alignmod3.so, not tst-alignmod3.so. >>> ^^ >> My confusion here. But even though the script in not involved: >> >> 2622 LDFLAGS-tst-p_alignmod3.so += -Wl,-z,max-page-size=0x100,-z,common-page-size=0x100 >> 2623 >> 2624 $(objpfx)tst-p_align3: $(objpfx)tst-p_alignmod3.so >> 2625 $(objpfx)tst-p_align3.out: tst-p_align3.sh $(objpfx)tst-p_align3 >> 2626 $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \ >> 2627 $(evaluate-test) >> >> That's why it is puzzling me that it start to fail now. > > This test checks the invalid p_align handling. You have to edit the > binary to change p_align to 0x100 which is invalid. > But it is already done by the LD_FLAGS above (from elf/Makefile). I am still failing to understand why my patch that only changes tst-p_align1 and tst-p_align2 objects made tst-p_align3 to fail. Before: $ readelf -l elf/tst-p_align3 [...] LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x00000000000015c0 0x00000000000015c0 R 0x1000 LOAD 0x0000000000002000 0x0000000000002000 0x0000000000002000 0x0000000000001892 0x0000000000001892 R E 0x1000 LOAD 0x0000000000004000 0x0000000000004000 0x0000000000004000 0x0000000000000d58 0x0000000000000d58 R 0x1000 LOAD 0x0000000000005cf8 0x0000000000006cf8 0x0000000000006cf8 0x0000000000000498 0x00000000000004d8 RW 0x1000 [...] $ readelf -l elf/tst-p_alignmod3.so [....] Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000540 0x0000000000000540 R 0x100 LOAD 0x0000000000000600 0x0000000000000600 0x0000000000000600 0x00000000000001f2 0x00000000000001f2 R E 0x100 LOAD 0x0000000000000800 0x0000000000000800 0x0000000000000800 0x00000000000000d0 0x00000000000000d0 R 0x100 LOAD 0x0000000000000930 0x0000000000000a30 0x0000000000000a30 0x00000000000001f8 0x0000000000000208 RW 0x100 After: $ readelf -l elf/tst-p_align3 [...] LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x00000000000015b8 0x00000000000015b8 R 0x1000 LOAD 0x0000000000002000 0x0000000000002000 0x0000000000002000 0x0000000000001892 0x0000000000001892 R E 0x1000 LOAD 0x0000000000004000 0x0000000000004000 0x0000000000004000 0x0000000000000d50 0x0000000000000d50 R 0x1000 LOAD 0x0000000000005cf8 0x0000000000006cf8 0x0000000000006cf8 0x0000000000000498 0x00000000000004d8 RW 0x1000 $ readelf -l elf/tst-p_alignmod3.so Elf file type is DYN (Shared object file) [....] Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000540 0x0000000000000540 R 0x100 LOAD 0x0000000000000600 0x0000000000000600 0x0000000000000600 0x00000000000001f2 0x00000000000001f2 R E 0x100 LOAD 0x0000000000000800 0x0000000000000800 0x0000000000000800 0x00000000000000d0 0x00000000000000d0 R 0x100 LOAD 0x0000000000000930 0x0000000000000a30 0x0000000000000a30 0x00000000000001f8 0x0000000000000208 RW 0x100 So PT_LOAD p_align are still strictly the same.