Re: PROPOSAL: Extend inline asm syntax with size spec

From: Alexander Monakov
Date: Sat Oct 13 2018 - 17:20:50 EST


Hi,

On Sat, 13 Oct 2018, Borislav Petkov wrote:
>
> Thoughts, suggestions, etc are most welcome.

I apologize for coming in late here with an alternative proposal, but would
you be happy if GCC gave you a way to designate a portion of the asm template
string that shouldn't be counted as its cost because it doesn't go into the
.text section? This wouldn't interact with your redefinitions of the inline
keyword, and you could do something like (assuming we go with %` ... %`
delimiters)

[if gcc-9 or compatible]

#define ASM_NONTEXT_START "%`\n"
#define ASM_NONTEXT_END "%`\n"

[else]

#define ASM_NONTEXT_START "\n"
#define ASM_NONTEXT_END "\n"

[endif]

#define _BUG_FLAGS(ins, flags) \
do { \
asm volatile("1:\t" ins "\n" \
ASM_NONTEXT_START \
".pushsection __bug_table,\"aw\"\n" \
"2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
"\t.word %c0" "\t# bug_entry::flags\n" \
"\t.org 2b+%c1\n" \
".popsection" \
ASM_NONTEXT_END \
: : "i" (flags), \
"i" (sizeof(struct bug_entry))); \
} while (0)


I think it's nicer because it also allows the compiler to estimate asm length
for branch range optimization more accurately.

Alexander