From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id E5F0B3858C78 for ; Wed, 26 Jan 2022 15:35:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5F0B3858C78 Received: by mail-pg1-x52f.google.com with SMTP id p125so21432546pga.2 for ; Wed, 26 Jan 2022 07:35:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jXqEAprHnkrdJgD/oao5RWstbHCDNrPnuGepxWQfRLg=; b=nPcnwZ8YPlGbWW9JgQi3aLpwilFjGBOjtTw+3EmhDo7LlHbbJYpYm6KZBXSwG3y0jM A8KFHBHLyQLAPcI9pa1CQtFKgH0imeE5tiYEHJZ3shVkD2Z5tIyi8G8pimfjXOm2tDuA JvOAB8fnV3qFxpTSJBftb1Za5NGCDNSIzkTeIxO9qui03nV08L4l+NaVMjSMibihHO6K YI6G6h7PVdD8XBFS/VmHk3+B+qvBQj6pUVQICq1bouUaKkSO8TuW7UiBs8pE2nvJnhyU CDlXjGwstk0BG/ugEtGAN4nvwxksaGhoxeHd/bnJuxbpSMCU2GZr1UFIxn5hoi/k2bqU JtNg== X-Gm-Message-State: AOAM530Yqwq9v9dOyuMzNjWC4PPHmA5YKYbkK6Zayi6z6cJhTC/1+Dwp gZ2ZVojtmgikW0+3G5gaFQCrjocPHx6XRbyvcSM= X-Google-Smtp-Source: ABdhPJy8BqqEvTfyBPYIwU0zEr1tgimwHOhPXFaJjUQd7+KY3CZ2aQizIVmYjuzd9M8GGpgGmG2/QepEA1ncu8a9S6s= X-Received: by 2002:a62:b409:0:b0:4cb:79d0:aa28 with SMTP id h9-20020a62b409000000b004cb79d0aa28mr4115012pfn.43.1643211345748; Wed, 26 Jan 2022 07:35:45 -0800 (PST) MIME-Version: 1.0 References: <20220125170523.952874-1-adhemerval.zanella@linaro.org> <877damvmen.fsf@oldenburg.str.redhat.com> <4ff7e613-2f51-cd9f-1466-68388f6a2a3a@linaro.org> In-Reply-To: <4ff7e613-2f51-cd9f-1466-68388f6a2a3a@linaro.org> From: "H.J. Lu" Date: Wed, 26 Jan 2022 07:35:09 -0800 Message-ID: Subject: Re: [PATCH] elf: Replace tst-p_alignmod1-editX with a python script To: Adhemerval Zanella Cc: Florian Weimer , Adhemerval Zanella via Libc-alpha , "Carlos O'Donell" , Joseph Myers Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3028.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED 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 15:35:49 -0000 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 @@ -5,24 +5,24 @@ There are 11 program headers, starting a Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align - LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000d38 0x000d38 R 0x200000 - LOAD 0x200000 0x0000000000200000 0x0000000000200000 0x0004c5 0x0004c5 R E 0x200000 - LOAD 0x400000 0x0000000000400000 0x0000000000400000 0x000340 0x000340 R 0x200000 - LOAD 0x400340 0x0000000000600340 0x0000000000600340 0x1ffcc4 0x1ffcd8 RW 0x200000 - DYNAMIC 0x400360 0x0000000000600360 0x0000000000600360 0x0001e0 0x0001e0 RW 0x8 + LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0008c8 0x0008c8 R 0x100 + LOAD 0x000900 0x0000000000000900 0x0000000000000900 0x000115 0x000115 R E 0x100 + LOAD 0x000b00 0x0000000000000b00 0x0000000000000b00 0x000098 0x000098 R 0x100 + LOAD 0x000c18 0x0000000000000c18 0x0000000000000c18 0x000200 0x000208 RW 0x100 + DYNAMIC 0x000c30 0x0000000000000c30 0x0000000000000c30 0x0001b0 0x0001b0 RW 0x8 NOTE 0x0002a8 0x00000000000002a8 0x00000000000002a8 0x000050 0x000050 R 0x8 NOTE 0x0002f8 0x00000000000002f8 0x00000000000002f8 0x000044 0x000044 R 0x4 GNU_PROPERTY 0x0002a8 0x00000000000002a8 0x00000000000002a8 0x000050 0x000050 R 0x8 - GNU_EH_FRAME 0x400118 0x0000000000400118 0x0000000000400118 0x000074 0x000074 R 0x4 + GNU_EH_FRAME 0x000b00 0x0000000000000b00 0x0000000000000b00 0x000024 0x000024 R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10 - GNU_RELRO 0x400340 0x0000000000600340 0x0000000000600340 0x000cc0 0x000cc0 R 0x1 + GNU_RELRO 0x000c18 0x0000000000000c18 0x0000000000000c18 0x0001e8 0x0001e8 R 0x1 Section to Segment mapping: Segment Sections... - 00 .note.gnu.property .note.gnu.build-id .note.ABI-tag .hash .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt - 01 .init .plt .plt.got .plt.sec .text .fini - 02 .rodata .eh_frame_hdr .eh_frame - 03 .init_array .fini_array .data.rel.ro .dynamic .got .got.plt .data .bss + 00 .note.gnu.property .note.gnu.build-id .note.ABI-tag .hash .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn + 01 .init .plt .plt.got .text .fini + 02 .eh_frame_hdr .eh_frame + 03 .init_array .fini_array .data.rel.ro .dynamic .got .got.plt .bss 04 .dynamic 05 .note.gnu.property 06 .note.gnu.build-id .note.ABI-tag -- H.J.