public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Georg-Johann Lay <avr@gjlay.de>
To: gcc-help@gcc.gnu.org
Subject: C++: __asm on static method
Date: Thu, 01 Aug 2019 09:45:00 -0000	[thread overview]
Message-ID: <5D42B4A6.6050104@gjlay.de> (raw)

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



                 reply	other threads:[~2019-08-01  9:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5D42B4A6.6050104@gjlay.de \
    --to=avr@gjlay.de \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).