Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: set C standard to GNU C due to inline assembly usage #1875

Closed

Conversation

magiruuvelvet
Copy link

@magiruuvelvet magiruuvelvet commented Aug 25, 2023

Standard ISO C does not have inline assembly support, but is a compiler extension. For compilers which default to ISO C, specify the use of GNU extensions to enable inline assembly.

Fixes compiler errors like this:

error: use of undeclared identifier 'asm'

I'm opening this pull request as a package maintainer, rather than a user of this library. Please feel free to ignore this pull request if it is not fitting for this project. I just want to bring attention to this issue and hopefully safe someone else a couple of headaches. I'm not even sure if this is the proper location to add this flag.

For reference: I'm using clang with extensions disabled by default, when -std= is not specified on the command line.

EDIT: I should mention that this is a very niche use case, since you must actively change the C standard (when -std= is omitted from the command line) during the configure step when building your own copy of LLVM. No sane compiler distribution will be configured like this.

Standard ISO C does not have inline assembly support, but is a compiler extension. For compilers which default to ISO C, specify the use of GNU extensions to enable inline assembly.

Fixes compiler errors like this:

```
error: use of undeclared identifier 'asm'
```
@wtdcode
Copy link
Member

wtdcode commented Aug 25, 2023

Thanks for the issue. Which package are you maintaining?

@magiruuvelvet
Copy link
Author

Local packages for myself to run on my Steam Deck. I recently picked up Vita3K which makes use of unicorn. yuzu-emu also used unicorn in the past (removed by now), where I had the exact same problem during compilation.

@wtdcode
Copy link
Member

wtdcode commented Aug 26, 2023

This obviously conflicts with our:

set(CMAKE_C_STANDARD 11)

@mlgiraud
Copy link
Contributor

mlgiraud commented Aug 28, 2023

The documentation says this:

When compiling in ISO C mode by GCC or Clang (e.g. with option -std=c11), __asm__ must be used instead of asm.

So replacing all asm usages by __asm__ should fix this i presume.

@magiruuvelvet
Copy link
Author

I compiled the version in the master branch just fine with my toolchain. Downstream is simply outdated or may contain custom patches which break the passing of the -std=gnu... flag, so I guess this issue is invalid for this repository.

For that, I will just continue to provide my own patches for the packaging process. It's not that much of a hassle for me.

I found the CMAKE_C_EXTENSIONS variable in the CMake documentation, but it is supposed to be ON by default. I don't have custom patches integrated into my CMake which would overwrite the behavior of this variable.


Regarding the __asm__ comment. This snippet of code compiled just fine in ISO C mode.

int main() {
    __asm__("nop");
    return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants