WebAssembly / wasi-sdk

WASI-enabled WebAssembly C/C++ toolchain
Apache License 2.0
1.23k stars 177 forks source link

Compilation issues with non-standard C keywords and functions. #489

Open ShubhamGupta577 opened 6 days ago

ShubhamGupta577 commented 6 days ago

I'm working on compiling an existing codebase using the WASI-SDK24 which is more of a legacy code written long way back for older compilers, but I'm encountering compilation errors due to the use of non-standard C keywords and functions in the codebase. I would greatly appreciate any guidance or assistance from the community in resolving this issue.

Background:

Errors encountered:-

typedef unsigned long huge *  UNSIGNED PTR;
typedef void __interrupt COMISR();
void _Cdecl _FARFUNC __assertfail( CONST char _FAR *__msg, ..)

There are multiple errors similar to this and these are mainly due to the keywords like "huge, far, _FARFUNC" and the functions like __interrupt which are of non c standard.

So if there is any solution in which wasi-sdk provide the support to run old code will be useful.

sunfishcode commented 6 days ago

If you want the compiler to ignore those keywords, you could try passing -Dhuge= -D_FARFUNC= -Dfar= -D__interrupt= to the compiler.

Wasm doesn't have any kind of interrupt handler functionality, so if the function with __interrupt is expected to be called on interrupts, you'll likely need to change the code in some way.

ShubhamGupta577 commented 5 days ago

Thanks for you help. I tried to implement the solution but this solution is ignoring the keywords which mentioned in the flags due to that there is some functionality breakdown in code base

I have a old code base which was build on the 'Paradigm C++ Compiler" which supports the non standard keywords and functions, now I want to convert that into wasm using the wasi-sdk so that I can reduce the memory footprint. So is there any way I can do this without breaking the existing functionality. Reference link of Paradigm C++:- https://www.embeddedindia.com/paradigm-software.html

In my understanding the issue is that wasi-sdk is using the clang which doesn't support the non standard keywords.

sbc100 commented 5 days ago

If the code in question can't be compiled with clang, then its highly unlikely you will be able to compile it with wasi-sdk, which simply used an unmodified version of upstream clang.

If you would like to pursue those features in clang then you might want to ask upstream in the clang project if there is any interest in adding them, but WASI and wasi-sdk probably isn't the right venue to propose this.