Skip to content

zig objcopy: --only-section stopped working as expected #25196

@patryk4815

Description

@patryk4815

Zig Version

0.15.1

Steps to Reproduce and Observed Behavior

cat << EOF > example.S
.section .text
.global _start
_start:
mov x0, 1
EOF

zig cc -target aarch64-freestanding -O0 example.S -o example.elf
zig objcopy -O binary --only-section=.text example.elf example.asmbin

On zig 0.15.1 output file example.asmbin contains all sections somehow:

$  hexdump -C example.asmbin
00000000  20 00 80 d2 74 00 00 00  04 00 00 00 00 00 08 01  | ...t...........|
00000010  00 00 00 00 20 01 01 01  00 00 00 00 24 01 01 01  |.... .......$...|
*
00000080  17 11 01 12 01 03 08 1b  08 25 08 13 05 00 00 02  |.........%......|
00000090  0a 00 03 08 3a 06 3b 06  11 01 00 00 00 2c 00 00  |....:.;......,..|
000000a0  00 02 00 00 00 00 00 08  00 00 00 00 00 20 01 01  |............. ..|
000000b0  01 00 00 00 00 04 00 00  00 00 00 00 00 00 00 00  |................|
000000c0  00 00 00 00 00 00 00 00  00 00 00 00 00 38 00 00  |.............8..|
000000d0  00 04 00 21 00 00 00 01  01 01 fb 0e 0d 00 01 01  |...!............|
000000e0  01 01 00 00 00 01 00 00  01 00 65 78 61 6d 70 6c  |..........exampl|
000000f0  65 2e 53 00 00 00 00 00  00 09 02 20 01 01 01 00  |e.S........ ....|
00000100  00 00 00 15 02 04 00 01  01 4c 69 6e 6b 65 72 3a  |.........Linker:|
00000110  20 4c 4c 44 20 32 30 2e  31 2e 38 00 00 00 00 00  | LLD 20.1.8.....|
00000120  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  10 00 00 00 10 00 01 00  20 01 01 01 00 00 00 00  |........ .......|
000001c0  00 00 00 00 00 00 00 00  00 2e 74 65 78 74 00 2e  |..........text..|
000001d0  64 65 62 75 67 5f 69 6e  66 6f 00 2e 64 65 62 75  |debug_info..debu|
000001e0  67 5f 61 62 62 72 65 76  00 2e 64 65 62 75 67 5f  |g_abbrev..debug_|
000001f0  61 72 61 6e 67 65 73 00  2e 64 65 62 75 67 5f 6c  |aranges..debug_l|
00000200  69 6e 65 00 2e 63 6f 6d  6d 65 6e 74 00 2e 73 79  |ine..comment..sy|
00000210  6d 74 61 62 00 2e 73 68  73 74 72 74 61 62 00 2e  |mtab..shstrtab..|
00000220  73 74 72 74 61 62 00 00  24 78 00 24 64 00 24 64  |strtab..$x.$d.$d|
00000230  00 24 64 00 24 64 00 5f  73 74 61 72 74 00 00 00  |.$d.$d._start...|
00000240  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000320

Expected Behavior

But on zig 0.14.1 output is:

$ hexdump -C example.asmbin
00000000  20 00 80 d2                                       | ...|
00000004

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions