### Configure ISA-specific Library Makefiles Source: https://illumos.org/books/dev/anatomy.html Examples of Makefile configurations for 32-bit (i386) and 64-bit (amd64) libraries. These files include common build definitions and specify installation targets for the proto area. ```Makefile # i386 Makefile include ../Makefile.com install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT) ``` ```Makefile # amd64 Makefile include ../Makefile.com include ../../Makefile.lib.64 install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTLINT64) ``` -------------------------------- ### Initialize Development Environment with bldenv Source: https://illumos.org/books/dev/workflow.html This code example shows how to use the `bldenv` command to set up a development environment for incremental builds in illumos. It emphasizes using the correct build type flag (e.g., `-d` for debug) that matches the initial `nightly` build. ```shell $ cd /ws/rm/illumos-gate $ /opt/onbld/bin/bldenv -d ./illumos.sh Build type is DEBUG RELEASE is VERSION is illumos-gate RELEASE_DATE is May 2013 The top-level 'setup' target is available to build headers and tools. Using /bin/bash as shell. $ ``` -------------------------------- ### Adding New Files and Committing with Git Source: https://illumos.org/books/dev/workflow.html This example demonstrates the process of adding newly created files to the git repository and then committing them. It first performs a dry run (`-n`) to verify which files will be added, followed by the actual `git add` command and a subsequent commit of all changes. ```shell $ git add -n lib/librm $ # Check the above dry run and verify it has everything you expect $ git add lib/librm $ git commit -a ``` -------------------------------- ### Architecture-Specific Makefile for i386 and sparc Source: https://illumos.org/books/dev/anatomy.html This Makefile snippet is for 32-bit architectures like i386 and sparc. It includes a common Makefile and defines an 'install' target that builds the program and installs it as a 32-bit executable. ```makefile # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2013 Joyent, Inc. All rights reserved. # include ../Makefile.com install: all $(ROOTPROG32) ``` -------------------------------- ### Configure 64-bit Architecture Makefile Source: https://illumos.org/books/dev/anatomy.html A snippet demonstrating the inclusion of 64-bit specific Makefile definitions and updating installation dependencies from 32-bit to 64-bit targets. ```Makefile include ../Makefile.com include ../../Makefile.cmd.64 install: all $(ROOTPROG64) ``` -------------------------------- ### Architecture-Specific Kernel Module Makefile (uts/intel/nr/Makefile) Source: https://illumos.org/books/dev/anatomy.html This is an example of an architecture-specific Makefile for a kernel module (nr) under the x86 architecture. It sets up build variables, includes common and architecture-specific makefile fragments, and defines installation targets. It's essential for building modules tailored to a particular instruction-set architecture. ```makefile # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2012 Joyent, Inc. All rights reserved. # Use is subject to license terms. # UTSBASE = ../.. MODULE = nr OBJECTS = $(NR_OBJS:%=$(OBJS_DIR)/%) ROOTMODULE = $(ROOT_DRV_DIR)/$(MODULE) CONF_SRCDIR = $(UTSBASE)/common/io/nr include $(UTSBASE)/intel/Makefile.intel ALL_TARGET = $(BINARY) $(SRC_CONFILE) INSTALL_TARGET = $(BINARY) $(ROOTMODULE) $(ROOT_CONFFILE) .KEEP_STATE: def: $(DEF_DEPS) all: $(ALL_DEPS) clean: $(CLEAN_DEPS) clobber: $(CLOBBER_DEPS) install: $(INSTALL_DEPS) include $(UTSBASE)/intel/Makefile.targ ``` -------------------------------- ### Command Line Usage Examples for ctfdump Source: https://illumos.org/books/dev/anatomy.html Shell commands demonstrating how to dump type information from a library and how to extract raw CTF data for inspection with mdb(1). ```bash $ ctfdump -t /usr/lib/libc.so.1 $ ctfdump -u ctf.out /usr/lib/libc.so.1 $ mdb ./ctf.out > ::typedef -r /usr/lib/libctf.so.1 > 0::print ctf_header_t ``` -------------------------------- ### Kernel Module Makefile Configuration Source: https://illumos.org/books/dev/anatomy.html An example of an x86 Makefile for a kernel module, defining module objects, build targets, and compiler flags. ```makefile UTSBASE = ../.. MODULE = vnic OBJECTS = $(VNIC_OBJS:%=$(OBJS_DIR)/%) ROOTMODULE = $(ROOT_DRV_DIR)/$(MODULE) CONF_SRCDIR = $(UTSBASE)/common/io/vnic include $(UTSBASE)/intel/Makefile.intel ALL_TARGET = $(BINARY) $(SRC_CONFILE) INSTALL_TARGET = $(BINARY) $(ROOTMODULE) $(ROOT_CONFFILE) CFLAGS += $(CCVERBOSE) LDFLAGS += -Ndrv/dld -Nmisc/mac -Nmisc/dls .KEEP_STATE: def: $(DEF_DEPS) all: $(ALL_DEPS) clean: $(CLEAN_DEPS) clobber: $(CLOBBER_DEPS) install: $(INSTALL_DEPS) ``` -------------------------------- ### Configure 'Makefile' for New Command Source: https://illumos.org/books/dev/anatomy.html This snippet shows the content of the 'Makefile' for the 'gethrtime' command. It defines the program name and includes common build system makefiles ('Makefile.cmd', 'Makefile.targ') to handle the build process. The 'all' and 'install' targets leverage these included makefiles for building and installing the program. ```makefile # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2013 Joyent, Inc. All rights reserved. # PROG = gethrtime include ../Makefile.cmd all: $(PROG) install: all $(ROOTPROG) clean: include ../Makefile.targ ``` -------------------------------- ### Architecture-Specific Makefile Configuration Source: https://illumos.org/books/dev/anatomy.html Specific Makefile implementations for i386 and amd64 architectures. These files include common build logic and define installation targets for libraries and lint files. ```makefile # i386/Makefile include ../Makefile.com install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT) ``` ```makefile # amd64/Makefile include ../Makefile.com include ../../Makefile.lib.64 install: all $(ROOTLIBS64) $(ROOTLINKS64) $(ROOTLINT64) ``` -------------------------------- ### Standard Library Top-level Makefile Structure Source: https://illumos.org/books/dev/anatomy.html An example of a top-level library Makefile in the illumos source tree, including the required CDDL license header. This file serves as the entry point for building specific libraries like libpcidb. ```makefile # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # ``` -------------------------------- ### Traverse kernel data structures Source: https://illumos.org/books/dev/debugging.html Demonstrates using mdb walkers and the print command to iterate through kernel process structures and display specific fields. ```mdb $ mdb -k Loading modules: [ unix genunix specfs dtrace mac cpu.generic uppc apix scsi_vhci ufs ip hook neti sockfs arp usba stmf_sbd stmf zfs lofs mpt idm crypto random cpc logindmux ptm kvm sppp nsmb smbsrv nfs sd ipc ] > ::walk proc | ::print proc_t p_user.u_comm p_user.u_comm = [ "sched" ] p_user.u_comm = [ "zpool-zones" ] p_user.u_comm = [ "fsflush" ] p_user.u_comm = [ "pageout" ] p_user.u_comm = [ "init" ] p_user.u_comm = [ "lldpd" ] p_user.u_comm = [ "nscd" ] p_user.u_comm = [ "devfsadm" ] p_user.u_comm = [ "syseventd" ] p_user.u_comm = [ "powerd" ] p_user.u_comm = [ "pfexecd" ] p_user.u_comm = [ "dlmgmtd" ] p_user.u_comm = [ "ipmgmtd" ] p_user.u_comm = [ "svc.configd" ] p_user.u_comm = [ "svc.startd" ] p_user.u_comm = [ "login" ] p_user.u_comm = [ "bash" ] p_user.u_comm = [ "mdb" ] p_user.u_comm = [ "ttymon" ] > ``` -------------------------------- ### Architecture-Specific Makefile for amd64 and sparcv9 Source: https://illumos.org/books/dev/anatomy.html This Makefile snippet is intended for 64-bit architectures like amd64 and sparcv9. It includes common build configurations and copyright information, but the specific installation logic might differ from 32-bit targets. ```makefile # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2013 Joyent, Inc. All rights reserved. ``` -------------------------------- ### Search processes with pgrep Source: https://illumos.org/books/dev/debugging.html Demonstrates how to use the pgrep utility to locate process IDs based on name matching, including exact matches and selecting the oldest or newest instances. ```shell $ pgrep sh 24388 68672 78935 24957 68544 24761 22363 68540 68541 22347 22348 $ pgrep -x bash 68672 68544 22363 $ pgrep -o sh 78935 $ pgrep -n sh 22363 ``` -------------------------------- ### Test System Core Dump Configuration Source: https://illumos.org/books/dev/debugging.html This snippet demonstrates how to verify that core dumps are enabled on the system. It involves creating a C program that triggers an abort, compiling it, and confirming the generation of a core file in the current directory. ```c #include int main(void) { abort(); return (0); } ``` ```shell $ gcc -o abort abort.c $ ./abort Abort (core dumped) $ ls core.abort.* ``` -------------------------------- ### Inspect open files with pfiles Source: https://illumos.org/books/dev/debugging.html Demonstrates the use of pfiles to list open file descriptors for a specific process. This command provides detailed information about file types, modes, and associated paths or sockets. ```shell $ pfiles $$ 68544: -bash Current rlimit: 65536 file descriptors 0: S_IFCHR mode:0620 dev:533,1 ino:4243104526 uid:1002 gid:7 rdev:6,25 O_RDWR|O_NOCTTY|O_LARGEFILE /dev/pts/25 offset:113761 1: S_IFCHR mode:0620 dev:533,1 ino:4243104526 uid:1002 gid:7 rdev:6,25 O_RDWR|O_NOCTTY|O_LARGEFILE /dev/pts/25 offset:113761 2: S_IFCHR mode:0620 dev:533,1 ino:4243104526 uid:1002 gid:7 rdev:6,25 O_RDWR|O_NOCTTY|O_LARGEFILE /dev/pts/25 offset:113761 3: S_IFDOOR mode:0444 dev:542,0 ino:413 uid:0 gid:0 rdev:541,0 O_RDONLY|O_LARGEFILE FD_CLOEXEC door to nscd[92307] /var/run/name_service_door 255: S_IFCHR mode:0620 dev:533,1 ino:4243104526 uid:1002 gid:7 rdev:6,25 O_RDWR|O_NOCTTY|O_LARGEFILE FD_CLOEXEC /dev/pts/25 offset:113761 ``` -------------------------------- ### Disassemble instructions at the instruction pointer Source: https://illumos.org/books/dev/debugging.html Uses the mdb disassembler to inspect machine code starting at the current instruction pointer (eip). This is useful for identifying the specific instruction that caused a crash. ```mdb $ mdb core.abort.54117 Loading modules: [ libc.so.1 ld.so.1 ] > libc.so.1`_lwp_kill+5: popl %edx libc.so.1`_lwp_kill+6: movl $0xa3,%eax libc.so.1`_lwp_kill+0xb: movl %esp,%ecx libc.so.1`_lwp_kill+0xd: addl $0x10,%edx libc.so.1`_lwp_kill+0x13: sysenter libc.so.1`_lwp_kill+0x15: jae +0xc libc.so.1`_lwp_kill+0x17: cmpl $0x5b,%eax libc.so.1`_lwp_kill+0x1a: jne +0x9 libc.so.1`_lwp_kill+0x1c: movl $0x4,%eax libc.so.1`_lwp_kill+0x21: jmp +0x2 libc.so.1`_lwp_kill+0x23: xorl %eax,%eax libc.so.1`_lwp_kill+0x25: ret > ``` -------------------------------- ### Create Command Directory and Files Source: https://illumos.org/books/dev/anatomy.html This snippet shows the initial steps to create a new command. It involves navigating to the 'cmd' directory, creating a new subdirectory for the command, and copying prototype files for the Makefile and the C source code. ```shell $ cd cmd $ mkdir gethrtime $ cd gethrtime $ cp ../../prototypes/prototype.Makefile Makefile $ cp ../../prototypes/prototype.c gethrtime.c $ ``` -------------------------------- ### Building Native Programs with Makefile (Make) Source: https://illumos.org/books/dev/anatomy.html Illustrates how to build a native program using a Makefile. It highlights the use of `NATIVECC` for the native compiler and ensures that linker flags (`LDLIBS`) correctly point to the build system's libraries and headers, not the target system's. ```makefile maketab: maketab.c $(NATIVECC) -O maketab.c -o $@ $(LDLIBS) proctab.c: maketab rm -f $@; ./maketab > $@ ``` -------------------------------- ### Initialize mdb debugger with a crash dump Source: https://illumos.org/books/dev/debugging.html This command starts the mdb debugger and loads a specified crash dump file for analysis. The number following 'mdb' typically corresponds to the dump file index. ```shell # mdb 2 ``` -------------------------------- ### Build and Test the New Command Source: https://illumos.org/books/dev/anatomy.html This snippet demonstrates how to build and test the newly created 'gethrtime' command. It involves navigating to the command's directory, using 'dmake' to build the program, checking the exit status, and then executing the command to verify its output. ```shell $ cd cmd/gethrtime $ dmake ... $ echo $? 0 $ ./gethrtime # The output will be different for everyone 40274477601353 $ ``` -------------------------------- ### Committing Selected Files with Git Source: https://illumos.org/books/dev/workflow.html This example shows how to commit only specific files to your local git repository. This is useful for making granular commits and tracking changes to individual components. The command targets a single file for commitment. ```shell $ git commit cmd/mdb/common/mdb/mdb_typedef.c ``` -------------------------------- ### Initialize New Library Directory Structure Source: https://illumos.org/books/dev/anatomy.html Shell commands to create the standard directory hierarchy for a new library in the Illumos source tree, including common and ISA-specific subdirectories. ```bash cd usr/src/lib mkdir libsolo cd libsolo mkdir common i386 amd64 sparc sparcv9 ``` -------------------------------- ### Configure libsolo Build with Makefile.com Source: https://illumos.org/books/dev/anatomy.html Sets up the build configuration for the libsolo library using 'Makefile.com'. This file specifies the library name, version, object files, and includes common build rules from 'Makefile.lib' and 'Makefile.targ'. It also defines linker flags, including the C library. ```makefile LIBRARY = libsolo.a VERS = .1 OBJECTS = solo.o include ../../Makefile.lib LIBS = $(DYNLIB) $(LINTLIB) SRCDIR = ../common LDLIBS += -lc .KEEP_STATE: all: $(LIBS) include ../../Makefile.targ ``` -------------------------------- ### Example of a C Code Compilation Failure in Illumos Source: https://illumos.org/books/dev/debugging.html This output demonstrates a typical C code compilation error during an Illumos build. It shows the compiler command (`cw` and `gcc`) that was executed, followed by the specific error message from the compiler indicating an undeclared variable. The error message format is standard for GCC-based compilers. ```text $ dmake -m serial install /home/rm/src/bardiche/projects/illumos/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/i386/cw -_gcc -m64 -Ui386 -U__i386 -xO3 -_gcc=-fno-inline-small-functions -_gcc=-fno-inline-functions-called-once ../../intel/amd64/ml/amd64.il -D_ASM_INLINES -Xa -xspace -xmodel=kernel -_gcc=-mno-mmx -_gcc=-mno-sse -Wu,-save_args -v -xildoff -g -xc99=%all -W0,-noglobal -Wu,-save_args -xdebugformat=stabs -errtags=yes -errwarn=%all -_gcc=-Wno-address -_gcc=-Wno-missing-braces -_gcc=-Wno-sign-compare -_gcc=-Wno-unknown-pragmas -_gcc=-Wno-unused-parameter -_gcc=-Wno-missing-field-initializers -_gcc=-Wno-parentheses -_gcc=-Wno-unused-label -_gcc=-Wno-uninitialized -_gcc=-Wno-unused-function -_gcc=-fno-inline-small-functions -_gcc=-fno-inline-functions-called-once -_gcc=-fno-ipa-cp -W0,-xglobalstatic -xstrconst -v -D_KERNEL -D_SYSCALL32 -D_SYSCALL32_IMPL -D_ELF64 -D_DDI_STRICT -Dsun -D__sun -D__SVR4 -DDEBUG -I../../intel -I../../common/fs/zfs -I../../common/io/bpf -Y I,../../common -c -o debug64/sdev_plugin.o ../../common/fs/dev/sdev_plugin.c + /home/rm/src/bardiche/proto.strap/usr/bin/gcc -fident -finline -fno-inline-functions -fno-builtin -fno-asm -fdiagnostics-show-option -nodefaultlibs -D__sun -m64 -mtune=opteron -Ui386 -U__i386 -fno-strict-aliasing -fno-unit-at-a-time -fno-optimize-sibling-calls -O2 -fno-inline-small-functions -fno-inline-functions-called-once -D_ASM_INLINES -ffreestanding -mno-red-zone -mno-mmx -mno-sse -msave-args -Wall -Wextra -gdwarf-2 -std=gnu99 -msave-args -Werror -Wno-address -Wno-missing-braces -Wno-sign-compare -Wno-unknown-pragmas -Wno-unused-parameter -Wno-missing-field-initializers -Wno-parentheses -Wno-unused-label -Wno-uninitialized -Wno-unused-function -fno-inline-small-functions -fno-inline-functions-called-once -fno-ipa-cp -D_KERNEL -ffreestanding -D_SYSCALL32 -D_SYSCALL32_IMPL -D_ELF64 -D_DDI_STRICT -Dsun -D__sun -D__SVR4 -DDEBUG -I../../intel -I../../common/fs/zfs -I../../common/io/bpf -nostdinc -I../../common -c -o debug64/sdev_plugin.o ../../common/fs/dev/sdev_plugin.c -mcmodel=kernel ../../common/fs/dev/sdev_plugin.c: In function 'sdev_plugin_vop_readdir': ../../common/fs/dev/sdev_plugin.c:325: error: 'sp' undeclared (first use in this function) ../../common/fs/dev/sdev_plugin.c:325: error: (Each undeclared identifier is reported only once ../../common/fs/dev/sdev_plugin.c:325: error: for each function it appears in.) *** Error code 1 make: Fatal error: Command failed for target `debug64/sdev_plugin.o' Current working directory /home/rm/src/bardiche/projects/illumos/usr/src/uts/intel/dev *** Error code 1 The following command caused the error: BUILD_TYPE=DBG64 VERSION='joyent_20130918T033911Z' /home/rm/src/bardiche/proto.strap/usr/bin/dmake install.targ make: Fatal error: Command failed for target `install.debug64' Current working directory /home/rm/src/bardiche/projects/illumos/usr/src/uts/intel/dev ``` -------------------------------- ### Create Illumos Kernel Module Directory and Files Source: https://illumos.org/books/dev/anatomy.html This snippet demonstrates the shell commands to create the necessary directory structure and the source/configuration files for a new Illumos kernel module. It assumes the user is in the usr/src directory. ```shell $ cd usr/src $ mkdir uts/common/io/nr $ cat > uts/common/io/nr/nr.c < uts/common/io/nr/nr.conf <