public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/101727] New: invalid symbol redefinition when -O2 enabled
@ 2021-08-02 18:00 zhan3299 at purdue dot edu
  2021-08-02 18:05 ` [Bug inline-asm/101727] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: zhan3299 at purdue dot edu @ 2021-08-02 18:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101727

            Bug ID: 101727
           Summary: invalid symbol redefinition when -O2 enabled
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhan3299 at purdue dot edu
  Target Milestone: ---

Following code can be successfully compiled with O0 optimization enabled, but
not O2.

Example code:
---
#include <stdio.h>

int func() {
    int filter;
    asm volatile(
        "  leaq _filter(%%rip), %%rax\n"
        "  jmp _out\n"
        "_filter:\n"
        ".ascii \"\\040\"\n"
        "_out:"
        : "=rax"(filter)
        :
        :);
    return filter;
}
int main() {
    printf("%#x", func());
    return 0;
}
---

Error messages of O2:
---
ASM generation compiler returned: 0
<source>: Assembler messages:
<source>:7: Error: symbol `_filter' is already defined
<source>:9: Error: symbol `_out' is already defined
Execution build compiler returned: 1
---

It affects 11.0, 12.0.

O2: https://godbolt.org/z/j9xG96fxW
O0: https://godbolt.org/z/b4TqddvYh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug inline-asm/101727] invalid symbol redefinition when -O2 enabled
  2021-08-02 18:00 [Bug inline-asm/101727] New: invalid symbol redefinition when -O2 enabled zhan3299 at purdue dot edu
@ 2021-08-02 18:05 ` pinskia at gcc dot gnu.org
  2021-08-02 18:25 ` jakub at gcc dot gnu.org
  2021-08-02 18:29 ` zhan3299 at purdue dot edu
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-02 18:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101727

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Inline-asm can be copied, If you need labels inside them you need to use
something different.


Also I really doubt "=rax" is the correct constraint you want.  Please read
https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Constraints.html#Constraints

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug inline-asm/101727] invalid symbol redefinition when -O2 enabled
  2021-08-02 18:00 [Bug inline-asm/101727] New: invalid symbol redefinition when -O2 enabled zhan3299 at purdue dot edu
  2021-08-02 18:05 ` [Bug inline-asm/101727] " pinskia at gcc dot gnu.org
@ 2021-08-02 18:25 ` jakub at gcc dot gnu.org
  2021-08-02 18:29 ` zhan3299 at purdue dot edu
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-08-02 18:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101727

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Note, the documentation talks about it:
https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Basic-Asm.html#Basic-Asm
Under certain circumstances, GCC may duplicate (or remove duplicates of) your
assembly code when optimizing. This can lead to unexpected duplicate symbol
errors during compilation if your assembly code defines symbols or labels.
and
https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Extended-Asm.html#Extended-Asm
Under certain circumstances, GCC may duplicate (or remove duplicates of) your
assembly code when optimizing. This can lead to unexpected duplicate symbol
errors during compilation if your asm code defines symbols or labels. Using
‘%=’ (see AssemblerTemplate) may help resolve this problem.
Normally people use numbered labels instead (leal 1f(...); ... 1: ...) or one
can use %=.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug inline-asm/101727] invalid symbol redefinition when -O2 enabled
  2021-08-02 18:00 [Bug inline-asm/101727] New: invalid symbol redefinition when -O2 enabled zhan3299 at purdue dot edu
  2021-08-02 18:05 ` [Bug inline-asm/101727] " pinskia at gcc dot gnu.org
  2021-08-02 18:25 ` jakub at gcc dot gnu.org
@ 2021-08-02 18:29 ` zhan3299 at purdue dot edu
  2 siblings, 0 replies; 4+ messages in thread
From: zhan3299 at purdue dot edu @ 2021-08-02 18:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101727

--- Comment #3 from zhan3299 at purdue dot edu ---
(In reply to Jakub Jelinek from comment #2)
> Note, the documentation talks about it:
> https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Basic-Asm.html#Basic-Asm
> Under certain circumstances, GCC may duplicate (or remove duplicates of)
> your assembly code when optimizing. This can lead to unexpected duplicate
> symbol errors during compilation if your assembly code defines symbols or
> labels.
> and
> https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Extended-Asm.html#Extended-Asm
> Under certain circumstances, GCC may duplicate (or remove duplicates of)
> your assembly code when optimizing. This can lead to unexpected duplicate
> symbol errors during compilation if your asm code defines symbols or labels.
> Using ‘%=’ (see AssemblerTemplate) may help resolve this problem.
> Normally people use numbered labels instead (leal 1f(...); ... 1: ...) or
> one can use %=.

Thanks for letting me know. I do apologize that I haven't gone through the
whole document and bothering you by this invalid issue. Sorry about it.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-02 18:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02 18:00 [Bug inline-asm/101727] New: invalid symbol redefinition when -O2 enabled zhan3299 at purdue dot edu
2021-08-02 18:05 ` [Bug inline-asm/101727] " pinskia at gcc dot gnu.org
2021-08-02 18:25 ` jakub at gcc dot gnu.org
2021-08-02 18:29 ` zhan3299 at purdue dot edu

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).