[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GAS bug] .asciz inserts zero byte for each string passed
From: |
Jiří Wolker |
Subject: |
[GAS bug] .asciz inserts zero byte for each string passed |
Date: |
Thu, 30 May 2024 16:57:51 +0200 |
User-agent: |
Mozilla Thunderbird |
Hello again!
I've just spent half an hour by debugging my code thanks to this bug. :)
Let's look at the docs:
7.6 ‘.asciz "STRING"’...
========================
‘.asciz’ is just like ‘.ascii’, but each string is followed by a zero
byte. The “z” in ‘.asciz’ stands for “zero”. Note that multiple string
arguments not separated by commas will be concatenated together and only
one final zero byte will be stored.
We see that “.asciz” inserts *no NUL byte* after the string. Let's play
with my GAS installation:
$ cat >test.s
.asciz "hello", "world"
$ as test.s
$ xxd a.out
00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000 .ELF............
00000010: 0100 3e00 0100 0000 0000 0000 0000 0000 ..>.............
00000020: 0000 0000 0000 0000 b000 0000 0000 0000 ................
00000030: 0000 0000 4000 0000 0000 4000 0600 0500 ....@.....@.....
00000040: 6865 6c6c 6f00 776f 726c 6400 0000 0000 hello.world.....
00000050: 0400 0000 2000 0000 0500 0000 474e 5500 .... .......GNU.
---------------------------------->8 ----[SNIP]--------------------
$ as --version
GNU assembler (Gentoo 2.41 p5) 2.41.0
Copyright (C) 2023 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `x86_64-pc-linux-gnu'.
As you can see at the byte 0x45, the NUL byte is placed after the first
string ("hello" ends).
The attached patch should fix that, but I do not know GAS source code
well, so please review that carefully.
I provide also an alternative patch that adjusts the documentation
according to the implementation.
I would appreciate if you include a reference to me in the commit log.
Applying one of the patches using “git am” already accomplishes that task.
Thanks,
Jiří Wolker
0001-gas-Fix-.asciz-directive-for-multiple-operands.patch
Description: Text Data
0001-gas-doc-Fix-doc-of-.asciz-behavior-with-1-arg.patch
Description: Text Data
- [GAS bug] .asciz inserts zero byte for each string passed,
Jiří Wolker <=