From patchwork Tue Nov 23 22:30:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 48047 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 4ECED385800B for ; Tue, 23 Nov 2021 22:31:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4ECED385800B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1637706678; bh=rnyPdlenJXJpODtgdatWBhqmhCthQNqk8Ah/NQP2Ly8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Rl7jI9nNkMKY4HJafxe8SaeV03mmlldNdCucZ5h0OJZeIki+EGbnbUKCyhYGIjuxb AC6Rpc8xVsmHJMrrjVNGxMwe5RbiShMFe7hvRJfEJRVZY3Qm4lBhj4SNipCPzoRO2r go/AmobxPX30pTkpcxhCaEU99tRx/vFhx+Rvg3YM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id AEFDF3858D28 for ; Tue, 23 Nov 2021 22:30:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AEFDF3858D28 Received: by mail-pf1-x432.google.com with SMTP id x131so643264pfc.12 for ; Tue, 23 Nov 2021 14:30:55 -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:subject:date:message-id:mime-version :content-transfer-encoding; bh=rnyPdlenJXJpODtgdatWBhqmhCthQNqk8Ah/NQP2Ly8=; b=ElxtiLA6om3jHxiJ7X4ZuNGZ2OodLQ26qLTEllTQ8i1tSkiVINIiMDFbDvdj10WH81 1Ns0P0XSTVrtbwO6wAyGySt3ZsJuOU4aiw2uWJWxAV8myQ7CWrTUYIhBi9R7UdVdbiJo +9Q/BX3lIXtZtPbK4mYGvUnTOej/OlPx5Xtw6kbDVs0Z9/kzp7hnuowl/ZZRCZEwZc2p Ck7SdThQh32utTp57Ll66EFyRTEbHphqHRuTro9KER2WOrfLOmRGFkJk9gRpb9InFT+B sezBIjv1kGGwu7hbTrmP66GJKam0HlpZo6qwdSSxYzaJYg+6DibI7ch9UGgyndADyU1i NaXQ== X-Gm-Message-State: AOAM531mcUJTTMaWu9/Oo5Cg4PE4MalzJ8M6n18bbeGSCf8ZlgD0pO1b KElhbxLVzUhUhZOpz+7Qm1OCwXuBKq4= X-Google-Smtp-Source: ABdhPJxE7tEjuc9LIbJr0/DXS8eedlP4hEo1srsBfwLBpjTqaKCjfjp3aXv4ejipNqnLzQi92V0SaA== X-Received: by 2002:a63:111d:: with SMTP id g29mr6284382pgl.49.1637706654548; Tue, 23 Nov 2021 14:30:54 -0800 (PST) Received: from gnu-tgl-3.localdomain (71-222-78-46.lsv2.qwest.net. [71.222.78.46]) by smtp.gmail.com with ESMTPSA id f15sm15637178pfe.171.2021.11.23.14.30.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Nov 2021 14:30:54 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 8ADF3C0DA3 for ; Tue, 23 Nov 2021 14:30:53 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2] Add GLIBC_ABI_VERSION_GEN2 for ABIVERSION Date: Tue, 23 Nov 2021 14:30:53 -0800 Message-Id: <20211123223053.3334224-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3030.6 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, 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_VERSION_GEN2, to mirror the EI_ABIVERSION bump from the baseline ABI features so that the existing dynamic linkers will issue an error on executables with GLIBC_ABI_VERSION_GEN2 depdendency. A dummy symbol, __libc_abi_version_placeholder, is added since linker won't create a symbol version node with an empty symbol list. --- elf/Makefile | 19 ++++++++++++++++--- elf/Versions | 3 +++ elf/libc-abi-version.c | 21 +++++++++++++++++++++ elf/libc-abi-version.exp | 1 + scripts/abilist.awk | 2 ++ 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 elf/libc-abi-version.c create mode 100644 elf/libc-abi-version.exp diff --git a/elf/Makefile b/elf/Makefile index 4723c159cb..5da419c0e5 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -25,7 +25,8 @@ headers = elf.h bits/elfclass.h link.h bits/link.h bits/link_lavcurrent.h routines = $(all-dl-routines) dl-support dl-iteratephdr \ dl-addr dl-addr-obj enbl-secure dl-profstub \ dl-origin dl-libc dl-sym dl-sysdep dl-error \ - dl-reloc-static-pie libc_early_init rtld_static_init + dl-reloc-static-pie libc_early_init rtld_static_init \ + libc-abi-version # The core dynamic linking functions are in libc for the static and # profiled libraries. @@ -517,8 +518,10 @@ $(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 \ + $(objpfx)check-abi-version-libc.out +tests-special += $(objpfx)check-abi-ld.out \ + $(objpfx)check-abi-version-libc.out update-abi: update-abi-ld update-all-abi: update-all-abi-ld @@ -1977,3 +1980,13 @@ $(objpfx)tst-ro-dynamic-mod.so: $(objpfx)tst-ro-dynamic-mod.os \ $(LINK.o) -nostdlib -nostartfiles -shared -o $@ \ -Wl,--script=tst-ro-dynamic-mod.map \ $(objpfx)tst-ro-dynamic-mod.os + +$(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_VERSION_" \ + | sed "s/^0\+/00000000/" > $@T + mv -f $@T $@ diff --git a/elf/Versions b/elf/Versions index 775aab62af..f51e77ab8a 100644 --- a/elf/Versions +++ b/elf/Versions @@ -20,6 +20,9 @@ libc { __register_frame_info_table_bases; _Unwind_Find_FDE; } %endif + GLIBC_ABI_VERSION_GEN2 { + __libc_abi_version_placeholder; + } GLIBC_PRIVATE { # functions used in other libraries __libc_early_init; diff --git a/elf/libc-abi-version.c b/elf/libc-abi-version.c new file mode 100644 index 0000000000..9763f6b19d --- /dev/null +++ b/elf/libc-abi-version.c @@ -0,0 +1,21 @@ +/* Placeholder definition for GLIBC_ABI_VERSION nodes. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifdef SHARED +char __libc_abi_version_placeholder attribute_compat_data_section; +#endif diff --git a/elf/libc-abi-version.exp b/elf/libc-abi-version.exp new file mode 100644 index 0000000000..64a97b8d6f --- /dev/null +++ b/elf/libc-abi-version.exp @@ -0,0 +1 @@ +00000000 A GLIBC_ABI_VERSION_GEN2 diff --git a/scripts/abilist.awk b/scripts/abilist.awk index 24a34ccbed..94ee8b0e0f 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_VERSION_/ && !include_abi_version) next; + if (version == "GLIBC_PRIVATE" && !include_private) next; desc = "";