This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug inline-asm/58748] New: %n asm output template with symbol references should not be permitted?
- From: "ktkachov at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 16 Oct 2013 13:05:00 +0000
- Subject: [Bug inline-asm/58748] New: %n asm output template with symbol references should not be permitted?
- Auto-submitted: auto-generated
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.