-
Notifications
You must be signed in to change notification settings - Fork 37
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
Modern GCC and GDB #624
base: master
Are you sure you want to change the base?
Modern GCC and GDB #624
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are some good changes and much appreciated to have some of these things cleaned up! I've left my preliminary thoughts about some of the fixes in the actual decompiled code.
For the changes related to the build system, I think it would be best to have them reviewed by @laqieer, @CT075, @StanHash, or @MokhaLeee (who each have a better grasp on the various aspects of it than me).
@@ -1000,7 +1000,7 @@ void ItemSubMenuEnd(struct MenuProc* menu) { | |||
return; | |||
} | |||
|
|||
u8 MenuCommand_SelectNo(struct MenuProc* menu, struct MenuItemProc* menuItem) { | |||
u8 MenuCommand_SelectNo(struct MenuProc* menu/*, struct MenuItemProc* menuItem*/) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to annotate this with a further comment about why the second argument is commented out -- the comment at the latter call site (L1027-L1028) is now no longer obvious as to what it was pointing out
src/bmmenu.c
Outdated
// This is really caused by implicit declaration | ||
isBallista = ((s32 (*)(struct Trap*))IsBallista)(trap); // TODO: FIXME: UB | ||
isBallista = IsBallista(trap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here - I think it becomes unclear as to what this comment is indicating about the implicit declaration. Would be good to either remove the comment or make a comment about what the bug was, and how/why we fixed it
@@ -989,7 +989,7 @@ void UnitChangeFaction(struct Unit* unit, int faction) { | |||
GetUnit(newUnit->rescue)->rescue = newUnit->index; | |||
} | |||
|
|||
inline s8 CanUnitCrossTerrain(struct Unit* unit, int terrain) { | |||
inline s32 CanUnitCrossTerrain(struct Unit* unit, int terrain) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it at all possible to avoid this change? I'm a bit worried since it pollutes a lot of places in the code where we now have to cast to s8
.
It seems pretty clear that this function is intended to return s8
/bool
, but there is just the one place (in mapanim_summon.c
) where it returns s32
due to implicit declaration...
If it cannot be helped then it's okay, but if there is a less invasive approach I'd prefer we take that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely another bug in the official code. Theoretically, there should only be a version of the function with a return type of s8. However, under the previous approach—where the function was not declared in the header file (.h) but individually declared in each source file (.c)—modern gcc would fail to link, unable to find the symbol for this function.
The current modification, while not ideal, ensures both the binary consistency after compilation with agbcc and resolves the linking issue with modern gcc.
AS := $(PREFIX)as$(EXE) | ||
LD := $(PREFIX)ld$(EXE) | ||
OBJCOPY := $(PREFIX)objcopy$(EXE) | ||
STRIP := $(PREFIX)strip$(EXE) | ||
|
||
CC1 := tools/agbcc/bin/agbcc$(EXE) | ||
CC1_OLD := tools/agbcc/bin/old_agbcc$(EXE) | ||
# note: the makefile must be set up so MODERNCC is never called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give more details on what this is accomplishing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly refer to https://github.com/pret/pokeemerald
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What parts of that repo is this intended to imitate? Should I believe that this is a good thing solely because emerald does it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is mainly inspired by the Makefile section, which allows for the compilation of different versions of the code. Intermediate files and .o files are generated in separate directories to ensure that switching between different versions during compilation does not cause interference.
Thanks for your contribution. Could you please provide these to help us review this PR:
|
Fix -Wimplicit-function-declaration Fix -Werror=builtin-declaration-mismatch
Fix MenuCommand_SelectNo
…ror=switch-outside-range]
…re incorrectly compiled into the .bss segment and discarded in the latest GCC version.
… using GDB (e.g., in VSCode with mGBA).
I performed a rebase and then made corresponding additions in ldscript_modern.txt based on the changes in ldscript.txt today. I removed two inappropriate comments and added two new comments elsewhere to explain why the changes were made. There are no conflicts now, and I manually compiled both versions without any issues. As for README and similar files, it's best for your team to write them as I'm not particularly skilled in handling such textual content. |
Forgot to quote this, I mentioned the relevant content in my reply above. |
Support compilation with modern GCC and enable source-level debugging using GDB (e.g., in VSCode with mGBA).