From patchwork Thu Feb 3 18:09:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 50744 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 227F83858410 for ; Thu, 3 Feb 2022 18:10:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 227F83858410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643911813; bh=I91tfO0BhdGmw0r5huhdoSSEz/N9gMLajrtcFgoi0Ms=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=pDl2f6K+EBj2Vi5RWU4nN5B5HamKwkgWcAXvTjDsbdNMaCK+JQLj6Jp7/Zm+h8lrJ uybZsczeBRYGVcdlzWNzVyQuO12flkfHi4zBsdOgJomG0nAlShjSBBb/bLe5gwM4KQ PZj4LAGe8xw/0UzUxnHTmYDx7nvEjC6Vey0y9wcs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id 7EBE63858D35 for ; Thu, 3 Feb 2022 18:09:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7EBE63858D35 Received: by mail-pj1-x1030.google.com with SMTP id h12so3162498pjq.3 for ; Thu, 03 Feb 2022 10:09:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I91tfO0BhdGmw0r5huhdoSSEz/N9gMLajrtcFgoi0Ms=; b=K+Bz5+t3+nvsiTty8QRuHmxE16Tp3/YyNN3m3J4xq2cm28GGuCJgMAsImiImI6/vSp CC0iGMiKSPjBymxuaLpqPNAd5LVVIwerPLxoCjK6zLOg6N952ljfRG6mGEo/gyNbUet+ F3do0Y5Up7UViecdIkuqN+Kafj44r7OAvVl27sOppdEJvaf7rwI9Y5LCMLydaydFnds1 SoWBwiprgKFyfcbjdZ988tgl9qQ9+j/yfkjbeQWBKJ59Ov41pRwcxOkR++AbhNOYq0mf b9hg6dwPuO+GzkMwBYJ3LV4+tbDsfr+dwbd4eAb29LQ1hbyO+/vv6S7HgDaDYe5T+HLC LWgg== X-Gm-Message-State: AOAM5324rMD8RsvCp7rQfmBly3g1bfbGd1Ou1GCid54kZx8XBGEX8N/1 Z/gjMNX0/C7sOxi99omUVsvK06fnrsw= X-Google-Smtp-Source: ABdhPJy2xi5AFbMf66D8PgRJ3nsjX+EyV1mGQ+NUYmYJZECsA8QJAIZGFwjb9UxHEEBOSEGizv7NaQ== X-Received: by 2002:a17:90b:3b88:: with SMTP id pc8mr15083659pjb.217.1643911790486; Thu, 03 Feb 2022 10:09:50 -0800 (PST) Received: from gnu-tgl-2.localdomain ([172.58.38.240]) by smtp.gmail.com with ESMTPSA id p16sm13163702pgj.79.2022.02.03.10.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:09:50 -0800 (PST) Received: from gnu-tgl-2.. (localhost [IPv6:::1]) by gnu-tgl-2.localdomain (Postfix) with ESMTP id D14193004A7; Thu, 3 Feb 2022 10:09:48 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 3/7] Add GLIBC_ABI_DT_RELR for DT_RELR support Date: Thu, 3 Feb 2022 10:09:44 -0800 Message-Id: <20220203180948.2744-4-hjl.tools@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220203180948.2744-1-hjl.tools@gmail.com> References: <20220203180948.2744-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3029.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK 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-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The EI_ABIVERSION field of the ELF header in executables and shared libraries can be bumped to indicate the minimum ABI requirement on the dynamic linker. However, EI_ABIVERSION in executables isn't checked by the Linux kernel ELF loader nor the existing dynamic linker. Executables will crash mysteriously if the dynamic linker doesn't support the ABI features required by the EI_ABIVERSION field. The dynamic linker should be changed to check EI_ABIVERSION in executables. Add a glibc version, GLIBC_ABI_DT_RELR, to indicate DT_RELR support so that the existing dynamic linkers will issue an error on executables with GLIBC_ABI_DT_RELR depdendency. Support __placeholder_only_for_empty_version_map as the placeholder symbol used only for empty version map to generate GLIBC_ABI_DT_RELR without any symbols. --- elf/Makefile | 18 ++++++++++++++++-- elf/Versions | 7 +++++++ elf/libc-abi-version.exp | 1 + scripts/abilist.awk | 2 ++ scripts/versions.awk | 7 ++++++- 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 elf/libc-abi-version.exp diff --git a/elf/Makefile b/elf/Makefile index d1094f40ce..c697e7b7ee 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -48,6 +48,10 @@ routines = \ rtld_static_init \ # routines +ifeq ($(have-dt-relr),yes) +check-abi-version-libc = $(objpfx)check-abi-version-libc.out +endif + # The core dynamic linking functions are in libc for the static and # profiled libraries. dl-routines = \ @@ -1106,8 +1110,8 @@ $(eval $(call include_dsosort_tests,dso-sort-tests-1.def)) $(eval $(call include_dsosort_tests,dso-sort-tests-2.def)) endif -check-abi: $(objpfx)check-abi-ld.out -tests-special += $(objpfx)check-abi-ld.out +check-abi: $(objpfx)check-abi-ld.out $(check-abi-version-libc) +tests-special += $(objpfx)check-abi-ld.out $(check-abi-version-libc) update-abi: update-abi-ld update-all-abi: update-all-abi-ld @@ -2747,3 +2751,13 @@ $(objpfx)check-tst-relr-pie.out: $(objpfx)tst-relr-pie | sed -ne '/required from libc.so/,$$ p' \ | grep GLIBC_ABI_DT_RELR > $@; \ $(evaluate-test) + +$(objpfx)check-abi-version-libc.out: libc-abi-version.exp \ + $(objpfx)libc.symlist-abi-version + cmp $^ > $@; \ + $(evaluate-test) + +$(objpfx)libc.symlist-abi-version: $(common-objpfx)libc.so + LC_ALL=C $(NM) -D $< | grep " GLIBC_ABI_" \ + | sed "s/^0\+/00000000/" > $@T + mv -f $@T $@ diff --git a/elf/Versions b/elf/Versions index 8bed855d8c..a84927c95f 100644 --- a/elf/Versions +++ b/elf/Versions @@ -23,6 +23,13 @@ libc { GLIBC_2.35 { _dl_find_object; } +%if HAVE_DT_RELR + GLIBC_ABI_DT_RELR { + # This symbol is used only for empty version map and will be removed + # by scripts/versions.awk. + __placeholder_only_for_empty_version_map; + } +%endif GLIBC_PRIVATE { # functions used in other libraries __libc_early_init; diff --git a/elf/libc-abi-version.exp b/elf/libc-abi-version.exp new file mode 100644 index 0000000000..455088dc6b --- /dev/null +++ b/elf/libc-abi-version.exp @@ -0,0 +1 @@ +00000000 A GLIBC_ABI_DT_RELR diff --git a/scripts/abilist.awk b/scripts/abilist.awk index 24a34ccbed..6cc7af6ac8 100644 --- a/scripts/abilist.awk +++ b/scripts/abilist.awk @@ -55,6 +55,8 @@ $2 == "g" || $2 == "w" && (NF == 7 || NF == 8) { # caused STV_HIDDEN symbols to appear in .dynsym, though that is useless. if (NF > 7 && $7 == ".hidden") next; + if (version ~ /^GLIBC_ABI_/ && !include_abi_version) next; + if (version == "GLIBC_PRIVATE" && !include_private) next; desc = ""; diff --git a/scripts/versions.awk b/scripts/versions.awk index 357ad1355e..d70b07bd1a 100644 --- a/scripts/versions.awk +++ b/scripts/versions.awk @@ -185,8 +185,13 @@ END { closeversion(oldver, veryoldver); veryoldver = oldver; } - printf("%s {\n global:\n", $2) > outfile; oldver = $2; + # Skip the placeholder symbol used only for empty version map. + if ($3 == "__placeholder_only_for_empty_version_map;") { + printf("%s {\n", $2) > outfile; + continue; + } + printf("%s {\n global:\n", $2) > outfile; } printf(" ") > outfile; for (n = 3; n <= NF; ++n) {