C++: __asm on static method

Georg-Johann Lay avr@gjlay.de
Thu Aug 1 09:45:00 GMT 2019


Hi,

suppose the following GNU C++ code:

class C
{
     __attribute((used))
     static void method() __asm ("__vector_1")
     {
         __asm ("; method1");
     }

     static void method2() __asm ("__vector_2");
};

void C::method2()
{
     __asm ("; method2");
}

Similar code is used on bare metal when you want an interrupt
service routine (ISR) be defined as a class method that can
access private (static) members.

The generated assembly for method2 is as expected
(here with avr-g++ v8):

	.text
	.global	__vector_2
	.type	__vector_2, @function
__vector_2:
/* #APP */
	; method2
/* #NOAPP */
	ret

The ISR must have this specific name to be recognized as
interrupt vector and to be inserted into the vector table.

method1 however reads as follows:

	.text
	.section	.text._ZN1C7method1Ev,"axG",@progbits,_ZN1C7method1Ev,comdat
	.weak	_ZN1C7method1Ev
	.type	_ZN1C7method1Ev, @function
_ZN1C7method1Ev:
/* #APP */
	; method1
/* #NOAPP */
	ret

As far as I understand the semantics of __asm, the assembler
name of method1 should be __vector_1.  For the comdat group
name, both __vector_1 and _ZN1C7method1Ev should be okay
provided it is consistent across units.

IMO method1 is not compiled correctly; it would be pointless
to specify __asm if it was supposed to have to effect.

Presumably, this is some glitch / bug in varasm.c?

Thanks,

Johann





More information about the Gcc-help mailing list