-fno-asynchronous-unwind-tables && .cfi_* in inline asm
Fangrui Song
i@maskray.me
Sat Feb 20 04:30:00 GMT 2021
On 2021-02-19, Jim Wilson wrote:
>On Fri, Feb 19, 2021 at 4:36 PM Fangrui Song <i@maskray.me> wrote:
>
>> How should we make the following code work with both
>> -fno-asynchronous-unwind-tables and -fasynchronous-unwind-tables?
>>
>> int main() {
>> asm(".cfi_undefined %rip");
>> }
>>
>> The example is minimalistic. The idea is that if inline asm does stack
>> push/pop and wants to manually add .cfi_* directives, the current
>> error behavior is undesired.
>>
>
>I don't think that there is a way currently to make this work.
>In general, I'd say that if you are doing something non-trivial you should
>not be using an extended asm. You should either use a built-in function or
>just write it in assembly language directly. Extended asms really only
>work well for simple stuff. If you use a built-in function, then the
>compiler should emit any CFI directives for that built-in if necessary. If
>writing in assembly language then you can hand write CFI directives for the
>entire function, or rely on assembler support if the assembler can figure
>it out from the code.
>But if you really want to do this in an extended asm, then we would need to
>extend the asm syntax so that one can put CFI info in the middle of an
>asm. One way to do that might be a special operator for formatting asm
>strings that only prints the string if we are emitting unwind info. We
>would have to find a free punctuation character that isn't already used by
>any existing port, and then assuming backquote is free we could do
>int main() {
> asm("`.cfi_undefined %rip`");
> }
>and the backquotes then only print the string if we are emitting unwind
>info. Or alternatively make this a % operator like %`. Either way, I
>think this would look funny, so might not be the best approach. It would
>likely be difficult for people to use. I seriously doubt many users can
>write CFI code and get it right.
In GNU as, can we have a .cfi_sections value to ignore subsequent .cfi_* directives?
If such a directive exists, gcc -fno-asynchronous-unwind-tables can emit
that directive, and pass through all the .cfi_* directives, then let GNU as ignore them.
More information about the Binutils
mailing list