From nobody Fri Dec 08 21:56:49 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Sn4jY2zwvz53TVK; Fri, 8 Dec 2023 21:56:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Sn4jY2W3Nz4RSx; Fri, 8 Dec 2023 21:56:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702072609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=k05cf3zE4NABwz0X7pWtCtZT3mbjEpcZs+gUNpVXp/4=; b=eceftnv1BVRN3KgzR/fN9SL7Cq9BEVlXVykas1z0rilTQ+zdy4kI74jHZemXM5xkAtXTj5 ARBrvbigbS5Ww19p4O6WHD5b/jrT0Uawyo0raK3R2G25FCv18sOHzqpEwR3SNVYNc63kkd brkxli3n+SpcY+8/ZhOrcG/qp0ui2LXo2BzcCI9Eo1t8q47fCBTkBKSYjAthCvWlAqSdKB /0KXXk7jhCNbwTZzYVg69BTl+eLmYvtl5Qj+tkpTWfL0KQvWbYWimHdK/i3bfkC5hWBHeF ++jxMZQyqnJwC6vV8P3hhXTBfQHiVwfU741AfkNwS2ss7lR/B4KNNDSLsZRpGQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702072609; a=rsa-sha256; cv=none; b=qDnlT0MWm3zmnSIXEOSr7mvXcLDiy5U5edS0uJYT7rCWW4BnpWM9+2q7vwJWPcmgakLu44 jm8DPbDF5uZ9DhliXVHgqWyFQcDzqpkSDSkBePGzRKwvvkW75V0ZFsC3ToGqKQTgyFL1+H WOnugff6ObKk3Suh//kaFP54E88F0An37Jj5UkdF6eERVPjV8ex7I6SCXt39eylRmrQihv dc0yZUgIVLwkZldWYCNowdPQt7u42o3l/9Ui40mHhZJSuy0Yw8TcslxJsqBtzK3csgCP8w UwwlLirofrl1zFmlekYDRgBA4JgJ2ad8XDlT67P/5qDurHZPkDBeqAKPjioobw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702072609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=k05cf3zE4NABwz0X7pWtCtZT3mbjEpcZs+gUNpVXp/4=; b=YDMNPeSFlwIIZ939ryXXalIluA3KdXUMfy3vxt6Hlk+/CncOTFSBhXm6WxBtw6OcPX8rgf hlENdkNuI5PILaWXUMEUgqXTOQIlR9p5s+l5kRc6QTn/wf0TNmIm9skNs3xcj7sI+olpfk qUVfDmA62Ub2bRGNbx4xiokD7l8hml6JOuh2AIdGOxusJ8N5HH7KaiKWU4+Wf+83/I2YK0 kun96MspeRP7ss1MF9rP/bCZCIU1NdNNusM41WZmw3qAflZ1TED4+8Vtn3oW1Pw89XGZAu h4UNm/wv8/waALVsbnahx/mzXSmZquTIk0Z+p/GpMDfnNlFCozvaTUGfAwcDkg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Sn4jY1ZLjzdnR; Fri, 8 Dec 2023 21:56:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3B8LunCQ003635; Fri, 8 Dec 2023 21:56:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3B8Lun7Y003632; Fri, 8 Dec 2023 21:56:49 GMT (envelope-from git) Date: Fri, 8 Dec 2023 21:56:49 GMT Message-Id: <202312082156.3B8Lun7Y003632@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Gordon Bergling Subject: git: e48c3d3a06db - stable/14 - Document library types in the intro(3) manual page List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: gbe X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: e48c3d3a06db6a435207f6c08b4d31e9deb242e7 Auto-Submitted: auto-generated The branch stable/14 has been updated by gbe: URL: https://cgit.FreeBSD.org/src/commit/?id=e48c3d3a06db6a435207f6c08b4d31e9deb242e7 commit e48c3d3a06db6a435207f6c08b4d31e9deb242e7 Author: Gordon Bergling AuthorDate: 2023-11-16 09:48:09 +0000 Commit: Gordon Bergling CommitDate: 2023-12-08 21:56:25 +0000 Document library types in the intro(3) manual page Add a paragraph about library types to the intro(3) manual page. Document library types, locations and versioning. Reviewed by: emaste, jilles, mhorne, pauamma_gundo.com Obtained from: OpenBSD (partial) Differential Revision: https://reviews.freebsd.org/D36594 (cherry picked from commit 54611b7cc69cee34e7bcdc2324a9159e7543a125) --- share/man/man3/intro.3 | 97 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/share/man/man3/intro.3 b/share/man/man3/intro.3 index c36ab620bed3..bfae9093af93 100644 --- a/share/man/man3/intro.3 +++ b/share/man/man3/intro.3 @@ -26,8 +26,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)intro.3 8.1 (Berkeley) 6/5/93 -.\" -.Dd November 7, 2022 +.Dd November 16, 2023 .Dt INTRO 3 .Os .Sh NAME @@ -278,13 +277,105 @@ the math library .It Pa /usr/lib/libm_p.a the math library compiled for profiling .El +.Sh LIBRARY TYPES +The system libraries are located in +.Pa /lib +and +.Pa /usr/lib . +A library has the following naming convention: +.Bd -unfilled -offset indent +libc.so.7 +.Ed +.Pp +Libraries with an +.Sq .a +suffix are static. +When a program is linked against a static library, all necessary library code +will be included in the binary. +This means the binary can be run even when the libraries are unavailable. +However, it can be inefficient with both disk space and memory usage +during execution. +The C compiler, +.Xr cc 1 , +can be instructed to link statically by specifying the +.Fl static +flag. +.Pp +Libraries with a +.Sq .so.X +suffix are dynamic libraries. +When code is linked dynamically, the library code that the application needs +is not included in the binary. +Instead, data structures are added containing information about which dynamic +libraries to link with. +When the binary is executed, the run-time linker +.Xr ld.so 1 +reads these data structures and loads them into the +process virtual address space. +.Xr rtld 1 +loads the shared libraries when the program is executed. +.Pp +.Sq X +represents the library version number of the library. +In the example above, a binary linked with +.Pa libc.so.8 +would not be usable on a system where only +.Pa libc.so.7 +is available. +.Pp +The advantages of dynamic libraries are that multiple instances of the same +library can share address space, and the physical size of the binary is +smaller. +A namespace per shared library is available via hidden visibility, +allowing multiple compilation units in a library to share things without +making them available to other libraries. +It is possible to load libraries dynamically via +.Xr dlopen 3 . +The disadvantage is the added complexity that comes with loading the +libraries dynamically, and the extra time taken to load the libraries. +Of course, if the libraries are not available, the binary will be unable +to execute. +Calls across shared libraries are also slightly slower and cannot be +inlined, not even with link time optimization. +The C compiler, +.Xr cc 1 , +can be instructed to link dynamically by specifying the +.Fl shared +flag. +.Pp +Shared libraries, as well as static libraries on architectures which produce +position-independent executables +.Pq PIEs +by default, contain position-independent code +.Pq PIC . +Normally, compilers produce relocatable code. +Relocatable code needs to be modified at run-time, depending on where in +memory it is to be run. +The C compiler, +.Xr cc 1 , +can be instructed to generate PIC code by specifying the +.Fl fPIC +flag. +.Pp +Static libraries are generated using the +.Xr ar 1 +utility. +The libraries contain an index to the contents of the library, +stored within the library itself. +The index lists each symbol defined by a member of a library that is a +relocatable object file. +This speeds up linking to the library, and allows routines in the library +to call each other regardless of their placement within the library. .Sh SEE ALSO +.Xr ar 1 , .Xr cc 1 , .Xr ld 1 , .Xr nm 1 , .Xr intro 2 , .Xr math 3 , -.Xr stdio 3 +.Xr stdio 3 , +.Xr make.conf 5 , +.Xr src.conf 5 .Sh HISTORY An .Nm