From patchwork Thu Oct 28 00:03:45 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: 46725 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 0F0243857C56 for ; Thu, 28 Oct 2021 00:06:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F0243857C56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635379618; bh=8JMPgxnLmFL9S7SX8PJUrQUOQ2OGAbs0W+jjciCOmXk=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=aBSBBiSVp1GIxbU1pOBcHaWlujHLpxRkhTuBlECdtVw2DEvIHlB+sXzqvb4WHsNes dJEH6aYl9aJA85UkgNPCTMhot+kWa2Mas4JRiaE9XJNXFhbade42x3FSjmNNGhsL7f f0evQakU5Rpsm4/KxCfPR8sXmPKGuAmDknED47gA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id 7F18A3858404; Thu, 28 Oct 2021 00:03:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7F18A3858404 Received: by mail-pj1-x1035.google.com with SMTP id n36-20020a17090a5aa700b0019fa884ab85so6473118pji.5; Wed, 27 Oct 2021 17:03:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=8JMPgxnLmFL9S7SX8PJUrQUOQ2OGAbs0W+jjciCOmXk=; b=thUOYKcl47PeZvqIduf+N4/4Xvu65XTpOHMF1aEn1IcYGuAjHqJZiplT8sEdI9wgDZ SEtm5G/RjBTHfEUaNfJJXPF9O8I2iLtYDrVpz1IQLNBjyUxFcL0GHoyyyGDL/klOQB7D XR9nn1udT7wYkvHHkS9mLB1cCCUNXwuge13HLRg7mkUyyMXF29d1FVzCOqRm8VHNjJ7J ySQYPC2yAZLeLDzF/X3TePmrPRtoY7Q03BLRHmmfqkm3U5rj0+foGrpurcKT9AnKDdiy jEWpbjhYXbhQAraVncb8phFb6f5Oes5xD2lcHr/4u/m72l4/djHF9B04cRoK8C31JInu buOA== X-Gm-Message-State: AOAM532sxAkEBjgEMR+tgF3yMTCicmflKifsYBP35UEAN80ZV9QCwq3c s0gfSIpsfFuHy9vaF9ueeQ4= X-Google-Smtp-Source: ABdhPJx2Gu5ilb86Ta3qEieUCudAW/n6Kaiy5VSnI2nRRqf1J77XRJYBpnyiDDcv9odqhqcr8w1IqA== X-Received: by 2002:a17:903:22c5:b0:140:298b:9e27 with SMTP id y5-20020a17090322c500b00140298b9e27mr844981plg.23.1635379426601; Wed, 27 Oct 2021 17:03:46 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id k3sm5009847pjg.43.2021.10.27.17.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 17:03:46 -0700 (PDT) Received: by gnu-cfl-2.localdomain (Postfix, from userid 1000) id 391D01A0C2E; Wed, 27 Oct 2021 17:03:45 -0700 (PDT) Date: Wed, 27 Oct 2021 17:03:45 -0700 To: GNU C Library , binutils@sourceware.org Subject: [PATCH] Add GNU_PROPERTY_1_GLIBC_2_NEEDED Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1015.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, LIKELY_SPAM_BODY, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable 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" Cc: llvm-dev@lists.llvm.org, gcc@gcc.gnu.org, gnu-gabi@sourceware.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Motivations: 1. Some binaries which require new ELF features, like DT_RELR, only work with the new glibc binary. They crash at run-time with the older glibc binaries. 2. Somes binaries compiled with the new language features, like C2X printf specifiers, only generate correct results with the new glibc binary. Since we don't add new glibc versions to the printf function family, they generate incorrect results at run-time with the older glibc binaries. Here is a proposal to encode glibc version dependencies in relocatable objects: /* The glibc 2 minor versions needed by the object file. */ #define GNU_PROPERTY_1_GLIBC_2_NEEDED (GNU_PROPERTY_UINT32_OR_LO + 1) /* The lowest glibc 2 minor version. */ #define GNU_PROPERTY_1_GLIBC_2_NEEDED_MINOR_BASE 35 /* Set if the object file requires glibc 2 minor version M. */ #define GNU_PROPERTY_1_GLIBC_2_NEEDED_MINOR_VERSION(m) \ (1U << ((m) - GNU_PROPERTY_1_GLIBC_2_NEEDED_MINOR_BASE)) Linker adds glibc versions in GNU_PROPERTY_1_GLIBC_2_NEEDED to the .gnu.version_r section and removes GNU_PROPERTY_1_GLIBC_2_NEEDED note when generating shared libraries and executables. [hjl@gnu-cfl-2 elfvers-1]$ ./readelf -n x.o Displaying notes found in: .note.gnu.property Owner Data size Description GNU 0x00000020 NT_GNU_PROPERTY_TYPE_0 Properties: x86 ISA used: x86 feature used: x86 [hjl@gnu-cfl-2 elfvers-1]$ ./readelf -n glibc-2-minor-1.o Displaying notes found in: .note.gnu.property Owner Data size Description GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 Properties: 1_glibc_2_needed: 2.35, 2.38 GNU 0x00000020 NT_GNU_PROPERTY_TYPE_0 Properties: x86 ISA used: x86 feature used: x86 [hjl@gnu-cfl-2 elfvers-1]$ make x gcc -B./ -o x x.o glibc-2-minor-1.o [hjl@gnu-cfl-2 elfvers-1]$ ./readelf -n --version-info x Version symbols section '.gnu.version' contains 4 entries: Addr: 0x00000000004004ae Offset: 0x0004ae Link: 6 (.dynsym) 000: 0 (*local*) 2 (GLIBC_2.34) 3 (GLIBC_2.2.5) 1 (*global*) Version needs section '.gnu.version_r' contains 1 entry: Addr: 0x00000000004004b8 Offset: 0x0004b8 Link: 7 (.dynstr) 000000: Version: 1 File: libc.so.6 Cnt: 4 0x0010: Name: GLIBC_2.38 Flags: none Version: 5 0x0020: Name: GLIBC_2.35 Flags: none Version: 4 0x0030: Name: GLIBC_2.2.5 Flags: none Version: 3 0x0040: Name: GLIBC_2.34 Flags: none Version: 2 ... [hjl@gnu-cfl-2 elfvers-1]$ ./x ./x: /lib64/libc.so.6: version `GLIBC_2.38' not found (required by ./x) ./x: /lib64/libc.so.6: version `GLIBC_2.35' not found (required by ./x) [hjl@gnu-cfl-2 elfvers-1]$ --- object-files.tex | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/object-files.tex b/object-files.tex index 834f508..41a434c 100644 --- a/object-files.tex +++ b/object-files.tex @@ -444,6 +444,7 @@ The following program property types are defined: \texttt{GNU_PROPERTY_UINT32_AND_HI} & \texttt{0xb0007fff} \\ \texttt{GNU_PROPERTY_UINT32_OR_LO} & \texttt{0xb0008000} \\ \texttt{GNU_PROPERTY_1_NEEDED} & \texttt{GNU_PROPERTY_UINT32_OR_LO + 0} \\ + \texttt{GNU_PROPERTY_1_GLIBC_2_NEEDED} & \texttt{GNU_PROPERTY_UINT32_OR_LO + 1} \\ \texttt{GNU_PROPERTY_UINT32_OR_HI} & \texttt{0xb000ffff} \\ \texttt{GNU_PROPERTY_LOPROC} & \texttt{0xc0000000} \\ \texttt{GNU_PROPERTY_HIPROC} & \texttt{0xdfffffff} \\ @@ -492,6 +493,11 @@ The following program property types are defined: \item[GNU_PROPERTY_1_NEEDED] The \code{pr_data} field contains a 4-byte integer to indicate the properties needed by object file. + \item[GNU_PROPERTY_1_GLIBC_2_NEEDED] + The \code{pr_data} field contains a 4-byte integer to indicate the + minor versions of the GNU C library version 2 needed by object file. + This property is only valid in relocatable object files. Linker + should not add it to executables nor shared libraries. \item[GNU_PROPERTY_LOPROC through GNU_PROPERTY_HIPROC] Values in this inclusive range are reserved for processor-specific semantics. @@ -528,6 +534,50 @@ The following bits are defined for \code{GNU_PROPERTY_1_NEEDED}: \end{sloppypar} \end{description} +The following values are defined for \code{GNU_PROPERTY_1_GLIBC_2_NEEDED}: + +\begin{table}[H] +\Hrule + \caption{GNU_PROPERTY_1_GLIBC_2_NEEDED Values} + \begin{center} + \begin{footnotesize} + \begin{tabular}[t]{l|l} + \multicolumn{1}{c}{Name} & \multicolumn{1}{c}{Value} \\ + \hline + \texttt{GNU_PROPERTY_1_GLIBC_2_NEEDED_MINOR_BASE} & \texttt{35} \\ + \texttt{GNU_PROPERTY_1_GLIBC_2_NEEDED_MINOR_VERSION(m)} + & \texttt{1U << (m - 35)} \\ + \end{tabular} + \end{footnotesize} + \end{center} +\Hrule +\end{table} + +\begin{description} + \item[GNU_PROPERTY_1_GLIBC_2_NEEDED_MINOR_BASE] + \begin{sloppypar} + This specifies the oldest minor version of the GNU C library version 2 + supported by \code{GNU_PROPERTY_1_GLIBC_2_NEEDED}. + \end{sloppypar} + \item[GNU_PROPERTY_1_GLIBC_2_NEEDED_MINOR_VERSION] + \begin{sloppypar} + The bit \code{n} in \code{GNU_PROPERTY_1_GLIBC_2_NEEDED} represents + the minor version \code{35 + n} of the GNU C library version 2 needed + by object file. This macro: + \begin{footnotesize} + \begin{verbatim} +#define GNU_PROPERTY_1_GLIBC_2_NEEDED_MINOR_VERSION(m) \ + (1U << ((m) - GNU_PROPERTY_1_GLIBC_2_NEEDED_MINOR_BASE)) + \end{verbatim} + \end{footnotesize} + maps the minor version \code{m} to a bit in + \code{GNU_PROPERTY_1_GLIBC_2_NEEDED}. + Linker should add minor versions of the GNU C library version 2 + which are set in \code{GNU_PROPERTY_1_GLIBC_2_NEEDED} to the run-time + requirements of executables and shared libraries. + \end{sloppypar} +\end{description} + \subsection{\code{.note.ABI-tag} section} \label{sec_abi_tag}