gba_base.h: fix "section conflict" GCC error#9
gba_base.h: fix "section conflict" GCC error#9LunarLambda wants to merge 1 commit intodevkitPro:masterfrom LunarLambda:patch-fix-section-conflict
Conversation
When mixing `IWRAM_CODE` and `IWRAM_DATA` in the same file, GCC generates a "section attribute conflict" error:
```c
#include <gba_console.h>
#include <gba_video.h>
#include <gba_interrupt.h>
#include <gba_systemcalls.h>
#include <gba_input.h>
#include <stdio.h>
#include <stdlib.h>
void IWRAM_CODE hello(void)
{
iprintf("Hello, world!\n");
}
int IWRAM_DATA x = 1;
int main(void) {
irqInit();
irqEnable(IRQ_VBLANK);
consoleDemoInit();
hello();
iprintf("%i\n", x);
while (1) {
VBlankIntrWait();
}
}
```
```
/home/luna/dev/homebrew/gba/iwram-test/src/main.c: In function 'main':
/home/luna/dev/homebrew/gba/iwram-test/src/main.c:14:16: error: 'x' causes a section type conflict with 'hello'
14 | int IWRAM_DATA x = 1;
| ^
/home/luna/dev/homebrew/gba/iwram-test/src/main.c:9:17: note: 'hello' was declared here
9 | void IWRAM_CODE hello(void)
| ^~~~~
```
This is quickly fixed making `IWRAM_DATA` (and `EWRAM_DATA`) map to a different section, `.iwram_data` (`.ewram_data`) instead.
The linker script handles this fine due to wildcard matching.
|
Hello, I'm 100% sure but the __attribute__, here IWRAM_CODE and IWRAM_DATA should be before the type. IWRAM_CODE void hello(void)
{
iprintf("Hello, world!\n");
}IWRAM_DATA int x = 1;Regards, |
|
It makes absolutely zero difference, and in fact GCC generally recommends putting attributes before identifiers, not types. I would highly appreciate if people actually tested their claims before making them, such that I'm not required to waste my time disproving them. #include <gba_console.h>
#include <gba_video.h>
#include <gba_interrupt.h>
#include <gba_systemcalls.h>
#include <gba_input.h>
#include <stdio.h>
#include <stdlib.h>
IWRAM_CODE void hello(void)
{
iprintf("Hello, world!\n");
}
IWRAM_DATA int x = 1;
int main(void)
{
irqInit();
irqEnable(IRQ_VBLANK);
consoleDemoInit();
hello();
iprintf("%d\n", x);
while (1)
{
VBlankIntrWait();
}
} |
|
Thank you for your check. |
|
What? libgba has nothing to do with the NDS. This is just a matter of libgba's attribute macros being broken. |
The architecture of NDS and GBA are quite similar. If you want to dive into the devkitpro |
|
I am well familiar with the linker scripts. This has nothing to do with that, the error happens at the compiler level, because the compiler does not permit creating sections that are both writable and executable.
The entire purpose of this PR is to fix the headers by making the macros work such that section conflicts will not happen under normal use. |
|
Oh ok ! :) |
Make the *_CODE and *_DATA section macros use separate section names. This fixes GCC complaining about conflicting section permissions (R-X vs RW-) when IWRAM_CODE and IWRAM_DATA are used in the same file. See devkitPro/libgba#9 for more information.
|
Sorry to leave this sitting so long. Forgotten in the midst of other things. Merged manually |
This is the exact same fix as devkitPro/libgba#9.
When mixing
IWRAM_CODEandIWRAM_DATAin the same file, GCC generates a "section type conflict" error:This is quickly fixed making
IWRAM_DATA(andEWRAM_DATA) map to a different section,.iwram_data(.ewram_data) instead.The linker script handles this fine due to wildcard matching.