### Configure Zlib Example Binaries Source: https://github.com/git/binutils-gdb/blob/master/zlib/CMakeLists.txt Conditionally builds example executables like 'example' and 'minigzip' with support for 64-bit file offsets if the platform supports it. ```cmake if(ZLIB_BUILD_EXAMPLES) add_executable(example test/example.c) target_link_libraries(example zlib) add_test(example example) add_executable(minigzip test/minigzip.c) target_link_libraries(minigzip zlib) if(HAVE_OFF64_T) add_executable(example64 test/example.c) target_link_libraries(example64 zlib) set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") add_test(example64 example64) endif() endif() ``` -------------------------------- ### Linker Script for Section Garbage Collection Source: https://github.com/git/binutils-gdb/blob/master/ld/testsuite/ld-elf/pr25490-4-16.rd This example shows a linker script configuration using '--gc-sections' to enable garbage collection of unused sections. It also specifies the entry point '_start' for the executable. ```linker-script #ld: --gc-sections -e _start ``` -------------------------------- ### GDB Basic Usage Source: https://context7.com/git/binutils-gdb/llms.txt This section covers fundamental GDB commands for debugging C, C++, and other programs. It includes starting GDB, setting breakpoints, running the program, stepping through code, inspecting variables, and exiting the debugger. ```APIDOC ## GDB Basic Usage ### Description This section covers fundamental GDB commands for debugging C, C++, and other programs. It includes starting GDB, setting breakpoints, running the program, stepping through code, inspecting variables, and exiting the debugger. ### Method N/A (Command-line tool) ### Endpoint N/A (Command-line tool) ### Parameters N/A (Command-line tool) ### Request Example ```bash gdb ./myprogram (gdb) break main (gdb) run ``` ### Response N/A (Interactive session) ``` -------------------------------- ### BFD Library C Example for Binary Analysis Source: https://context7.com/git/binutils-gdb/llms.txt A C program demonstrating the use of the BFD (Binary File Descriptor) library to open, inspect, and read information from object files. It shows how to initialize BFD, open files, check formats, retrieve file metadata, iterate through sections, and read symbol tables and section contents. ```c #include #include int main(int argc, char **argv) { bfd *abfd; // Initialize BFD library bfd_init(); // Open object file abfd = bfd_openr(argv[1], NULL); // NULL = auto-detect format if (!abfd) { bfd_perror("bfd_openr"); return 1; } // Check file format if (!bfd_check_format(abfd, bfd_object)) { fprintf(stderr, "Not an object file\n"); bfd_close(abfd); return 1; } // Print basic info printf("File: %s\n", bfd_get_filename(abfd)); printf("Format: %s\n", bfd_get_target(abfd)); printf("Architecture: %s\n", bfd_printable_arch_mach(bfd_get_arch(abfd), bfd_get_mach(abfd))); printf("Start address: 0x%lx\n", (unsigned long)bfd_get_start_address(abfd)); // Iterate through sections asection *section; printf("\nSections:\n"); for (section = abfd->sections; section; section = section->next) { printf(" %-20s VMA: 0x%08lx Size: 0x%lx Flags: 0x%x\n", bfd_section_name(section), (unsigned long)bfd_section_vma(section), (unsigned long)bfd_section_size(section), (unsigned int)bfd_section_flags(section)); } // Read symbol table long storage_needed = bfd_get_symtab_upper_bound(abfd); if (storage_needed > 0) { asymbol **symbol_table = malloc(storage_needed); long num_symbols = bfd_canonicalize_symtab(abfd, symbol_table); printf("\nSymbols (%ld):\n", num_symbols); for (long i = 0; i < num_symbols; i++) { asymbol *sym = symbol_table[i]; printf(" 0x%08lx %c %s\n", (unsigned long)bfd_asymbol_value(sym), bfd_decode_symclass(sym), bfd_asymbol_name(sym)); } free(symbol_table); } // Read section contents asection *text = bfd_get_section_by_name(abfd, ".text"); if (text) { bfd_size_type size = bfd_section_size(text); bfd_byte *contents = malloc(size); if (bfd_get_section_contents(abfd, text, contents, 0, size)) { printf("\n.text section first 32 bytes:\n "); for (int i = 0; i < 32 && i < size; i++) printf("%02x ", contents[i]); printf("\n"); } free(contents); } bfd_close(abfd); return 0; } // Compile with: gcc -o bfd_example bfd_example.c -lbfd -liberty -lz ``` -------------------------------- ### CMake Build Configuration for zlib Source: https://github.com/git/binutils-gdb/blob/master/zlib/CMakeLists.txt This snippet shows the core CMake commands for configuring the zlib build. It sets the minimum CMake version, project name, version, and installation directories for executables, libraries, headers, man pages, and pkgconfig files. It also includes CMake modules for checking system features. ```cmake cmake_minimum_required(VERSION 2.4.4...3.15.0) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) project(zlib C) set(VERSION "1.3.1") option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON) set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages") set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") include(CheckTypeSize) include(CheckFunctionExists) include(CheckIncludeFile) include(CheckCSourceCompiles) enable_testing() ``` -------------------------------- ### Configure Binutils for ARM Embedded Cross-Compilation (Bash) Source: https://context7.com/git/binutils-gdb/llms.txt Configures the Binutils build system for cross-compiling tools for an ARM embedded target (arm-none-eabi). It specifies the target architecture, installation prefix, and enables specific features like interworking and multilib support, while using GNU assembler and linker. ```bash # Configure for ARM embedded target ./configure \ --target=arm-none-eabi \ --prefix=/opt/arm-toolchain \ --enable-interwork \ --enable-multilib \ --with-gnu-as \ --with-gnu-ld \ --disable-nls ``` -------------------------------- ### Configure GDB for AArch64 Linux Cross-Debugging (Bash) Source: https://context7.com/git/binutils-gdb/llms.txt Configures the GDB build system for cross-debugging AArch64 Linux targets from an x86_64 host. It sets the host and target systems, installation prefix, Python support, and enables all target architectures, along with Expat and zlib support. ```bash # Configure for AArch64 Linux cross-debugging ./configure \ --host=x86_64-linux-gnu \ --target=aarch64-linux-gnu \ --prefix=/opt/aarch64-gdb \ --with-python=/usr/bin/python3 \ --enable-targets=all \ --with-expat \ --with-system-zlib ``` -------------------------------- ### Include zlib and Standard C Headers Source: https://github.com/git/binutils-gdb/blob/master/zlib/examples/zlib_how.html This snippet demonstrates the necessary header files required to perform file I/O and zlib compression operations. It includes standard libraries for input/output, string manipulation, assertions, and the zlib library itself. ```c #include #include #include #include "zlib.h" ``` -------------------------------- ### Get Decompression Efficiency Property Source: https://github.com/git/binutils-gdb/blob/master/zlib/old/visual-basic.txt A getter property that returns the private variable representing the percentage reduction in file size. ```vba Public Property Get lngPercentSmaller() As Long lngPercentSmaller = lngpvtPcnSml End Property ``` -------------------------------- ### Initialize zlib Compression State (C) Source: https://github.com/git/binutils-gdb/blob/master/zlib/examples/zlib_how.html Initializes the zlib compression state using deflateInit. This function sets up the necessary structures for compression and checks for errors. It requires the zlib library and handles memory allocation and version compatibility. ```c strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; ret = deflateInit(&strm, level); if (ret != Z_OK) return ret; ``` -------------------------------- ### Manage Output Buffer for Deflate Source: https://github.com/git/binutils-gdb/blob/master/zlib/examples/zlib_how.html Sets the output buffer parameters for the deflate function. It specifies the size of the output buffer (CHUNK) and a pointer to the output buffer's starting location. ```c strm.avail_out = CHUNK; strm.next_out = out; ``` -------------------------------- ### File Compression Utility in Visual Basic Source: https://github.com/git/binutils-gdb/blob/master/zlib/old/visual-basic.txt A wrapper implementation for file compression using Zlib, demonstrating how to handle buffer sizing and file I/O in Visual Basic. ```Visual Basic Private Declare Function lngfncCpr Lib "zlib.dll" Alias "compress2" (ByRef dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long, ByVal level As Integer) As Long Public Sub subCompressFile(ByVal strargOriFilPth As String, Optional ByVal strargCprFilPth As String, Optional ByVal intLvl As Integer = 9) Dim lngOriSiz As Long, lngCprSiz As Long Dim bytaryOri() As Byte, bytaryCpr() As Byte lngOriSiz = FileLen(strargOriFilPth) ReDim bytaryOri(lngOriSiz - 1) Open strargOriFilPth For Binary Access Read As #1 Get #1, , bytaryOri() Close #1 lngCprSiz = (lngOriSiz * 1.01) + 12 ReDim bytaryCpr(lngCprSiz - 1) If lngfncCpr(bytaryCpr(0), lngCprSiz, bytaryOri(0), lngOriSiz, intLvl) = 0 Then ReDim Preserve bytaryCpr(lngCprSiz - 1) Open strargCprFilPth For Binary Access Write As #1 Put #1, , bytaryCpr() Put #1, , lngOriSiz Close #1 End If End Sub ``` -------------------------------- ### GNU Linker (ld) Command-Line Usage Source: https://context7.com/git/binutils-gdb/llms.txt Demonstrates various command-line options for the GNU Linker (ld) to combine object files, create executables and shared libraries, manage symbols, and apply security options. It covers basic linking, entry point specification, library inclusion, shared library creation, position-independent code, linker scripts, and symbol stripping. ```bash # Basic linking ld -o program main.o utils.o -lc # Link with specific entry point ld -e main -o program main.o # Link with libraries ld -o program main.o -L/usr/lib -lm -lpthread # Create shared library ld -shared -o libfoo.so foo.o bar.o ld -shared -soname libfoo.so.1 -o libfoo.so.1.0 foo.o # Create position-independent executable ld -pie -o program main.o # Create relocatable output (partial linking) ld -r -o combined.o file1.o file2.o # Use linker script ld -T linker.ld -o program main.o # Static vs dynamic linking ld -Bstatic -lfoo -Bdynamic -lbar -o program main.o # Only link needed libraries ld --as-needed -o program main.o -lunused -lused # Include all archive members ld --whole-archive libfoo.a --no-whole-archive -o program main.o # Garbage collection of unused sections ld --gc-sections -o program main.o ld --gc-sections --print-gc-sections -o program main.o # Generate map file ld -Map=program.map -o program main.o # Strip symbols ld -s -o program main.o # Strip all ld -S -o program main.o # Strip debug only # Set section addresses ld -Ttext=0x400000 -Tdata=0x600000 -o program main.o # Define symbol ld --defsym=VERSION=0x100 -o program main.o # Trace symbol resolution ld -y printf -o program main.o -lc # Security options ld -z relro -z now -o program main.o # Full RELRO ld -z noexecstack -o program main.o # Non-executable stack # Version script for symbol versioning ld --version-script=libfoo.map -shared -o libfoo.so foo.o # Example version script (libfoo.map): # LIBFOO_1.0 { # global: foo_init; foo_process; # local: *; # }; # Print supported targets ld --help ld -V ``` -------------------------------- ### Initialize Compression State and Read Input Source: https://github.com/git/binutils-gdb/blob/master/zlib/examples/zlib_how.html Initializes the compression stream and reads data from the source file. It checks for end-of-file and sets the appropriate flush mode for the deflate function. Error handling for file reading is included. ```c strm.avail_in = fread(in, 1, CHUNK, source); if (ferror(source)) { (void)deflateEnd(&strm); return Z_ERRNO; } flush = feof(source) ? Z_FINISH : Z_NO_FLUSH; strm.next_in = in; ``` -------------------------------- ### C Recursive Factorial Function for GDB Analysis Source: https://github.com/git/binutils-gdb/blob/master/gdb/doc/stack_frame.txt This C code defines a recursive function to calculate the factorial of a non-negative integer. It's commonly used in debugging examples to demonstrate stack frame behavior, including function calls, parameter passing (n), and return values (f). The main function iterates through numbers 0 to 9, calculating and printing their factorials. ```c int fact (int n) { if (0 == n) { return 1; } else { return n * fact (n - 1); } } main () { int i; for (i = 0; i < 10; i++) { int f = fact (i); printf ("%d! = %d\n", i , f); } } ``` -------------------------------- ### Analyze PROGBITS Section with readelf Source: https://github.com/git/binutils-gdb/blob/master/ld/testsuite/ld-elf/pr25490-5-32.rd This snippet demonstrates how to use the 'readelf' tool to analyze the '__patchable_function_entries' section. It specifies linker flags like '--gc-sections' and '-e _start' for section garbage collection and entry point definition. The output format from 'readelf' is '-SW', which shows section header information. ```shell #source: pr25490-5.s #ld: --gc-sections -e _start #readelf: -SW #... +[ *[0-9]+] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+8 +00 +WAL +[0-9] +0 +[1248] ``` -------------------------------- ### Encode SFrame Data with libsframe (C) Source: https://context7.com/git/binutils-gdb/llms.txt Demonstrates encoding SFrame stack trace data using the libsframe API. It shows how to create an encoder context, add function descriptors and frame row entries, and then serialize the data into a buffer. Requires the sframe-api.h header. ```c #include #include #include // Create SFrame data void encode_sframe_example(void) { int err; sframe_encoder_ctx *encoder; // Create encoder encoder = sframe_encode( SFRAME_VERSION_2, // Version SFRAME_F_FDE_SORTED, // Flags SFRAME_ABI_AMD64_ENDIAN_LITTLE, // ABI/Arch -8, // Fixed FP offset (from CFA) -8, // Fixed RA offset (from CFA) &err ); if (!encoder) { fprintf(stderr, "sframe_encode failed: %s\n", sframe_errmsg(err)); return; } // Add function descriptor uint8_t func_info = sframe_fde_create_func_info( SFRAME_FRE_TYPE_ADDR4, // 4-byte FRE addresses SFRAME_FDE_TYPE_PCINC // PC-relative FDEs ); err = sframe_encoder_add_funcdesc_v2(encoder, 0x401000, // Function start address 0x100, // Function size func_info, 0, // Rep block size (0 = none) 3 // Number of FREs ); // Add Frame Row Entries sframe_frame_row_entry fre = {0}; fre.fre_start_addr = 0; fre.fre_info = 0x01; // CFA = RSP + offset // Set offsets in fre_datawords... sframe_encoder_add_fre(encoder, 0, &fre); // Serialize to buffer size_t encoded_size; char *output = sframe_encoder_write(encoder, &encoded_size, true, &err); if (output) { printf("Encoded SFrame: %zu bytes\n", encoded_size); // Write to file or use in linking... free(output); } sframe_encoder_free(&encoder); } ``` -------------------------------- ### Decode SFrame Data with libsframe (C) Source: https://context7.com/git/binutils-gdb/llms.txt Demonstrates decoding SFrame stack trace data from a buffer using the libsframe API. It shows how to initialize a decoder, retrieve header information, iterate through function descriptors, and find frame row entries for a specific program counter. Requires the sframe-api.h header. ```c #include #include #include // Decode SFrame data from a buffer void decode_sframe_example(const char *sframe_buf, size_t size) { int err; sframe_decoder_ctx *decoder; // Create decoder from buffer decoder = sframe_decode(sframe_buf, size, &err); if (!decoder) { fprintf(stderr, "sframe_decode failed: %s\n", sframe_errmsg(err)); return; } // Get header information printf("SFrame Version: %u\n", sframe_decoder_get_version(decoder)); printf("ABI/Arch: %u\n", sframe_decoder_get_abi_arch(decoder)); printf("Flags: 0x%x\n", sframe_decoder_get_flags(decoder)); printf("Number of FDEs: %u\n", sframe_decoder_get_num_fidx(decoder)); printf("Fixed FP offset: %d\n", sframe_decoder_get_fixed_fp_offset(decoder)); printf("Fixed RA offset: %d\n", sframe_decoder_get_fixed_ra_offset(decoder)); // Iterate through function descriptors uint32_t num_funcs = sframe_decoder_get_num_fidx(decoder); for (uint32_t i = 0; i < num_funcs; i++) { uint32_t num_fres, func_size; int64_t func_start; uint8_t func_info; uint32_t rep_size; err = sframe_decoder_get_funcdesc_v2(decoder, i, &num_fres, &func_size, &func_start, &func_info, &rep_size); if (err) { fprintf(stderr, "Error getting FDE %u: %s\n", i, sframe_errmsg(err)); continue; } printf("\nFunction %u: start=0x%lx, size=%u, FREs=%u\n", i, (unsigned long)func_start, func_size, num_fres); // Get Frame Row Entries for this function for (uint32_t j = 0; j < num_fres; j++) { sframe_frame_row_entry fre; err = sframe_decoder_get_fre(decoder, i, j, &fre); if (err) continue; int32_t cfa_off = sframe_fre_get_cfa_offset(decoder, &fre, func_info & 0xf, &err); printf(" FRE[%u]: CFA offset=%d\n", j, cfa_off); } } // Find FRE for specific PC sframe_frame_row_entry fre; int64_t target_pc = 0x401100; if (sframe_find_fre(decoder, target_pc, &fre) == 0) { printf("\nFound FRE for PC 0x%lx\n", (unsigned long)target_pc); } sframe_decoder_free(&decoder); } ``` -------------------------------- ### Miscellaneous Instruction Extensions Source: https://github.com/git/binutils-gdb/blob/master/opcodes/s390-opc.txt Instructions for counting leading/trailing zeros and loading indexed addresses. ```APIDOC ## RRE_RR CLZ ### Description Count leading zeros. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RRE_RR CTZ ### Description Count trailing zeros. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RXY_RRRD LXAB ### Description Load indexed address (shift left 0). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RXY_RRRD LXAH ### Description Load indexed address (shift left 1). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RXY_RRRD LXAF ### Description Load indexed address (shift left 2). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RXY_RRRD LXAG ### Description Load indexed address (shift left 3). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RXY_RRRD Lxaq ### Description Load indexed address (shift left 4). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RXY_RRRD LLXAB ### Description Load logical indexed address (shift left 0). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RXY_RRRD LLXAH ### Description Load logical indexed address (shift left 1). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RXY_RRRD LLXAF ### Description Load logical indexed address (shift left 2). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RXY_RRRD LLXAG ### Description Load logical indexed address (shift left 3). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RXY_RRRD LLXAQ ### Description Load logical indexed address (shift left 4). ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RRF_R0RR2 BEXTG ### Description Bit extract. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## RRF_R0RR2 BDEPG ### Description Bit deposit. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Vector Pack Logical Saturate Instructions Source: https://github.com/git/binutils-gdb/blob/master/opcodes/s390-opc.txt Instructions for packing vector data with logical saturation. ```APIDOC ## Vector Pack Logical Saturate Instructions ### Description These instructions pack vector data with logical saturation, supporting different data sizes (halfword, word, double word). ### Method N/A (These are assembly instructions) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## vpklshs VRR_VVV "vector pack logical saturate halfword" ## vpklsfs VRR_VVV "vector pack logical saturate word" ## vpklsgs VRR_VVV "vector pack logical saturate double word" ``` -------------------------------- ### Zlib Deflate Error Checking and Output Handling Source: https://github.com/git/binutils-gdb/blob/master/zlib/examples/zlib_how.html This snippet demonstrates checking the return value of the deflate() function and handling potential errors like Z_STREAM_ERROR. It also shows how to calculate the amount of output produced and write it to a file, managing buffer reuse. ```c ret = deflate(&strm, flush); /* no bad return value */ assert(ret != Z_STREAM_ERROR); /* state not clobbered */ have = CHUNK - strm.avail_out; if (fwrite(out, 1, have, dest) != have || ferror(dest)) { (void)deflateEnd(&strm); return Z_ERRNO; } ``` -------------------------------- ### GDB Machine Interface (MI) Commands Source: https://context7.com/git/binutils-gdb/llms.txt Interact with GDB programmatically using the Machine Interface (MI). This provides a structured, text-based protocol for IDEs and scripting. Commands are prefixed with '-' and responses are structured with '^', '*', or '~' prefixes. ```bash # Start GDB with MI interface gdb -i=mi ./myprogram # MI commands and responses -file-exec-and-symbols ./myprogram ^done -break-insert main ^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00401150",func="main",file="main.c",line="10"} -exec-run ^running *stopped,reason="breakpoint-hit",bkptno="1",frame={addr="0x00401150",func="main",args=[],file="main.c",line="10"} -data-evaluate-expression counter ^done,value="42" -stack-list-frames ^done,stack=[frame={level="0",addr="0x00401150",func="main",file="main.c",line="10"},frame={level="1",addr="0x7f000100",func="__libc_start_main"}] -stack-list-locals --simple-values ^done,locals=[{name="i",type="int",value="0"},{name="ptr",type="char *",value="0x7fff5000"}] -var-create myvar * counter ^done,name="myvar",numchild="0",value="42",type="int" -var-update myvar ^done,changelist=[{name="myvar",value="43",in_scope="true",type_changed="false"}] -exec-step ^running *stopped,reason="end-stepping-range",frame={...} -exec-continue ^running -gdb-exit ^exit ``` -------------------------------- ### Analyze Section Flags with readelf Source: https://github.com/git/binutils-gdb/blob/master/ld/testsuite/ld-elf/pr25490-6-32.rd This snippet demonstrates how to use the `readelf -SW` command to analyze section flags in an object file. It specifically looks for the `__patchable_function_entries` section with `PROGBITS` type and `WAL` flags, indicating a pass condition in the analysis. ```assembly #source: pr25490-6.s #ld: --gc-sections -e _start #readelf: -SW #... +[ *[0-9]+] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+c +00 +WAL +[0-9] +0 +[1248] #pass ``` -------------------------------- ### Analyze Section Flags with readelf Source: https://github.com/git/binutils-gdb/blob/master/ld/testsuite/ld-elf/pr25490-4-16.rd This snippet demonstrates how to use the 'readelf -SW' command to analyze section flags in an object file. It specifically looks for the PROGBITS section with WAL flags, indicating executable or writable data. ```shell #readelf: -SW +\+\[ *[0-9]+\] __patchable_function_entries +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+4 +00 +WAL +[0-9] +0 +[1248] ``` -------------------------------- ### Vector Store Element Instructions Source: https://github.com/git/binutils-gdb/blob/master/opcodes/s390-opc.txt Instructions for storing vector elements to memory. ```APIDOC ## Vector Store Element Instructions ### Description These instructions store vector elements to memory, supporting different byte sizes. ### Method N/A (These are assembly instructions) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## vsteb VRX_VRRDU "vector store byte element" ## vsteh VRX_VRRDU "vector store halfword element" ## vstef VRX_VRRDU "vector store word element" ## vsteg VRX_VRRDU "vector store double word element" ``` -------------------------------- ### Define Zlib Library Targets and Properties Source: https://github.com/git/binutils-gdb/blob/master/zlib/CMakeLists.txt Creates shared and static library targets and applies platform-specific properties such as versioning, output naming, and linker flags. ```cmake add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) target_include_directories(zlib PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) target_include_directories(zlibstatic PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL SOVERSION 1) if(NOT CYGWIN) set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) endif() ``` -------------------------------- ### Vector Remainder Instructions Source: https://github.com/git/binutils-gdb/blob/master/opcodes/s390-opc.txt Documentation for vector remainder instructions, including quadword, logical, and word variants. ```APIDOC ## VRR_VVV0U02 VRQ ### Description Vector remainder quadword. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## VRR_VVV0UU VRL ### Description Vector remainder logical. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## VRR_VVV0U02 VRLF ### Description Vector remainder logical word. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## VRR_VVV0U02 VRLG ### Description Vector remainder logical doubleword. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` ```APIDOC ## VRR_VVV0U02 VRLQ ### Description Vector remainder logical quadword. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Basic GDB Command-Line Operations Source: https://context7.com/git/binutils-gdb/llms.txt Common commands for launching GDB, attaching to processes, and navigating debugging sessions. These commands are executed directly in the terminal or within the GDB interactive prompt. ```bash # Start GDB with an executable gdb ./myprogram # Start GDB and attach to running process gdb -p 12345 # Start GDB with core dump gdb ./myprogram core # Run program with arguments gdb --args ./myprogram arg1 arg2 # Enable TUI mode for split source/command view gdb -tui ./myprogram # Common GDB session commands (gdb) break main (gdb) run (gdb) next (gdb) step (gdb) continue (gdb) print variable (gdb) backtrace (gdb) quit ``` -------------------------------- ### Deflate Compression Routine (C) Source: https://github.com/git/binutils-gdb/blob/master/zlib/examples/zlib_how.html The 'def' routine compresses data from a source file to a destination file using zlib. It handles the entire compression process, including initialization, data processing, and flushing. The routine returns zlib status codes indicating success or failure. ```c int def(FILE *source, FILE *dest, int level) { // ... initialization code ... /* compress until end of file */ do { // ... compression logic ... } while (flush != Z_FINISH); ``` -------------------------------- ### Analyze ELF File Structure with readelf Source: https://context7.com/git/binutils-gdb/llms.txt readelf provides detailed information about ELF (Executable and Linkable Format) files, including headers, sections, symbols, and dynamic linking information. It is ELF-specific and does not use the BFD library. ```bash # Display ELF file header readelf -h program # Output: # ELF Header: # Magic: 7f 45 4c 46 02 01 01 00 ... # Class: ELF64 # Type: EXEC (Executable file) # Machine: Advanced Micro Devices X86-64 # Entry point address: 0x401050 # Display program headers (segments) readelf -l program # Output: # Program Headers: # Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align # LOAD 0x000000 0x00400000 0x00400000 0x001000 0x001000 R 0x1000 # LOAD 0x001000 0x00401000 0x00401000 0x002000 0x002000 R E 0x1000 # Display section headers readelf -S program readelf --sections program # Display symbol table readelf -s program readelf --syms program # Display dynamic symbol table readelf --dyn-syms program # Display dynamic section (shared library dependencies) readelf -d program # Output: # Dynamic section at offset 0x2f00 contains 24 entries: # Tag Type Name/Value # 0x0000001 (NEEDED) Shared library: [libc.so.6] # Display relocations readelf -r program # Display notes section readelf -n program # Display version information readelf -V program # Hex dump of section readelf -x .rodata program # String dump of section readelf -p .rodata program # Display DWARF debug info readelf -w program readelf --debug-dump=info program readelf --debug-dump=line program # Display all information readelf -a program # Wide output format readelf -W -S program ``` -------------------------------- ### int def(FILE *source, FILE *dest, int level) Source: https://github.com/git/binutils-gdb/blob/master/zlib/examples/zlib_how.html Compresses data from a source file to a destination file using zlib compression. ```APIDOC ## POST /compress ### Description Compresses data from an input file to an output file using the zlib format. The routine handles memory allocation for the zlib state and processes data in chunks. ### Method POST ### Endpoint /compress ### Parameters #### Request Body - **source** (FILE*) - Required - Pointer to the input file stream. - **dest** (FILE*) - Required - Pointer to the output file stream. - **level** (int) - Required - Compression level ranging from -1 (default) to 9. ### Request Example { "source": "input.txt", "dest": "output.zlib", "level": 6 } ### Response #### Success Response (200) - **status** (int) - Returns Z_OK (0) on success. #### Error Responses - **Z_MEM_ERROR** - Memory could not be allocated. - **Z_STREAM_ERROR** - Invalid compression level supplied. - **Z_VERSION_ERROR** - Version mismatch between zlib.h and library. - **Z_ERRNO** - File I/O error. ``` -------------------------------- ### List Symbols from Object Files with nm Source: https://context7.com/git/binutils-gdb/llms.txt nm lists symbols from object files, executables, and libraries. It displays symbol names, types, and values, which is crucial for understanding binary structure and debugging linking issues. It can also demangle C++ symbols. ```bash # List all symbols nm program # List symbols with filename prepended nm -A *.o # Sort by address nm -n program nm --numeric-sort program # Show only external (global) symbols nm -g program nm --extern-only program # Show only undefined symbols (dependencies) nm -u program nm --undefined-only program # Show only defined symbols nm -U program nm --defined-only program # Demangle C++ symbols nm -C program nm --demangle program # Show symbol sizes nm -S program # Include debug symbols nm -a program # Show dynamic symbols nm -D program nm --dynamic program # Print in different radix (d=decimal, o=octal, x=hex) nm -t x program # Show line numbers (requires debug info) nm -l program # List symbols from static library nm libfoo.a # Print archive index nm -s libfoo.a # Example output interpretation: # 0000000000401150 T main # T = text (code) section, global # 0000000000402000 D data # D = initialized data, global # 0000000000403000 B bss # B = uninitialized data (BSS) # 0000000000401000 t helper # t = text section, local # U printf # U = undefined (external reference) # 0000000000404000 R rodata # R = read-only data ``` -------------------------------- ### Vector String Search and Shift Instructions Source: https://github.com/git/binutils-gdb/blob/master/opcodes/s390-opc.txt Instructions for performing bit-level vector shifts and string searches across different element sizes, including zero-terminated search variants. ```assembly e70000000086 vsld VRI_VVV0U "vector shift left double by bit" arch13 zarch e7000000008b vstrs VRR_VVVUU0V "vector string search" arch13 zarch e7000002008b vstrszb VRR_VVV0V "vector string search byte zero" arch13 zarch ``` -------------------------------- ### Vector Floating-Point Conversion Instructions Source: https://github.com/git/binutils-gdb/blob/master/opcodes/s390-opc.txt Instructions for converting between fixed-point/logical values and floating-point formats, including specific 32-bit variants. ```assembly e700000000c3 vcfps VRR_VV0UUU "vector fp convert from fixed" arch13 zarch e700000020c3 vcefb VRR_VV0UU "vector fp convert from fixed 32 bit" arch13 zarch e700000000c0 vclfp VRR_VV0UUU "vector fp convert to logical" arch13 zarch ```