When as AM target, nemu cannot use some glibc functions like fopen & fclose. Even if the macro CONFIG_TARGET_AM is applied, this file will still be compiled by the cross-compiler. The reason why it did not go wrong is probably that the compiler optimized it and this object file(or the function) didn't participate in linking process. I think it is not a good idea and we shall add explicit conditional compile statements.
To find such kinds of problems, some clever methods could be further applied(though I don't do them in this PR):
Add conditional compile statements when using glibc functions. E.g. #include <string.h> in common.h; #include <stdio.h> in debug.h (Note: this is also the source where the compiler get the declaration of fopen and fclose in this PR so that it does not report error when compiling), etc. Add conditional comile statements with #include <klib.h> instead.
When as AM target, nemu cannot use some glibc functions like
fopen
&fclose
. Even if the macroCONFIG_TARGET_AM
is applied, this file will still be compiled by the cross-compiler. The reason why it did not go wrong is probably that the compiler optimized it and this object file(or the function) didn't participate in linking process. I think it is not a good idea and we shall add explicit conditional compile statements.To find such kinds of problems, some clever methods could be further applied(though I don't do them in this PR):
Add conditional compile statements when using glibc functions. E.g.
#include <string.h>
in common.h;#include <stdio.h>
in debug.h (Note: this is also the source where the compiler get the declaration offopen
andfclose
in this PR so that it does not report error when compiling), etc. Add conditional comile statements with#include <klib.h>
instead.