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

Compat: force zero word into sdata #165

Closed
riptl opened this issue Mar 31, 2022 · 5 comments · Fixed by #166
Closed

Compat: force zero word into sdata #165

riptl opened this issue Mar 31, 2022 · 5 comments · Fixed by #166
Labels
decomp PRs that add decompiled code help wanted Extra attention is needed

Comments

@riptl
Copy link
Collaborator

riptl commented Mar 31, 2022

Problem

RVL/NAND contains empty strings like strcpy(dest, "").
These strings get placed as 0x00000000 in sdata.

This is hard to reproduce from inline assembly:
All of the below allocate an sbss entry in the object file, not sdata.

char c[] = "";
__declspec(section ".sdata") u32 u = 0;
__declspec(section ".sdata") float f = 0.0f;

Task

Figure out a way how to declare a zero word in .sdata and document it.

@riptl riptl added help wanted Extra attention is needed decomp PRs that add decompiled code labels Mar 31, 2022
@riptl
Copy link
Collaborator Author

riptl commented Mar 31, 2022

@riidefi @kiwi515 do you have any ideas?

@kiwi515
Copy link
Contributor

kiwi515 commented Apr 1, 2022

Have you tried making the data const? I think that might just put it in sbss2 though

@kiwi515
Copy link
Contributor

kiwi515 commented Apr 1, 2022

Actually, couldn't you just recreate the strcpy call in a stripped function? If you have string pooling on the string constant will stay in the binary.

@riptl
Copy link
Collaborator Author

riptl commented Apr 1, 2022

Thanks @kiwi515, yeah decompiling works.
Const landed in sbss2 and __declspec(section ".sdata") const char[] = ""; again landed in sbss :D a bit painful.
I was hoping we could find a solution at the inline asm level (for splitting).

@riptl
Copy link
Collaborator Author

riptl commented Apr 2, 2022

This has been solved using the MKW_PATCH macro. It allows us to place a dummy non-zero value to force a variable into .sdata, as well as a patch instruction in a custom section.

This mechanism is fully relocatable. That way we only have to patch the final ELF before transforming into DOL.

@riptl riptl changed the title force zero word into sdata Compat: force zero word into sdata Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decomp PRs that add decompiled code help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants