This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug inline-asm/58748] New: %n asm output template with symbol references should not be permitted?


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58748

            Bug ID: 58748
           Summary: %n asm output template with symbol references should
                    not be permitted?
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org

consider code:

struct tracepoint {
    int dummy;
    int state;
};
static struct tracepoint tp;

void test(void)
{
    __asm__ ("b %c0" : : "i"(&tp.state));
}


compiling for arm will give the assembly:

test:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
@ 9 "constr.c" 1
        b tp+4
@ 0 "" 2
        bx      lr
        .size   test, .-test
        .bss
        .align  2
        .type   tp, %object
        .size   tp, 8
tp:
        .space  8


Now, if we change the output template from %c to %n:
__asm__ ("b %n0" : : "i"(&tp.state));

we get

test:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
@ 9 "constr.c" 1
        b -tp+4
@ 0 "" 2
        bx      lr
        .size   test, .-test
        .bss
        .align  2
        .type   tp, %object
        .size   tp, 8
tp:
        .space  8

gcc just adds a '-' in front of the tp+4 expression instead of properly
negating it. Now this is reasonably easy to fix in final.c, but I was
wondering: since "-tp + 4" fails to assemble with gas anyway, should we just
forbid the use of %n with non-literal constant expressions?

This situation applies to x86 and aarch64 as well.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]