From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) by sourceware.org (Postfix) with ESMTPS id 4E7693857726 for ; Wed, 27 Sep 2023 17:18:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E7693857726 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-59bbdb435bfso143243127b3.3 for ; Wed, 27 Sep 2023 10:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695835088; x=1696439888; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=viLFo4oYpI2n1xsR+NLikqnQ73GMMwGfVdTbdnEBUlY=; b=P1LeM7wu3d2AGkrFOztml56MFnq7PEWVXf+sda/9zO2Y7Ar7GFfFAIlRI8uSbdDGuV c5wIaEpmJ7SxUZHOtQGlQsiBXPU3i04C3kX1vFT69WuaHa+ioMsvm6BVY7NbRfaRkYPR siU3Rl76ydVvBVWnMpHvzzg5vdZrEuEnpa64YPRW15GrAo1r8hUOyx2swh4etFwiVV7z O0ATK1m5s26sqfjoFJA9nsEHCQIDATMxHCjMNpDAhW9+3Y/A7uhK+uuj7WpBsCWPtJxd T22oI0N5bcOXZDbN2em9ywGegFXFbyR+HqOOobzAaJYKI+rkg0gxBLqrU+noqX5SJjBs 9kmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695835088; x=1696439888; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=viLFo4oYpI2n1xsR+NLikqnQ73GMMwGfVdTbdnEBUlY=; b=o7OH+Kx5TvovM2QsBR03rW6W/UJNoKnz2o9hlat+kmD2AUBpF7zmfvA50X++Th6gd0 nBCm2otT0QBQX0PjSVZRyvBvx5CUem/T3TQLtuBSnAT5glDHH5vosoeXtfh4l1N9kv64 5ZDQpnfkW7JbEfLEOfFczXIUrRWHkiEFul6ptcK+KU8bE/PGlZrP1cM/YOOEzxPw94a3 Z1tzwvqcAjySIMLcjoab0WeSpY8zz+I+3bDkXO3zFxMlB0fa+Z1yFFNNtdHMQM72BtB5 DTQq1fH86/NQRh5dwqnRUjDse9Os2Yw2Hz6ccdL9tgzi4I9EiNKdICk15NDBmhH8XZ6Y yEyw== X-Gm-Message-State: AOJu0YyTPqt4jXMU8/MQyPQYsGiwDHbBCA4pioqy7PMx+nPQzGVuM9Nb yd98BSyuss7caHgfl6IlmqVtN11GDXiGhwz353tGAU/mRns= X-Google-Smtp-Source: AGHT+IEKwiRFJPZzvcF2agfjrr+KoXeuq8noSPkLHyeQxPS6GsHaDyOSZaO1zS2KKNkKfVfhQ2K/LUAHmdfBGzwFRH8= X-Received: by 2002:a0d:cdc3:0:b0:589:db22:bfd6 with SMTP id p186-20020a0dcdc3000000b00589db22bfd6mr2944202ywd.40.1695835088608; Wed, 27 Sep 2023 10:18:08 -0700 (PDT) MIME-Version: 1.0 References: <20230926161354.312545-1-hjl.tools@gmail.com> <86209ea1-7ae7-b14a-3a26-c9454caf5c32@suse.com> In-Reply-To: <86209ea1-7ae7-b14a-3a26-c9454caf5c32@suse.com> From: "H.J. Lu" Date: Wed, 27 Sep 2023 10:17:32 -0700 Message-ID: Subject: Re: [PATCH] x86-64: Add -z mark-plt and -z nomark-plt To: Jan Beulich Cc: binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3015.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham 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 Tue, Sep 26, 2023 at 11:56=E2=80=AFPM Jan Beulich wr= ote: > > On 26.09.2023 18:13, H.J. Lu via Binutils wrote: > > The PLT entry in executables and shared libraries contains an indirect > > branch, like > > > > jmp *foo@GOTPCREL(%rip) > > push $index_foo > > jmp .PLT0 > > > > or > > > > endbr64 > > jmp *foo@GOTPCREL(%rip) > > NOP padding > > > > which is used to branch to the function, foo, defined in another object= . > > Each R_X86_64_JUMP_SLOT relocation has a corresponding PLT entry. > > > > The dynamic tags have been added to the x86-64 psABI to mark such PLT > > entries: > > > > https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/6d824a52a42d173eb838b= 879616c1be5870b593e > > > > Add an x86-64 linker option, -z mark-plt, to mark PLT entries with > > > > #define DT_X86_64_PLT (DT_LOPROC + 0) > > #define DT_X86_64_PLTSZ (DT_LOPROC + 1) > > #define DT_X86_64_PLTENT (DT_LOPROC + 3) > > > > 1. DT_X86_64_PLT: The address of the procedure linkage table. > > 2. DT_X86_64_PLTSZ: The total size, in bytes, of the procedure linkage > > table. > > 3. DT_X86_64_PLTENT: The size, in bytes, of a procedure linkage table > > entry. > > > > and set the r_addend field of the R_X86_64_JUMP_SLOT relocation to the > > memory offset of the indirect branch instruction. The dynamic linker > > can use these tags to update the PLT section to direct branch. > > > > bfd/ > > > > * elf-linker-x86.h (elf_linker_x86_params): Add mark_plt. > > * elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Set the > > r_addend of R_X86_64_JUMP_SLOT to the indirect branch offset > > in PLT entry for -z mark-plt. > > * elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Add > > DT_X86_64_PLT, DT_X86_64_PLTSZ and DT_X86_64_PLTENT for > > -z mark-plt. > > (_bfd_x86_elf_finish_dynamic_sections): Set DT_X86_64_PLT, > > DT_X86_64_PLTSZ and DT_X86_64_PLTENT. > > (_bfd_x86_elf_get_synthetic_symtab): Ignore addend for > > JUMP_SLOT relocation. > > (_bfd_x86_elf_link_setup_gnu_properties): Set > > plt_indirect_branch_offset. > > * elfxx-x86.h (elf_x86_plt_layout): Add plt_indirect_branch_offse= t. > > > > binutils/ > > > > * readelf.c (get_x86_64_dynamic_type): New function. > > (get_dynamic_type): Call get_x86_64_dynamic_type. > > > > include/ > > > > * elf/x86-64.h (DT_X86_64_PLT): New. > > (DT_X86_64_PLTSZ): Likewise. > > (DT_X86_64_PLTENT): Likewise. > > > > ld/ > > * emulparams/elf32_x86_64.sh: Source x86-64-plt.sh. > > * emulparams/elf_x86_64.sh: Likewise. > > * emulparams/x86-64-plt.sh: New file. > > * testsuite/ld-x86-64/mark-plt-1.s: Likewise. > > * testsuite/ld-x86-64/mark-plt-1a-x32.d: Likewise. > > * testsuite/ld-x86-64/mark-plt-1a.d: Likewise. > > * testsuite/ld-x86-64/mark-plt-1b-x32.d: Likewise. > > * testsuite/ld-x86-64/mark-plt-1b.d: Likewise. > > * testsuite/ld-x86-64/mark-plt-1c-x32.d: Likewise. > > * testsuite/ld-x86-64/mark-plt-1c.d: Likewise. > > * testsuite/ld-x86-64/mark-plt-1d-x32.d: Likewise. > > * testsuite/ld-x86-64/mark-plt-1d.d: Likewise. > > * testsuite/ld-x86-64/x86-64.exp: Run -z mark-plt tests. > > Don't you also want to add text to ld.texi? There it would also be made Will fix it in v2. > clear what the default setting is ("off" aiui). A related question would > be whether it would make sense to allow configure time selection of the > default. > Since glibc versions without commit f8587a61892cbafd98ce599131bf4f103466f084 Author: H.J. Lu Date: Fri May 20 19:21:48 2022 -0700 x86-64: Ignore r_addend for R_X86_64_GLOB_DAT/R_X86_64_JUMP_SLOT According to x86-64 psABI, r_addend should be ignored for R_X86_64_GLOB= _DAT and R_X86_64_JUMP_SLOT. Since linkers always set their r_addends to 0,= we can ignore their r_addends. Reviewed-by: Fangrui Song won't ignore the r_addend value in the R_X86_64_JUMP_SLOT relocation. making -z mark-plt the default may cause run-time issues for older versions of glibc. --=20 H.J.