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

feat(c11): Adapt code to be compatible with ISO C11 #122

Merged
merged 16 commits into from May 22, 2024
Merged

feat(c11): Adapt code to be compatible with ISO C11 #122

merged 16 commits into from May 22, 2024

Conversation

miguelafsilva5
Copy link
Member

@miguelafsilva5 miguelafsilva5 commented Jan 30, 2024

PR Description

This PR is the first on the chain of PRs (This PR <- #146 <- #147 ).
The main goal of this PR is to force ISO C11 on bao and deal with all -pedantic errors. Each commit tries to deal with a specific error.

The platforms tested were:

  • qemu-aarch64-virt
  • qemo-riscv64-virt

Makefile Outdated Show resolved Hide resolved
src/arch/riscv/inc/arch/csrs.h Outdated Show resolved Hide resolved
src/arch/riscv/inc/arch/csrs.h Outdated Show resolved Hide resolved
src/core/inc/bao.h Outdated Show resolved Hide resolved
src/lib/inc/util.h Show resolved Hide resolved
src/arch/armv8/vgic.c Outdated Show resolved Hide resolved
@josecm
Copy link
Member

josecm commented Jan 31, 2024

I don't think we need the wip in #120. We can use just this PR for both enabling pedantic C11 and adding the fixes to the new errors.

@josecm josecm changed the base branch from wip/c11 to main January 31, 2024 10:58
@josecm josecm self-assigned this Jan 31, 2024
@josecm josecm mentioned this pull request Jan 31, 2024
2 tasks
@josecm
Copy link
Member

josecm commented Feb 1, 2024

@miguelafsilva5 please fix your commit messages to pass gitlint checks and apply the code formatter.

I also see that the builds are still failing due to -Wpedantic errors.

Copy link
Member

@josecm josecm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, the scopes you are using in your commit messages don't make much sense. Scopes are supposed to be more of a component of subsystem of the code or a topic regarding the modification, not a keyword for the modification you are introducing. As many of these are related to ISO C, C11, pedantic c, I would suggest using some scope in this sense or none at all.

src/arch/armv8/armv8-a/aarch64/vmm.c Outdated Show resolved Hide resolved
src/arch/armv8/vgicv3.c Outdated Show resolved Hide resolved
src/arch/riscv/inc/arch/csrs.h Outdated Show resolved Hide resolved
src/lib/inc/util.h Outdated Show resolved Hide resolved
src/lib/inc/util.h Show resolved Hide resolved
src/core/inc/bao.h Outdated Show resolved Hide resolved
Copy link
Member

@danielRep danielRep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes seem OK to me and well-documented on each commit description. However, build checkers are failing.

@miguelafsilva5
Copy link
Member Author

The changes seem OK to me and well-documented on each commit description. However, build checkers are failing.

Commit 1853b59 seems to have fixed it.

danielRep
danielRep previously approved these changes Mar 25, 2024
@miguelafsilva5 miguelafsilva5 force-pushed the feat/c11 branch 2 times, most recently from 8cb9f80 to f769441 Compare May 22, 2024 12:50
Initial commit for the process of adapting bao to the standard C11.
Modified the makefile to compile according to C11 and reject the use of any
extension.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
The asm keyword is a GNU extension. Changed all instances to the C11
counterpart __asm__

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
The use of binary constants (e.g., 0b0101) is a GCC extension.
Refactor all binary constants to hex (e.g., 0x5).

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
GCC issues an error ("initializer element is not constant") when
SPINLOCK_INITVAL was defined in a macro.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
Most macros expand to functions. C11 does not allow the use of ;
at the end of non-statements.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
sgi_base[0] was used for better legibility while ensuring the the next
registers were aligned properly. C11 does not allow these declarations.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
Using an expression in return statement is illegal in C11.
In this case, the function has a void return type.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
__VA_OPT__ is only available as a GNU extension or in C23.
The error issued by gcc is "error: __VA_OPT__ is not available until C2X"

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
C11 does not allow arithmetic operations on void* ptrs.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
Add a dummy uint8_t to the structs page_table_arch and iommu_vm_arch since
C11 does not allow structs to be declared without members.
This was the best solution available avoiding majors modifications to bao.
Considering both structs are only used in a small number of ocasions, the
increase in memory usage is acceptable.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
The macro DEFINED evaluates if a given macro was defined or not. Its expansion
ends in a variadic macro that was not receiving the correct number of arguments
if the evaluated macro was not defined. It was fixed by added a dummy argument
that is ignored.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
@miguelafsilva5
Copy link
Member Author

There are compilations errors for tx2, ultra96, zcu102, zcu104 platforms These are related to the uart drivers

The errors were related to previous commits. I've fixed them in commits ee8c6b4 and 88d90e9

josecm
josecm previously approved these changes May 22, 2024
danielRep
danielRep previously approved these changes May 22, 2024
@DavidMCerdeira DavidMCerdeira self-requested a review May 22, 2024 13:22
ISO C forbids zero-size arrays.
From our understanding, that declaration does not achieve anything.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
ISO C forbids braced-groups within expressions which was used in the
CSRR macro. We use the same strategy as in arm code, by generating
static functions accessors for each CSR

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
Pedantic C does not allow for the initialization of flexible array members.
The presented solution follows the same pattern as other attributes in structs
used in the configuration (e.g., shmemlist or regions).

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
With the changes to the type of vmlist, the system fails to build to
generate the headers without adding an entry to the new vmlist array.

Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
Signed-off-by: Miguel Silva <miguelafsilva5@gmail.com>
@josecm josecm merged commit a032f52 into main May 22, 2024
15 checks passed
@josecm josecm deleted the feat/c11 branch May 22, 2024 13:55
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.

None yet

4 participants