-
Notifications
You must be signed in to change notification settings - Fork 71
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
elf2x: wrong ELF parsing leads to huge t_size, producing ~2GiB output #32
Comments
Update: I recompiled GCC and binutils again, this time as However, elf2x still seems to parse an otherwise valid ELF incorrectly, so I'll leave this issue open for now. The problem that caused the bug in my earlier case doesn't seem to lie with the third or fourth, but second program header, where p_vaddr = 4194304. All example programs that compiled correctly have this value always as a large negative integer (as formatted by printf anyway) |
Well this is the first time I've seen anyone having an issue like this, all I could think of is the ELF file format probably changed in the experimental version of the GNU toolchain you're trying to use with PSn00bSDK. Does it still occur when using the SDK with older versions of the GNU toolchain? |
The issue seems to be much weirder than I thought. The problem occurs with both the provided GCC version 10.2 (and ld version 2.35) as well as my experimental build. Should behave exactly the same as doing: But that's not true. People who use CMake or [the provided] make[file] won't run into this, but people that try to quickly compile a simple program on the command line will be stuck. I haven't tested this on any older versions of GCC yet, like 7 |
I haven't actually gotten building an ELF from a single gcc/g++ command line to work right so I never bothered getting that to work on PSn00bSDK and is therefore, untested. The closest I ever got was it would produce an ELF file but for whatever reason the call to main() from _start() always points to address 0. Perhaps that might be why elf2x looked like it was parsing the ELF file incorrectly as one of the objects were addressed to 0x0 rather than 0x80000000. |
Do you think this could be a linker script issue? (Side note: you can change the VMA/LMA of the .text section in the ld script instead of having to pass the address as a compile flag) If this issue won't find a solution, at least this will serve as a documentation that compilation in one line doesn't work for now, so people won't be surprised. Thank you a lot for going through this hell to make this library. The linker scripts and ELF's intrinsics gave me eye and brain cancer personally, and I can't make sense of why this particular case brings up so many issues |
Hi!
I followed your guide and have built mipsel-unknown-elf-gcc (experimental 11.0.1 20210411) successfully on MSYS2, including libc (it worked for me out-of-the-box). It compiles C programs, including the provided beginner/hello example, without warnings or errors.
When I tried to run the ELF through elf2x though, the tool started allocating a ~2GiB chunk of memory and then produced a binary with the same size. I've attached an example ELF (of the hello example) below. No matter what compile options (including those from the example makefiles) or program I've tried, the produced ELF causes the same issue. I also used both my own modified elf32elmip.x and the one from psn00bsdk to no avail.
I'm not familiar at all with the ELF format, but did some digging. I modified elf2x.c to add some printf debugging:
The program's output (with
main.Og.elf
):Looks like either the p_vaddr of the third and fourth program headers are corrupted somehow, or elf2x is parsing the values from a place in the ELF it's not supposed to read from.
mipsel-unknown-elf-objdump -x
parses the ELF just fine, so I think it's the latter casemain.Og.zip
The text was updated successfully, but these errors were encountered: