public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/101738] New: Variable value is not set when address passed as register in inline assembly at O2
@ 2021-08-03 0:23 moinakb001 at gmail dot com
2021-08-03 0:25 ` [Bug inline-asm/101738] " moinakb001 at gmail dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: moinakb001 at gmail dot com @ 2021-08-03 0:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101738
Bug ID: 101738
Summary: Variable value is not set when address passed as
register in inline assembly at O2
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: inline-asm
Assignee: unassigned at gcc dot gnu.org
Reporter: moinakb001 at gmail dot com
Target Milestone: ---
If one compiles the following code at -O2 (on x86, -v dump follows):
```
void test()
{
int x = 0x12345678;
asm volatile(".asm_label:"::"r"(&x));
}
```
one can see that the stack space allocated for x is not initialized before the
inline assembly label (indeed, the store is elided entirely), generating
incorrect sequence:
```
test:
lea rax, [rsp-4]
.asm_label:
ret
```
This, in certain cases, would seriously screw up things like inline asm syscall
implementations (if one takes address of a stack var).
bash # gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/10.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-10.3.0/work/gcc-10.3.0/configure
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr
--bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/10.3.0
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/10.3.0
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/10.3.0/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/10.3.0/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include/g++-v10
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/10.3.0/python
--enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt
--disable-werror --with-system-zlib --enable-nls --without-included-gettext
--enable-checking=release --with-bugurl=https://bugs.gentoo.org/
--with-pkgversion='Gentoo 10.3.0 p1' --disable-esp --enable-libstdcxx-time
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64
--disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp
--disable-libada --disable-systemtap --disable-vtable-verify --disable-libvtv
--without-zstd --enable-lto --without-isl --enable-default-pie
--enable-default-ssp
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.3.0 (Gentoo 10.3.0 p1)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug inline-asm/101738] Variable value is not set when address passed as register in inline assembly at O2
2021-08-03 0:23 [Bug inline-asm/101738] New: Variable value is not set when address passed as register in inline assembly at O2 moinakb001 at gmail dot com
@ 2021-08-03 0:25 ` moinakb001 at gmail dot com
2021-08-03 0:35 ` pinskia at gcc dot gnu.org
2021-08-03 0:38 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: moinakb001 at gmail dot com @ 2021-08-03 0:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101738
--- Comment #1 from Moinak Bhattacharyya <moinakb001 at gmail dot com> ---
Note: clang does not have this problem, generating:
```
test:
mov dword ptr [rsp - 4], 305419896
lea rax, [rsp - 4]
.asm_label:
ret
```
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug inline-asm/101738] Variable value is not set when address passed as register in inline assembly at O2
2021-08-03 0:23 [Bug inline-asm/101738] New: Variable value is not set when address passed as register in inline assembly at O2 moinakb001 at gmail dot com
2021-08-03 0:25 ` [Bug inline-asm/101738] " moinakb001 at gmail dot com
@ 2021-08-03 0:35 ` pinskia at gcc dot gnu.org
2021-08-03 0:38 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-03 0:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101738
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
you are only passing the address to the inline-asm.
You need to either the m constraint also or add a memory clobber.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug inline-asm/101738] Variable value is not set when address passed as register in inline assembly at O2
2021-08-03 0:23 [Bug inline-asm/101738] New: Variable value is not set when address passed as register in inline assembly at O2 moinakb001 at gmail dot com
2021-08-03 0:25 ` [Bug inline-asm/101738] " moinakb001 at gmail dot com
2021-08-03 0:35 ` pinskia at gcc dot gnu.org
@ 2021-08-03 0:38 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-03 0:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101738
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|INVALID |DUPLICATE
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** This bug has been marked as a duplicate of bug 36639 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-03 0:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 0:23 [Bug inline-asm/101738] New: Variable value is not set when address passed as register in inline assembly at O2 moinakb001 at gmail dot com
2021-08-03 0:25 ` [Bug inline-asm/101738] " moinakb001 at gmail dot com
2021-08-03 0:35 ` pinskia at gcc dot gnu.org
2021-08-03 0:38 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).