tyfkda / xcc

Standalone C compiler/assembler/linker/libc for x86-64/aarch64/riscv64/wasm
https://tyfkda.github.io/xcc/
MIT License
197 stars 14 forks source link

Bug: various functions do not open binary files as binary #155

Closed ijsf closed 3 months ago

ijsf commented 3 months ago

It seems that the load_archive function in archive.c is not opening the archive file in binary mode:

https://github.com/tyfkda/xcc/blob/e49b25916388ba39ce3b4ac9a6474e454228e8d2/src/util/archive.c#L21

In my case, this is causing odd issues with a different version of llvm-ar:

Assertion failed: pos < symbols[0].offset, file src/util/archive.c, line 53

Obviously, the position here is way too far ahead as only a few bytes should have been read, this seems due to the fread() encountering newlines. Adding "rb" fixes the issue.


I've noticed the same issue here:

https://github.com/tyfkda/xcc/blob/e49b25916388ba39ce3b4ac9a6474e454228e8d2/src/wcc/wasm_linker.c#L1426

This was causing issues with wcc failing to read emitted wasm (stored in a temporary file). Changing to rb solved the issue.

There might be other places where "r" or "w" are used instead of "rb" or "wb".

tyfkda commented 3 months ago

@ijsf Could you send a pull request? Thanks.

ijsf commented 3 months ago

Done.