From patchwork Fri Aug 4 18:16:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 73635 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 E22AD3856962 for ; Fri, 4 Aug 2023 18:17:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E22AD3856962 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1691173051; bh=xqFA8IBSdD/3Jd/GxE7z438R36V/SzU4IkyCpu0Y1Z4=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=O+GnhJqx3EVF1yi453PjcLos6lxZGvVi9TvEwPeofyaQcq+eaamLvH7r5YWxWO0dH zKlhQPWSMaVq/mmhT9JxO3JHnvJmyKTi429t+BcpPA3WqrS7H4xocahL0nBDdIUsvd D7hlss/F3SwOMx2urZyfFMoLj/Q8hDY8Bi519+mY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 7A5CC3857019 for ; Fri, 4 Aug 2023 18:16:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A5CC3857019 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-207-bYGNpAWzN02yVQx5kiT01g-1; Fri, 04 Aug 2023 14:16:27 -0400 X-MC-Unique: bYGNpAWzN02yVQx5kiT01g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 05BF98DC669 for ; Fri, 4 Aug 2023 18:16:27 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 57F1F4021CE for ; Fri, 4 Aug 2023 18:16:26 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 2/3] manual: Document ld.so --list-diagnostics output In-Reply-To: Message-ID: References: X-From-Line: b17c05bcb9bdb932274db611445e19c83abfaa6c Mon Sep 17 00:00:00 2001 Date: Fri, 04 Aug 2023 20:16:25 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 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: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" --- manual/dynlink.texi | 279 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 279 insertions(+) diff --git a/manual/dynlink.texi b/manual/dynlink.texi index 45bf5a5b55..fc2cd2f0a4 100644 --- a/manual/dynlink.texi +++ b/manual/dynlink.texi @@ -13,9 +13,288 @@ as plugins) later at run time. Dynamic linkers are sometimes called @dfn{dynamic loaders}. @menu +* Dynamic Linker Invocation:: Explicit invocation of the dynamic linker. * Dynamic Linker Introspection:: Interfaces for querying mapping information. @end menu +@node Dynamic Linker Invocation + +@cindex program interpreter +When a dynamically linked program starts, the operating system +automatically loads the dynamic linker along with the program. +@Theglibc{} also supports invoking the dynamic linker explicitly to +launch a program. This command uses the implied dynamic linker +(also sometimes called the @dfn{program interpreter}): + +@smallexample +sh -c 'echo "Hello, world!"' +@end smallexample + +This command specifies the dynamic linker explicitly: + +@smallexample +ld.so /bin/sh -c 'echo "Hello, world!"' +@end smallexample + +Note that @command{ld.so} does not search the @env{PATH} environment +variable, so the full file name of the executable needs to be specified. + +The @command{ld.so} program supports various options. Options start +@samp{--} and need to come before the program that is being launched. +Some of the supported options are listed below. + +@table @code +@item --list-diagnostics +Print system diagnostic information in a machine-readable format. +@xref{Dynamic Linker Diagnostics}. +@end table + +@menu +* Dynamic Linker Diagnostics:: Obtaining system diagnostic information. +@end menu + +@node Dynamic Linker Diagnostics +@section Dynamic Linker Diagnostics +@cindex diagnostics (dynamic linker) + +The @samp{ld.so --list-diagnostics} produces machine-readable +diagnostics output. This output contains system data that affects +behavior of @theglibc{}, and potentially application behavior as well. + +The exact set of diagnostic items can change between releases of +@theglibc{}. The output format itself is not expected to change +radically. + +The following table shows some example lines that can be written by the +diagnostics command. + +@table @code +@item dl_pagesize=0x1000 +The system page size is 4096 bytes. + +@item env[0x14]="LANG=en_US.UTF-8" +This item indicates that the 21st environment variable at process +startup contains a setting for @code{LANG}. + +@item env_filtered[0x22]="DISPLAY" +The 35th environment variable is @code{DISPLAY}. Its value is not +included in the output for privacy reasons because it is not recognized +as harmless by the diagnostics code. + +@item path.prefix="/usr" +This means that @theglibc{} was configured with @code{--prefix=/usr}. + +@item path.system_dirs[0x0]="/lib64/" +@itemx path.system_dirs[0x1]="/usr/lib64/" +The built-in dynamic linker search path contains two directories, +@code{/lib64} and @code{/usr/lib64}. +@end table + +@subsection Dynamic Linker Diagnostics Output Format + +As seen above, diagnostic lines assign values (integers or strings) to a +sequences of labeled subscripts, separated by @samp{.}. Some subscripts +have integer indices associated with them. The subscript indices are +not necessarily contiguous or small, so an associative array should be +used to store them. Currently, all integers fit into the 64-bit +unsigned integer range. Every access path to a value has a fixed type +(string or integer) independently of subscript index values. Likewise, +whether a subscript is indexed does not depend on previous indices (but +may depend on previous subscript labels). + +A syntax description in ABNF (RFC 5234) follows. Note that +@code{%x30-39} denotes the range of decimal digits. Diagnostic output +lines are expected to match the @code{line} production. + +@c ABNF-START +@smallexample +HEXDIG = %x30-39 / %x61-6f ; lowercase a-f only +ALPHA = %x41-5a / %x61-7a / %x7f ; letters and underscore +ALPHA-NUMERIC = ALPHA / %x30-39 / "_" +DQUOTE = %x22 ; " + +; Numbers are always hexadecimal and use a 0x prefix. +hex-value-prefix = %x30 %x78 +hex-value = hex-value-prefix 1*HEXDIG + +; Strings use octal escape sequences and \\, \". +string-char = %x20-21 / %x23-5c / %x5d-7e ; printable but not "\ +string-quoted-octal = %x30-33 2*2%x30-37 +string-quoted = "\" ("\" / DQUOTE / string-quoted-octal) +string-value = DQUOTE *(string-char / string-quoted) DQUOTE + +value = hex-value / string-value + +label = ALPHA *ALPHA-NUMERIC +index = "[" hex-value "]" +subscript = label [index] + +line = subscript *("." subscript) "=" value +@end smallexample + +Output lines can be parsed with the following Python function. It +assumes lines formatted according to the ABNF @code{line} production +above. + +@c PYTHON-START +@smallexample +def parse_line(line): + """Parse a line of --list-diagnostics output. + + This function returns a pair (SUBSCRIPTS, VALUE). VALUE is either + a byte string or an integer. SUBSCRIPT is a tuple of (LABEL, + INDEX) pairs, where LABEL is a field identifier (a string), and + INDEX is an integer or None, to indicate that this field is not + indexed. + + """ + + # Extract the list of subscripts before the value. + idx = 0 + subscripts = [] + while line[idx] != '=': + start_idx = idx + + # Extract the label. + while line[idx] not in '[.=': + idx += 1 + label = line[start_idx:idx] + + if line[idx] == '[': + # Subscript with a 0x index. + assert label + close_bracket = line.index(']', idx) + index = line[idx + 1:close_bracket] + assert index.startswith('0x') + index = int(index, 0) + subscripts.append((label, index)) + idx = close_bracket + 1 + else: # '.' or '='. + if label: + subscripts.append((label, None)) + if line[idx] == '.': + idx += 1 + + # The value is either a string or a 0x number. + value = line[idx + 1:] + if value[0] == '"': + # Decode the escaped string into a byte string. + assert value[-1] == '"' + idx = 1 + result = [] + while True: + ch = value[idx] + if ch == '\\': + if value[idx + 1] in '"\\': + result.append(ord(value[idx + 1])) + idx += 2 + else: + result.append(int(value[idx + 1:idx + 4], 8)) + idx += 4 + elif ch == '"': + assert idx == len(value) - 1 + break + else: + result.append(ord(value[idx])) + idx += 1 + value = bytes(result) + else: + # Convert the value into an integer. + assert value.startswith('0x') + value = int(value, 0) + return (tuple(subscripts), value) +@end smallexample + +@subsection Dynamic Linker Diagnostics Values + +As mentioned above, the set of diagnostics may change between +@theglibc{} releases. Nevertheless, the following table documents a few +common diagnostic items. + +@table @code +@item dl_dst_lib=@var{string} +The @code{$LIB} dynamic string token expands to @var{string}. + +@item dl_hwcap=@var{integer} +@itemx dl_hwcap2=@var{integer} +@cindex HWCAP (diagnostics) +The HWCAP and HWCAP2 values, as returned for @code{getauxval}, and as +used in other places depending on the architecture. + +@item dl_pagesize=@var{integer} +@cindex page size (diagnostics) +The system page size is @var{integer} bytes. + +@item dl_platform=@var{string} +The @code{$PLATFORM} dynamic string token expands to @var{string}. + +@item dso.libc=@var{string} +This is the soname of the shared @code{libc} object that is part of +@theglibc{}. On most architectures, this is @code{libc.so.6}. + +@item env[@var{index}]=@var{string} +@itemx env_filtered[@var{index}]=@var{string} +An environment variable from the process environment. The integer +@var{index} is the array index in the environment array. Variables +under @code{env} include the variable value after the @samp{=} (assuming +that it was present), variables under @code{env_filtered} do not. + +@item path.prefix=@var{string} +This indicates that @theglibc{} was configured using +@samp{--prefix=@var{string}}. + +@item path.sysconfdir=@var{string} +@Theglibc{} was configured (perhaps implicitly) with +@samp{--sysconfdir=@var{string}} (typically @code{/etc}). + +@item path.system_dirs[@var{index}]=@var{string} +These items list the elements of the built-in array that describes the +default library search path. The value @var{string} a directory file +name with a trailing @samp{/}. + +@item path.rtld=@var{string} +This string indicates the application binary interface (ABI) file name +of the run-time dynamic linker. + +@item version.release="stable" +@itemx version.release="development" +The value @code{"stable"} indicates that this build of @theglibc{} is +from a release branch. Releases labeled as @code{"development"} are +unreleased development versions. + +@item version.version="@var{major}.@var{minor}" +@itemx version.version="@var{major}.@var{minor}.9000" +@cindex version (diagnostics) +@Theglibc{} version. Development releases end in @samp{.9000}. + +@item auxv[@var{index}].a_type=@var{type} +@itemx auxv[@var{index}].a_val=@var{integer} +@itemx auxv[@var{index}].a_val_string=@var{string} +@cindex auxiliary vector (diagnostics) +An entry in the auxiliary vector (specific to Linux). The values +@var{type} (an integer) and @var{integer} correspond to the members of +@code{struct auxv}. If the value is a string, @code{a_val_string} is +used instead of @code{a_val}, so that values have consistent types. + +The @code{AT_HWCAP} and @code{AT_HWCAP2} values in this output do not +reflect adjustment by @theglibc{}. + +@item uname.sysname=@var{string} +@itemx uname.nodename=@var{string} +@itemx uname.release=@var{string} +@itemx uname.version=@var{string} +@itemx uname.machine=@var{string} +@itemx uname.domain=@var{string} +These Linux-specific items show the values of @code{struct utsname}, as +reported by the @code{uname} function. @xref{Platform Type}. + +@item x86.cpu_features.@dots{} +@cindex CPUID (diagnostics) +These items are specific to the i386 and x86-64 architectures. They +reflect supported CPU feature and information on cache geometry, mostly +collected using the @code{CPUID} instruction. +@end table + @node Dynamic Linker Introspection @section Dynamic Linker Introspection