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

how to make the change of system lib source to work? #22462

Open
yejun81 opened this issue Aug 28, 2024 · 6 comments
Open

how to make the change of system lib source to work? #22462

yejun81 opened this issue Aug 28, 2024 · 6 comments

Comments

@yejun81
Copy link

yejun81 commented Aug 28, 2024

Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.64 (a1fe390)
clang version 19.0.0git (https:/github.com/llvm/llvm-project 4d8e42ea6a89c73f90941fd1b6e899912e31dd34)
Target: wasm32-unknown-emscripten
Thread model: posix

i make a little change the emscripten_fetch.c file of the fetch lib,

emscripten_fetch_t* fetch = (emscripten_fetch_t*)calloc(1, sizeof(emscripten_fetch_t));

to something like this:

  printf("change calloc to malloc\n");
  emscripten_fetch_t* fetch = (emscripten_fetch_t*)malloc(sizeof(emscripten_fetch_t));
  if (!fetch) {
    return NULL;
  }
  memset(fetch, 0, sizeof(emscripten_fetch_t));

after change the code ,i remove the libfetch*.a in cache/sysroot/lib folder, and after compile , in runtime, i see the 'change calloc to malloc' output in the browser console, but when i see the wasm decode in web browser, there is no malloc call, the calloc call is still there, why?

@sbc100
Copy link
Collaborator

sbc100 commented Aug 29, 2024

If you see the printf in the console then I don't see how the following line wouldn't be a call to malloc.

You can check contents libfetch.a if you like by extracting that object files and using wasm-objdump -x on them.

@yejun81
Copy link
Author

yejun81 commented Aug 30, 2024

yes, i am also very confused by the result, after change calloc to malloc, i even did printf in the dlcalloc function, the browser console showed that the real function be called was still dlcalloc.
so, i thought it may due to compiler optimize?

@sbc100
Copy link
Collaborator

sbc100 commented Aug 30, 2024

I don't think the compiler would ever change a calloc to a malloc though.. that seem backwards. Something strange much be going on. What does the it looks like if you inspect (via objdump or similar) the emscripten_fetch.o object file? Do you see a call to calloc or malloc?

By the way why are trying to make this change from calloc to malloc?

@yejun81
Copy link
Author

yejun81 commented Aug 30, 2024

seriously, i seeked for the compiled emscripten_fetch.o file, but i can't find it.it would be auto removed after compile?
i can't use memory large than 4GB, so i want to record the actually memory used to do some control, so i made some change to the dlmalloc, but it seemed the calloc doesn't memset the memory because the change i did.so i changed the calloc call to malloc to test.but it still call calloc...

@yejun81
Copy link
Author

yejun81 commented Sep 2, 2024

I don't think the compiler would ever change a calloc to a malloc though.. that seem backwards. Something strange much be going on. What does the it looks like if you inspect (via objdump or similar) the emscripten_fetch.o object file? Do you see a call to calloc or malloc?

By the way why are trying to make this change from calloc to malloc?

i have confirmed that when there is a memset after malloc, the compiler will change these to a calloc call.
anyway, thks for your reply and advices.
and i want to know where the compiled intermediate files like emscripten_fetch.o?

@sbc100
Copy link
Collaborator

sbc100 commented Sep 3, 2024

To get emscripten_fetch.o you can run ar x cache/sysroot/lib/wasm32-emscripten/libfetch.a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants