返回资讯中心
外部精选
软件工程
#社区热议

Zig v0.17.0

--all-headers Alias for --file-headers --linker-member=2 --member-headers --section-headers --relocs --symbols

Hacker NewsErenayDev2026/10/2 · 2026/10/217 分钟阅读

以下正文同步自 Hacker News,版权归原站所有,已转换为易读排版。

Usage: zig objdump [options] file

Options: -h, --help Print this help and exit --all-headers Alias for --file-headers --linker-member=2 --member-headers --section-headers --relocs --symbols --exports[=sort] Display exported symbols. In the case of COFF import libraries, displays the symbol list and import headers. Specify =sort to optionally sort the import headers by symbol name. --file-headers Display file-format specific headers --imports Display imported symbols --linker-member[=1|2|longnames] (Coff) Display contents of the specified archive linker member (default 2) --member-headers Display archive member headers --elements=[e1],[e2],-[e3],... Select which formatting elements are displayed. Intended for snapshot testing. file-type File type summary header-name Name that precedes a header block member-path Display full member paths. If removed, only basenames will be used. newlines Newlines between output sections table-header Table headers with column names all (default) All of the above --only-member=[name] Only consider archive members names that contain [name]. Can be specified multiple times. --only-section=[name] Only consider section names that contain [name]. Can be specified multiple times. --only-symbol=[name] Only consider symbol names that contain [name]. Can be specified multiple times. --redact=[kind] Redact the specified field kind. Intended for snapshot testing. rva Relative virtual addresses va Virtual addresses and file offsets ord Symbol ordinals / hints size Sizes and lengths all All of the above --relocs Display relocations -s, --snapshot Alias for --redact=all --elements=-all --section-headers Display section headers --strings Display string tables --symbols Display symbol tables --tls Display TLS information

Some example output:

❯ zig objdump mathtest-dync-exe-no-llvm.dll --all-headers mathtest-dync-exe-no-llvm.dll: PE/COFF image

COFF Header: 8664 machine (AMD64) 7 number_of_sections 6a08670a time_date_stamp 0 pointer_to_symbol_table 0 number_of_symbols f0 size_of_optional_header 2022 flags | EXECUTABLE_IMAGE | LARGE_ADDRESS_AWARE | DLL

COFF Optional Header: 20b magic (PE32+) 14.00 linker_version 14a400 size_of_code 84e00 size_of_initialized_data 0 size_of_uninitialized_data 1000 address_of_entry_point ( 180001000) 1000 base_of_code ( 180001000) 180000000 image_base 1000 section_alignment 200 file_alignment 6.00 operating_system_version 1.00 image_version 6.00 subsystem_version 0 win32_version_value 1d6000 size_of_image 400 size_of_headers 0 checksum 2 subsystem (WINDOWS_GUI) 160 dll_flags | HIGH_ENTROPY_VA | DYNAMIC_BASE | NX_COMPAT 100000 size_of_stack_reserve 1000 size_of_stack_commit 100000 size_of_heap_reserve 1000 size_of_heap_commit 0 loader_flags 10 number_of_rva_and_sizes

Data Directories: 1b48d0 54 EXPORT 1b4924 8c IMPORT 0 0 RESOURCE 1cc000 633c EXCEPTION 0 0 SECURITY 1d4000 1280 BASERELOC 1bc000 1c DEBUG 0 0 ARCHITECTURE 0 0 GLOBALPTR 1aebc8 28 TLS 0 0 LOAD_CONFIG 0 0 BOUND_IMPORT 1b4c80 2d0 IAT 0 0 DELAY_IMPORT 0 0 COM_DESCRIPTOR 0 0 RESERVED

Sections in 'mathtest-dync-exe-no-llvm.dll': Num Name RVA Virt Size Data Size & Data & Relocs & Lines # Relocs # Lines Flags 1 .text 1000 14a346 14a400 400 0 0 0 0 60000020 | CNT_CODE MEM_EXECUTE MEM_READ 2 .rdata 14c000 6fe3c 70000 14a800 0 0 0 0 40000040 | CNT_INITIALIZED_DATA MEM_READ 3 .buildid 1bc000 52 200 1ba800 0 0 0 0 40000040 | CNT_INITIALIZED_DATA MEM_READ 4 .data 1bd000 e2a0 d200 1baa00 0 0 0 0 c0000040 | CNT_INITIALIZED_DATA MEM_READ MEM_WRITE 5 .pdata 1cc000 633c 6400 1c7c00 0 0 0 0 40000040 | CNT_INITIALIZED_DATA MEM_READ 6 .tls 1d3000 20 200 1ce000 0 0 0 0 c0000040 | CNT_INITIALIZED_DATA MEM_READ MEM_WRITE 7 .reloc 1d4000 1280 1400 1ce200 0 0 0 0 42000040 | CNT_INITIALIZED_DATA MEM_DISCARDABLE MEM_READ

No symbol table found

If this output was used for a snapshot test that wanted to test the presence of a particular export:

❯ zig objdump mathtest-dync-exe-no-llvm.dll --exports --only-symbol=add --redact=rva --elements=-all Export directory: 0 flags 0 time_date_stamp 0.00 version xxxxxxxxxxxxxxxx name_rva 1 ordinal_base 1 number_of_entries 1 number_of_names xxxxxxxxxxxxxxxx export_address_table_rva xxxxxxxxxxxxxxxx name_pointer_table_rva xxxxxxxxxxxxxxxx ordinal_table_rva 1 0 xxxxxxxx | add

The redaction (--redact=) and element removal (--elements=) functionality is used to remove parts of the output that don't matter for the particular test, as to not cause spurious failures if say, an RVA for a symbol changes due to some unrelated change to the linker. -s is shorthand which enables all the redacts and removes all extra output elements, but particular tests may not use this if they do care about specific values.

Windows resource script compilation will be moved out of the compiler and into an official-but-external build system package in the next release. As such, the corresponding std.Build functions and fields (Build.Module.addWin32ResourceFile, etc) have been marked as deprecated in this release.

The zig rc subcommand will remain after this change in order to continue supporting the use case of using the Zig toolchain with other build systems.

It's a simple tool for counting tokens and AST nodes, which can be used to share how an edit to a source file increases or reduces complexity with a heuristic that is more insightful than line count.

For example, running it on old ELF linker directory:

info: src/link/Elf/gc.zig: tokens=1538 nodes=770 info: src/link/Elf/Atom.zig: tokens=15576 nodes=7768 info: src/link/Elf/Merge.zig: tokens=2288 nodes=1092 info: src/link/Elf/Thunk.zig: tokens=1128 nodes=519 info: src/link/Elf/SharedObject.zig: tokens=4566 nodes=2236 info: src/link/Elf/eh_frame.zig: tokens=4840 nodes=2335 info: src/link/Elf/Symbol.zig: tokens=3770 nodes=1872 info: src/link/Elf/synthetic_sections.zig: tokens=13287 nodes=6375 info: src/link/Elf/Object.zig: tokens=13903 nodes=6842 info: src/link/Elf/LinkerDefined.zig: tokens=4140 nodes=2091 info: src/link/Elf/relocatable.zig: tokens=3598 nodes=1848 info: src/link/Elf/Archive.zig: tokens=2176 nodes=1028 info: src/link/Elf/ZigObject.zig: tokens=20783 nodes=10274 info: src/link/Elf/AtomList.zig: tokens=1819 nodes=933 info: src/link/Elf/relocation.zig: tokens=1289 nodes=551 info: src/link/Elf/file.zig: tokens=2330 nodes=1087 info: total: tokens=97031 nodes=47621

Another example is after editing Lld.zig to use arena.print rather than std.fmt.allocPrint. The line count is roughly the same but --complexity tells a different story:

In the future this metric may be helpful for an automatic import organizer to determine whether to create an import alias or not.

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →