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

wasm-ld: error: failed to write the output file: permission denied #13067

Open
jinkoo2 opened this issue Dec 17, 2020 · 36 comments
Open

wasm-ld: error: failed to write the output file: permission denied #13067

jinkoo2 opened this issue Dec 17, 2020 · 36 comments

Comments

@jinkoo2
Copy link

jinkoo2 commented Dec 17, 2020

Installed following the getting started guide on Windows 7. The installation went fine with no error and the installation check was okay without any error. But, I get the permission error when I try to test on the hello_world.c sample (emcc hello_world.c). I have full-permission on the machine and the disk has enough free space.

C:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\mytests>emcc hello_world.c
wasm-ld: error: failed to write the output file: permission denied
emcc: error: 'C:/Users/jkim20/Desktop/projects/express/deleteme/emscripten/emsdk/upstream/bin\wasm-ld.exe -o a.out.wasm C:\Users\jkim20\AppData\Local\Temp\emscripten_temp_b9hqya07\hello_world_0.o -LC:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\emsdk\upstream\emscripten\system\local\lib -LC:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\emsdk\upstream\emscripten\system\lib -LC:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\emsdk\upstream\emscripten\cache\wasm C:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\emsdk\upstream\emscripten\cache\wasm\libc.a C:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\emsdk\upstream\emscripten\cache\wasm\libcompiler_rt.a C:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\emsdk\upstream\emscripten\cache\wasm\libc++-noexcept.a C:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\emsdk\upstream\emscripten\cache\wasm\libc++abi-noexcept.a C:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\emsdk\upstream\emscripten\cache\wasm\libdlmalloc.a C:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\emsdk\upstream\emscripten\cache\wasm\libc_rt_wasm.a C:\Users\jkim20\Desktop\projects\express\deleteme\emscripten\emsdk\upstream\emscripten\cache\wasm\libsockets.a -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --strip-debug --export-table --export main --export emscripten_stack_get_end --export emscripten_stack_get_free --export emscripten_stack_init --export stackSave --export stackRestore --export stackAlloc --export __wasm_call_ctors --export fflush --export __errno_location -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (1)

@geogiam-net
Copy link

This is also happening to me right now.

Windows 7, full permissions, cmd as admin, no write only attribs

C:\wasm-emscripten\emsdk\upstream\emscripten>emcc tests/hello_world.c -v
shared:INFO: (Emscripten: Running sanity checks)
"C:/wasm-emscripten/emsdk/upstream/bin\clang.exe" -DEMSCRIPTEN -fignore-excepti
ons -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj
-mllvm -disable-lsr -Xclang -isystemC:\wasm-emscripten\emsdk\upstream\emscripten
\system\include\SDL -target wasm32-unknown-emscripten -D__EMSCRIPTEN_major__=2 -
D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=10 -D_LIBCPP_ABI_VERSION=2 -Dunix
-D__unix -D__unix__ -Werror=implicit-function-declaration --sysroot=C:\wasm-emsc
ripten\emsdk\upstream\emscripten\system -Xclang -isystemC:\wasm-emscripten\emsdk
\upstream\emscripten\cache\wasm\include -Xclang -iwithsysroot/include\compat -Xc
lang -iwithsysroot/include\libc -Xclang -iwithsysroot/lib\libc\musl\arch\emscrip
ten -Xclang -iwithsysroot/local\include -Xclang -iwithsysroot/include\SSE -Xclan
g -iwithsysroot/include\neon -Xclang -iwithsysroot/lib\compiler-rt\include -Xcla
ng -iwithsysroot/lib\libunwind\include -v tests/hello_world.c -c -o C:\Users\urz
a\AppData\Local\Temp\emscripten_temp_s5t9rfg9\hello_world_0.o
clang version 12.0.0 (Cswircachegitchromium.googlesource.com-external-github.aaakk.us.kg
-llvm-llvm--project 445289aa63e1b82b9eea6497fb2d0443813a9d4e)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:/wasm-emscripten/emsdk/upstream/bin
(in-process)
"C:\wasm-emscripten\emsdk\upstream\bin\clang.exe" -cc1 -triple wasm32-unkn
own-emscripten -emit-obj -mrelax-all --mrelax-relocations -disable-free -main-fi
le-name hello_world.c -mrelocation-model static -mframe-pointer=none -fno-roundi
ng-math -mconstructor-aliases -target-cpu generic -fvisibility hidden -debugger-
tuning=gdb -v -resource-dir "C:\wasm-emscripten\emsdk\upstream\lib\clang\1
2.0.0" -D EMSCRIPTEN -D EMSCRIPTEN_major=2 -D EMSCRIPTEN_minor=0 -D EM
SCRIPTEN_tiny
=10 -D _LIBCPP_ABI_VERSION=2 -D unix -D __unix -D unix -isysr
oot "C:\wasm-emscripten\emsdk\upstream\emscripten\system" -internal-isystem
"C:\wasm-emscripten\emsdk\upstream\lib\clang\12.0.0\include" -internal-i
system "C:\wasm-emscripten\emsdk\upstream\emscripten\system/include/wasm32-
emscripten" -internal-isystem "C:\wasm-emscripten\emsdk\upstream\emscripten
\system/include" -Werror=implicit-function-declaration -fdebug-compilation-dir "
C:\wasm-emscripten\emsdk\upstream\emscripten" -ferror-limit 19 -fmessage-len
gth=80 -fgnuc-version=4.2.1 -fignore-exceptions -fcolor-diagnostics "-isystemC:
\wasm-emscripten\emsdk\upstream\emscripten\system\include\SDL" "-isystemC:
\wasm-emscripten\emsdk\upstream\emscripten\cache\wasm\include" "-iwithsys
root/include\compat" "-iwithsysroot/include\libc" "-iwithsysroot/lib\libc\mu
sl\arch\emscripten" "-iwithsysroot/local\include" "-iwithsysroot/include\SSE
" "-iwithsysroot/include\neon" "-iwithsysroot/lib\compiler-rt\include" "-iwit
hsysroot/lib\libunwind\include" -mllvm -combiner-global-alias-analysis=false -
mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o "C:\Users\urza\AppData\
Local\Temp\emscripten_temp_s5t9rfg9\hello_world_0.o" -x c tests/hello_world.c

clang -cc1 version 12.0.0 based upon LLVM 12.0.0git default target x86_64-pc-win
dows-msvc
ignoring nonexistent directory "C:\wasm-emscripten\emsdk\upstream\emscripten\cac
he\wasm\include"
ignoring nonexistent directory "C:\wasm-emscripten\emsdk\upstream\emscripten\sys
tem/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
C:\wasm-emscripten\emsdk\upstream\emscripten\system\include\SDL
C:\wasm-emscripten\emsdk\upstream\emscripten\system/include\compat
C:\wasm-emscripten\emsdk\upstream\emscripten\system/include\libc
C:\wasm-emscripten\emsdk\upstream\emscripten\system/lib\libc\musl\arch\emscript
en
C:\wasm-emscripten\emsdk\upstream\emscripten\system/local\include
C:\wasm-emscripten\emsdk\upstream\emscripten\system/include\SSE
C:\wasm-emscripten\emsdk\upstream\emscripten\system/include\neon
C:\wasm-emscripten\emsdk\upstream\emscripten\system/lib\compiler-rt\include
C:\wasm-emscripten\emsdk\upstream\emscripten\system/lib\libunwind\include
C:\wasm-emscripten\emsdk\upstream\lib\clang\12.0.0\include
C:\wasm-emscripten\emsdk\upstream\emscripten\system/include
End of search list.
cache:INFO: generating system library: libc.a... (this will be cached in "C:\was
m-emscripten\emsdk\upstream\emscripten\cache\wasm\libc.a" for subsequent builds)

C:/wasm-emscripten/emsdk/upstream/bin\llvm-ar.exe: error: C:\Users\urza\AppData
Local\Temp\emscripten_temp_s5t9rfg9\libc.a: permission denied
Traceback (most recent call last):
File "C:\wasm-emscripten\emsdk\upstream\emscripten\emcc.py", line 3313, in
sys.exit(main(sys.argv))
File "C:\wasm-emscripten\emsdk\upstream\emscripten\emcc.py", line 3306, in ma
in
ret = run(args)
File "C:\wasm-emscripten\emsdk\upstream\emscripten\emcc.py", line 2137, in ru
n
extra_files_to_link += system_libs.calculate([f for , f in sorted(temp_file
s)] + extra_files_to_link, link_as_cxx, forced=forced_stdlibs)
File "C:\wasm-emscripten\emsdk\upstream\emscripten\tools\system_libs.py", line
1536, in calculate
add_library(system_libs_map['libc'])
File "C:\wasm-emscripten\emsdk\upstream\emscripten\tools\system_libs.py", line
1479, in add_library
libs_to_link.append((lib.get_path(), need_whole_archive))
File "C:\wasm-emscripten\emsdk\upstream\emscripten\tools\system_libs.py", line
337, in get_path
return shared.Cache.get(self.get_filename(), self.build)
File "C:\wasm-emscripten\emsdk\upstream\emscripten\tools\cache.py", line 127,
in get
temp = creator()
File "C:\wasm-emscripten\emsdk\upstream\emscripten\tools\system_libs.py", line
386, in build
create_lib(out_filename, self.build_objects())
File "C:\wasm-emscripten\emsdk\upstream\emscripten\tools\system_libs.py", line
108, in create_lib
building.emar('cr', libname, inputs)
File "C:\wasm-emscripten\emsdk\upstream\emscripten\tools\building.py", line 81
0, in emar
run_process(cmd, stdout=stdout, stderr=stderr, env=env)
File "C:\wasm-emscripten\emsdk\upstream\emscripten\tools\shared.py", line 94,
in run_process
ret = subprocess.run(cmd, check=check, input=input, *args, **kw)
File "D:\obj\windows-release\37amd64_Release\msi_python\zip_amd64\subprocess.p
y", line 487, in run
subprocess.CalledProcessError: Command '['C:\wasm-emscripten\emsdk\upstream\
emscripten\emar.bat', 'cr', 'C:\Users\urza\AppData\Local\Temp\emscripten

temp_s5t9rfg9\libc.a', '@C:\Users\urza\AppData\Local\Temp\emscripten_gelw
bild.rsp']' returned non-zero exit status 1.

@geogiam-net
Copy link

jinkoo2, move \emsdk\ to c:, remove all read only attributes, that is how I stopped your error and got my error

@jinkoo2
Copy link
Author

jinkoo2 commented Dec 17, 2020

Thanks for the quick reply, geogiam-net!
I just installed an older version as test (1.40.0) and it works well. So, for now, I'll be using a version that works for me. Certainly, the current 'latest' version has issue...

@geogiam-net
Copy link

you are right, thx, now it can do it

@fzy139
Copy link

fzy139 commented Dec 18, 2020

same environment.
delete the upstream folder(wasm-binary) and reinstall the sdk.
2.0.0 works well.
Thanks @jinkoo2

@brupelo
Copy link

brupelo commented Dec 22, 2020

Thanks guys, this thread helped over here, first I tried latest (2.0.11 atm) and I'd get that permission error (win7 and unpacked on d:\software\emscripten). Then I just reverted to 2.0.0 as suggested and I was able to compile the hello world from the official tutorial.

@Xeverous
Copy link

Xeverous commented Jan 3, 2021

Can confirm: same issue for me (newest emscripten on Windows 7). Rolling back to emscripten 2.0.0 fixes the problem.

@Xeverous
Copy link

Xeverous commented Jan 3, 2021

For me 2.0.8 is the latest version that does not have this problem.

@sbc100
Copy link
Collaborator

sbc100 commented Jan 3, 2021

If anyone can figure out what is going on here we would love to see a fix for this.

@brupelo
Copy link

brupelo commented Jan 3, 2021

Probably if some emscripten contributor would make a git-bisect this one would be fixed in no time :)

@kripken
Copy link
Member

kripken commented Jan 8, 2021

There are docs for bisection here: https://emscripten.org/docs/contributing/developers_guide.html#bisecting

Yes, for those that can reproduce this issue, bisection may be the fastest way to find out where this broke, as @brupelo said.

I don't have a windows machine but let me know if there are any questions on those docs.

@Xeverous
Copy link

Xeverous commented Jan 8, 2021

I have no setup currently that could build and install emscripten from specific commits, but I have "bisected" emsdk-downloadable releases:

  • 2.0.8 is the last that works
  • 2.0.9 is the first that does not work

@MrFrenik
Copy link

Still getting this issue. Any word on an official fix for this?

@sbc100
Copy link
Collaborator

sbc100 commented Feb 11, 2021

Unfortunately this issue seems very specific to the virtual environment and the windows filesystem its hard to reproduce or diagnose without that specific setup.

I think we are reliant those of folks who are experiencing this to dig into it and get to the bottom on if. One thing I'm curious about is whether this is actaully a generic llvm / lld issue. The code for writing output files is not specific to wasm-ld so it seems likely. If that is true we should file an upstream issue in the llvm bug tracker.

@MrFrenik
Copy link

Unfortunately this issue seems very specific to the virtual environment and the windows filesystem its hard to reproduce or diagnose without that specific setup.

I think we are reliant those of folks who are experiencing this to dig into it and get to the bottom on if. One thing I'm curious about is whether this is actaully a generic llvm / lld issue. The code for writing output files is not specific to wasm-ld so it seems likely. If that is true we should file an upstream issue in the llvm bug tracker.

I appreciate the quick reply and understand the issue now. Reverting to a previous version seems to have fixed this momentarily. Thanks.

@pineapplemachine
Copy link

I ran into this issue today on Windows 7 trying to compile the hello_world.c example, following the tutorial and using the latest master branch.


Here are the tutorial steps I followed:

https://emscripten.org/docs/getting_started/downloads.html

https://emscripten.org/docs/getting_started/Tutorial.html


Here's a log:

E:\apps\emsdk (master -> origin)
λ ls
bazel/                        emsdk.bat      emsdk_env.fish       legacy-binaryen-tags.txt    python/    upstream/
docker/                       emsdk.ps1      emsdk_env.ps1        legacy-emscripten-tags.txt  README.md  zips/
emcmdprompt.bat               emsdk.py*      emsdk_env.sh         LICENSE                     scripts/
emscripten-releases-tags.txt  emsdk_env.bat  emsdk_manifest.json  llvm-tags-64bit.txt         tests/
emsdk*                        emsdk_env.csh  java/                node/                       tmp/

E:\apps\emsdk (master -> origin)
λ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        tests/

nothing added to commit but untracked files present (use "git add" to track)

E:\apps\emsdk (master -> origin)
λ emsdk install latest
Installing SDK 'sdk-releases-upstream-ce0e4a4d1cab395ee5082a60ebb4f3891a94b256-64bit'..
Skipped installing node-12.18.1-64bit, already installed.
Skipped installing python-3.7.4-pywin32-64bit, already installed.
Skipped installing java-8.152-64bit, already installed.
Skipped installing releases-upstream-ce0e4a4d1cab395ee5082a60ebb4f3891a94b256-64bit, already installed.
Running post-install step: npm ci ...
Running post-install step: npm install google-closure-compiler-windows
Done running: npm ci
Done installing SDK 'sdk-releases-upstream-ce0e4a4d1cab395ee5082a60ebb4f3891a94b256-64bit'.

E:\apps\emsdk (master -> origin)
λ emsdk activate latest
Setting the following tools as active:
   node-12.18.1-64bit
   python-3.7.4-pywin32-64bit
   java-8.152-64bit
   releases-upstream-ce0e4a4d1cab395ee5082a60ebb4f3891a94b256-64bit

Setting environment variables:
PATH = E:\apps\emsdk;E:\apps\emsdk\node\12.18.1_64bit\bin;E:\apps\emsdk\python\3.7.4-pywin32_64bit;E:\apps\emsdk\java\8.152_64bit\bin;E:\apps\emsdk\upstream\emscripten;etc/etc/etc
The changes made to environment variables only apply to the currently running shell instance. Use the 'emsdk_env.bat' to re-enter this environment later, or if you'd like to permanently register this environment permanently, rerun this command with the option --permanent.

E:\apps\emsdk (master -> origin)
λ emsdk_env.bat
Setting environment variables:
PATH = E:\apps\emsdk;E:\apps\emsdk\upstream\emscripten;E:\apps\emsdk\node\12.18.1_64bit\bin;E:\apps\emsdk\python\3.7.4-pywin32_64bit;E:\apps\emsdk\java\8.152_64bit\bin;etc/etc/etc

E:\apps\emsdk (master -> origin)
λ emcc tests/hello_world.c
wasm-ld: error: failed to write the output file: permission denied
emcc: error: 'E:/apps/emsdk/upstream/bin\wasm-ld.exe -o a.out.wasm C:\Users\etc\AppData\Local\Temp\emscripten_temp_d1fmk4ft\hello_world_0.o -LE:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libgl.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libal.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libhtml5.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++-noexcept.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++abi-noexcept.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libdlmalloc.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libsockets.a -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --strip-debug --export main --export emscripten_stack_get_end --export emscripten_stack_get_free --export emscripten_stack_init --export stackSave --export stackRestore --export stackAlloc --export __wasm_call_ctors --export fflush --export __errno_location --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (1)

@sbc100
Copy link
Collaborator

sbc100 commented Feb 12, 2021

Can the compiler write output files to that directory? i.e. can you run emcc -c tests/hello_world.c

@sbc100
Copy link
Collaborator

sbc100 commented Feb 12, 2021

I wonder if the regular lld linker can write output files here? Do you have a vanilla clang/lld installation you should try?

Also, are you using virtual environment? We had some other bugs where folks were using virtual machines and getting unexpected failures that might have looked like this.

@pineapplemachine
Copy link

pineapplemachine commented Feb 12, 2021

@sbc100 The command you suggested runs without errors. I'm not using a VM, but a normal Win7 installation. I can think of no reason why the permissions to this directory should be restricted.

E:\apps\emsdk (master -> origin)
λ emcc --verbose -c tests/hello_world.c
clang version 13.0.0 (Cswircachegitchromium.googlesource.com-external-github.aaakk.us.kg-llvm-llvm--project 8d7cbcf582c5c7bc08a9de7f31fed63bf2687127)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: E:/apps/emsdk/upstream/bin
 (in-process)
 "E:\\apps\\emsdk\\upstream\\bin\\clang.exe" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all --mrelax-relocations -disable-free -main-file-name hello_world.c -mrelocation-model static -mframe-pointer=none -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility hidden -debugger-tuning=gdb -v -resource-dir "E:\\apps\\emsdk\\upstream\\lib\\clang\\13.0.0" -D EMSCRIPTEN -D __EMSCRIPTEN_major__=2 -D __EMSCRIPTEN_minor__=0 -D __EMSCRIPTEN_tiny__=13 -D _LIBCPP_ABI_VERSION=2 -D unix -D __unix -D __unix__ -isysroot "E:\\apps\\emsdk\\upstream\\emscripten\\cache\\sysroot" -c-isystem "C:\\MinGW-3.4.2\\include" -c-isystem "C:\\MinGW-3.4.2\\lib\\gcc\\mingw32\\3.4.2\\include" -cxx-isystem "C:\\MinGW\\include" -cxx-isystem "C:\\MinGW\\lib\\gcc\\mingw32\\3.4.2\\include" -cxx-isystem "C:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include\\c++" -internal-isystem "E:\\apps\\emsdk\\upstream\\lib\\clang\\13.0.0\\include" -internal-isystem "E:\\apps\\emsdk\\upstream\\emscripten\\cache\\sysroot/include/wasm32-emscripten" -internal-isystem "E:\\apps\\emsdk\\upstream\\emscripten\\cache\\sysroot/include" -Werror=implicit-function-declaration -fdebug-compilation-dir "E:\\apps\\emsdk" -ferror-limit 19 -fmessage-length=126 -fgnuc-version=4.2.1 -fignore-exceptions -fcolor-diagnostics -iwithsysroot/include/SDL "-iwithsysroot/include\\compat" -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o hello_world.o -x c tests/hello_world.c
clang -cc1 version 13.0.0 based upon LLVM 13.0.0git default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++"
ignoring nonexistent directory "E:\apps\emsdk\upstream\emscripten\cache\sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 E:\apps\emsdk\upstream\emscripten\cache\sysroot/include/SDL
 E:\apps\emsdk\upstream\emscripten\cache\sysroot/include\compat
 C:\MinGW-3.4.2\include
 C:\MinGW-3.4.2\lib\gcc\mingw32\3.4.2\include
 E:\apps\emsdk\upstream\lib\clang\13.0.0\include
 E:\apps\emsdk\upstream\emscripten\cache\sysroot/include
End of search list.

Clang compiles hello_world.c without errors.

E:\apps\emsdk (master -> origin)
λ cd tests

E:\apps\emsdk\tests (master -> origin)
λ clang --version
clang version 10.0.1 (https://github.com/Alexpux/MINGW-packages.git 94b687508346d10cec7e8c769785f73da18b4e54)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:\msys64\mingw64\bin

E:\apps\emsdk\tests (master -> origin)
λ clang hello_world.c

E:\apps\emsdk\tests (master -> origin)
λ ls
a.exe*  hello_world.c

E:\apps\emsdk\tests (master -> origin)
λ a.exe
hello, world!

@Xeverous
Copy link

I have this issue without using any virtual machine.

@sbc100
Copy link
Collaborator

sbc100 commented Feb 12, 2021

Interesting. Can you run that clang command again with -v. i.e. clang hello_world.c -v ? I'm curious if its using lld to link?

@sbc100
Copy link
Collaborator

sbc100 commented Feb 12, 2021

Looking at the wasm-ld code it seems that file is opened successfully here:
https://github.com/llvm/llvm-project/blob/0b1914e83a03be926569892c17ca743c5ea46d1f/lld/wasm/Writer.cpp#L1499

But then the commit to disc fails here:
https://github.com/llvm/llvm-project/blob/0b1914e83a03be926569892c17ca743c5ea46d1f/lld/wasm/Writer.cpp#L1491

Looking at the COFF linker (the one that normal clang/lld is using) the code looks roughly the same:
https://github.com/llvm/llvm-project/blob/0b1914e83a03be926569892c17ca743c5ea46d1f/lld/COFF/Writer.cpp#L1526
and:
https://github.com/llvm/llvm-project/blob/0b1914e83a03be926569892c17ca743c5ea46d1f/lld/COFF/Writer.cpp#L658

.. so i wonder why one works here and the other doesn't (assuming windows COFF lld is actually used and working above).

@pineapplemachine
Copy link

pineapplemachine commented Feb 12, 2021

@sbc100 Here you go:

I tried clang -c ... followed by invoking lld-link manually but I proved too dim to give it lld-link functioning command line arguments. I'm happy to follow more troubleshooting instructions from someone who knows this toolchain better than I do.

E:\apps\emsdk\tests (master -> origin)
λ clang -v hello_world.c
clang version 10.0.1 (https://github.com/Alexpux/MINGW-packages.git 94b687508346d10cec7e8c769785f73da18b4e54)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:\msys64\mingw64\bin
 "C:\\msys64\\mingw64\\bin\\clang.exe" -cc1 -triple x86_64-w64-windows-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello_world.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir "C:\\msys64\\mingw64\\lib\\clang\\10.0.1" -c-isystem "C:\\MinGW-3.4.2\\include" -c-isystem "C:\\MinGW-3.4.2\\lib\\gcc\\mingw32\\3.4.2\\include" -cxx-isystem "C:\\MinGW\\include" -cxx-isystem "C:\\MinGW\\lib\\gcc\\mingw32\\3.4.2\\include" -cxx-isystem "C:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include\\c++" -internal-isystem "C:\\msys64\\mingw64\\lib\\clang\\10.0.1\\include" -internal-isystem "C:\\msys64\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/include" -internal-isystem "C:\\msys64\\mingw64\\x86_64-w64-mingw32\\include" -internal-isystem "C:\\msys64\\mingw64\\include" -fdebug-compilation-dir "E:\\apps\\emsdk\\tests" -ferror-limit 19 -fmessage-length 126 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fseh-exceptions -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o "C:\\Users\\Sophie\\AppData\\Local\\Temp\\hello_world-199135.o" -x c hello_world.c
clang -cc1 version 10.0.1 based upon LLVM 10.0.1 default target x86_64-w64-windows-gnu
ignoring nonexistent directory "C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++"
ignoring nonexistent directory "C:\msys64\mingw64\x86_64-w64-mingw32/sys-root/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
 C:\MinGW-3.4.2\include
 C:\MinGW-3.4.2\lib\gcc\mingw32\3.4.2\include
 C:\msys64\mingw64\lib\clang\10.0.1\include
 C:\msys64\mingw64\x86_64-w64-mingw32\include
 C:\msys64\mingw64\include
End of search list.
 "C:\\msys64\\mingw64\\bin\\ld" -m i386pep -Bdynamic -o a.exe "C:\\msys64\\mingw64\\x86_64-w64-mingw32\\lib\\crt2.o" "C:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\10.2.0\\crtbegin.o" "-LC:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\10.2.0" "-LC:\\msys64\\mingw64\\x86_64-w64-mingw32\\lib" "-LC:\\msys64\\mingw64\\lib" "-LC:\\msys64\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/lib" "C:\\Users\\Sophie\\AppData\\Local\\Temp\\hello_world-199135.o" -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt "C:\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\10.2.0\\crtend.o"

@pineapplemachine
Copy link

More futzing about:

I'm running this CLI as an administrator. wasm-ld has got to be doing something strange for it to be denied access to anything.


E:\apps\emsdk\tests (master -> origin)
λ emcc -c hello_world.c -o hello_world.o --verbose
clang version 13.0.0 (Cswircachegitchromium.googlesource.com-external-github.aaakk.us.kg-llvm-llvm--project 8d7cbcf582c5c7bc08a9de7f31fed63bf2687127)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: E:/apps/emsdk/upstream/bin
 (in-process)
 "E:\\apps\\emsdk\\upstream\\bin\\clang.exe" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all --mrelax-relocations -disable-free -main-file-name hello_world.c -mrelocation-model static -mframe-pointer=none -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility hidden -debugger-tuning=gdb -v -resource-dir "E:\\apps\\emsdk\\upstream\\lib\\clang\\13.0.0" -D EMSCRIPTEN -D __EMSCRIPTEN_major__=2 -D __EMSCRIPTEN_minor__=0 -D __EMSCRIPTEN_tiny__=13 -D _LIBCPP_ABI_VERSION=2 -D unix -D __unix -D __unix__ -isysroot "E:\\apps\\emsdk\\upstream\\emscripten\\cache\\sysroot" -c-isystem "C:\\MinGW-3.4.2\\include" -c-isystem "C:\\MinGW-3.4.2\\lib\\gcc\\mingw32\\3.4.2\\include" -cxx-isystem "C:\\MinGW\\include" -cxx-isystem "C:\\MinGW\\lib\\gcc\\mingw32\\3.4.2\\include" -cxx-isystem "C:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include\\c++" -internal-isystem "E:\\apps\\emsdk\\upstream\\lib\\clang\\13.0.0\\include" -internal-isystem "E:\\apps\\emsdk\\upstream\\emscripten\\cache\\sysroot/include/wasm32-emscripten" -internal-isystem "E:\\apps\\emsdk\\upstream\\emscripten\\cache\\sysroot/include" -Werror=implicit-function-declaration -fdebug-compilation-dir "E:\\apps\\emsdk\\tests" -ferror-limit 19 -fmessage-length=126 -fgnuc-version=4.2.1 -fignore-exceptions -fcolor-diagnostics -iwithsysroot/include/SDL "-iwithsysroot/include\\compat" -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o hello_world.o -x c hello_world.c
clang -cc1 version 13.0.0 based upon LLVM 13.0.0git default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++"
ignoring nonexistent directory "E:\apps\emsdk\upstream\emscripten\cache\sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 E:\apps\emsdk\upstream\emscripten\cache\sysroot/include/SDL
 E:\apps\emsdk\upstream\emscripten\cache\sysroot/include\compat
 C:\MinGW-3.4.2\include
 C:\MinGW-3.4.2\lib\gcc\mingw32\3.4.2\include
 E:\apps\emsdk\upstream\lib\clang\13.0.0\include
 E:\apps\emsdk\upstream\emscripten\cache\sysroot/include
End of search list.

E:\apps\emsdk\tests (master -> origin)
λ E:/apps/emsdk/upstream/bin\wasm-ld.exe -o a.out.wasm hello_world.o -LE:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libgl.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libal.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libhtml5.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++-noexcept.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++abi-noexcept.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libdlmalloc.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libsockets.a -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined --strip-debug --export main --export emscripten_stack_get_end --export emscripten_stack_get_free --export emscripten_stack_init --export stackSave --export stackRestore --export stackAlloc --export __wasm_call_ctors --export fflush --export __errno_location --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024 --verbose
wasm-ld: Loading: hello_world.o
wasm-ld: Loading: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libgl.a
wasm-ld: Loading: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libal.a
wasm-ld: Loading: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libhtml5.a
wasm-ld: Loading: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a
wasm-ld: Loading: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a
wasm-ld: Loading: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++-noexcept.a
wasm-ld: Loading: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++abi-noexcept.a
wasm-ld: Loading: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libdlmalloc.a
wasm-ld: Loading: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a
wasm-ld: Loading: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libsockets.a
wasm-ld: Processing: hello_world.o
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libgl.a
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libal.a
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libhtml5.a
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++-noexcept.a
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc++abi-noexcept.a
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libdlmalloc.a
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(printf.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(stdout.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(__stdio_write.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(wasi-helpers.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(__errno_location.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(vfprintf.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(emscripten_memset.o)

wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(isdigit.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(memchr.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(wctomb.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(wcrtomb.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(emscripten_pthread.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(libc.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(frexp.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a(trunctfdf2.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a(ashlti3.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a(lshrti3.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(fwrite.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(__towrite.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(__stdio_exit.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(ofl.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(extras.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(emscripten_memcpy.o)

wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(__lockfile.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libsockets.a
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a(stack_limits.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a(stack_ops.o)
wasm-ld: Processing: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(fflush.o)
wasm-ld: -- createOutputSegments
wasm-ld: -- createSyntheticSections
wasm-ld: -- populateProducers
wasm-ld: -- calculateImports
wasm-ld: -- layoutMemory
wasm-ld: mem: global base = 1024
wasm-ld: mem: .rodata         offset=1024     size=565      align=4
wasm-ld: mem: .data           offset=1592     size=376      align=3
wasm-ld: mem: .bss            offset=1968     size=1124     align=4
wasm-ld: mem: static data = 2068
wasm-ld: mem: stack size  = 5242880
wasm-ld: mem: stack base  = 3104
wasm-ld: mem: stack top   = 5245984
wasm-ld: mem: heap base   = 5245984
wasm-ld: mem: total pages = 256
wasm-ld: mem: max pages   = 256
wasm-ld: -- scanRelocations
wasm-ld: -- finalizeIndirectFunctionTable
wasm-ld: -- createSyntheticInitFunctions
wasm-ld: -- assignIndexes
wasm-ld: -- calculateInitFunctions
wasm-ld: -- calculateTypes
wasm-ld: -- calculateExports
wasm-ld: -- calculateCustomSections
wasm-ld: calculateCustomSections
wasm-ld: -- populateSymtab
wasm-ld: -- populateTargetFeatures
wasm-ld: -- addSections
wasm-ld: addSection: TYPE
wasm-ld: addSection: IMPORT
wasm-ld: addSection: FUNCTION
wasm-ld: addSection: TABLE
wasm-ld: addSection: MEMORY
wasm-ld: addSection: GLOBAL
wasm-ld: addSection: EXPORT
wasm-ld: addSection: ELEM
wasm-ld: addSection: CODE
wasm-ld: addSection: DATA
wasm-ld: createCustomSections
wasm-ld: addSection: CUSTOM(producers)
wasm-ld: Defined Functions: 49
wasm-ld: Defined Globals  : 3
wasm-ld: Defined Events   : 0
wasm-ld: Defined Tables   : 1
wasm-ld: Function Imports : 2
wasm-ld: Global Imports   : 0
wasm-ld: Event Imports    : 0
wasm-ld: Table Imports    : 0
wasm-ld: info for: hello_world.o
              Symbols : 16
     Function Imports : 5
       Global Imports : 1
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(__errno_location.o)
              Symbols : 2
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(wasi-helpers.o)
              Symbols : 5
     Function Imports : 2
       Global Imports : 1
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(__stdio_write.o)
              Symbols : 4
     Function Imports : 2
       Global Imports : 1
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(stdout.o)
              Symbols : 8
     Function Imports : 1
       Global Imports : 0
        Event Imports : 0
        Table Imports : 1
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(emscripten_memset.o)
              Symbols : 1
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(isdigit.o)
              Symbols : 3
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(memchr.o)
              Symbols : 1
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(libc.o)
              Symbols : 7
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(emscripten_pthread.o)
              Symbols : 4
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(wcrtomb.o)
              Symbols : 3
     Function Imports : 2
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(wctomb.o)
              Symbols : 2
     Function Imports : 1
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(frexp.o)
              Symbols : 1
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a(ashlti3.o)
              Symbols : 1
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a(lshrti3.o)
              Symbols : 1
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a(trunctfdf2.o)
              Symbols : 4
     Function Imports : 2
       Global Imports : 1
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(extras.o)
              Symbols : 8
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(ofl.o)
              Symbols : 6
     Function Imports : 2
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(__stdio_exit.o)
              Symbols : 10
     Function Imports : 2
       Global Imports : 0
        Event Imports : 0
        Table Imports : 1
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(__towrite.o)
              Symbols : 3
     Function Imports : 1
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(emscripten_memcpy.o)
              Symbols : 2
     Function Imports : 1
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(fwrite.o)
              Symbols : 8
     Function Imports : 4
       Global Imports : 0
        Event Imports : 0
        Table Imports : 1
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(vfprintf.o)
              Symbols : 37
     Function Imports : 10
       Global Imports : 1
        Event Imports : 0
        Table Imports : 1
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(printf.o)
              Symbols : 8
     Function Imports : 3
       Global Imports : 1
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc_rt_wasm.a(__lockfile.o)
              Symbols : 2
     Function Imports : 0
       Global Imports : 0
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a(stack_limits.o)
              Symbols : 10
     Function Imports : 0
       Global Imports : 1
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libcompiler_rt.a(stack_ops.o)
              Symbols : 5
     Function Imports : 0
       Global Imports : 1
        Event Imports : 0
        Table Imports : 0
wasm-ld: info for: E:\apps\emsdk\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libc.a(fflush.o)
              Symbols : 10
     Function Imports : 4
       Global Imports : 0
        Event Imports : 0
        Table Imports : 1
wasm-ld: -- finalizeSections
wasm-ld: setOffset: TYPE: 8
wasm-ld: createHeader: TYPE body=138 total=141
wasm-ld: setOffset: IMPORT: 149
wasm-ld: createHeader: IMPORT body=63 total=65
wasm-ld: setOffset: FUNCTION: 214
wasm-ld: createHeader: FUNCTION body=50 total=52
wasm-ld: setOffset: TABLE: 266
wasm-ld: createHeader: TABLE body=5 total=7
wasm-ld: setOffset: MEMORY: 273
wasm-ld: createHeader: MEMORY body=6 total=8
wasm-ld: setOffset: GLOBAL: 281
wasm-ld: createHeader: GLOBAL body=19 total=21
wasm-ld: setOffset: EXPORT: 302
wasm-ld: createHeader: EXPORT body=212 total=215
wasm-ld: setOffset: ELEM: 517
wasm-ld: createHeader: ELEM body=11 total=13
wasm-ld: setOffset: CODE: 530
wasm-ld: createHeader: CODE body=10765 total=10768
wasm-ld: setOffset: DATA: 11298
wasm-ld: Data segment: size=565, startVA=400, name=.rodata
wasm-ld: Data segment: size=376, startVA=638, name=.data
wasm-ld: createHeader: DATA body=956 total=959
wasm-ld: setOffset: CUSTOM(producers): 12257
wasm-ld: createHeader: CUSTOM(producers) body=162 total=165
wasm-ld: -- writeMapFile
wasm-ld: -- openFile
wasm-ld: writing: a.out.wasm
wasm-ld: -- writeSections
wasm-ld: writing CUSTOM(producers)
wasm-ld: writing MEMORY
wasm-ld: writing IMPORT
wasm-ld: writing TYPE
wasm-ld: writing EXPORT
wasm-ld: writing GLOBAL
wasm-ld: writing DATA size=959 body=956
wasm-ld: writing TABLE
wasm-ld: writing FUNCTION
wasm-ld: writing CODE
wasm-ld:  size=10768
wasm-ld:  headersize=3
wasm-ld:  codeheadersize=1
wasm-ld: writing ELEM
wasm-ld: error: failed to write the output file: permission denied

@pineapplemachine
Copy link

pineapplemachine commented Feb 12, 2021

I can confirm that the tutorial works with version 2.0.8 on my Windows 7 installation:

E:\apps\emsdk\tests (master -> origin)
λ cd ../

E:\apps\emsdk (master -> origin)
λ emsdk install 2.0.8
Installing SDK 'sdk-releases-upstream-e4ed6c79f4db8b175d9bbe55869b697aba9bcf2a-64bit'..
Skipped installing node-12.18.1-64bit, already installed.
Skipped installing python-3.7.4-pywin32-64bit, already installed.
Skipped installing java-8.152-64bit, already installed.
Installing tool 'releases-upstream-e4ed6c79f4db8b175d9bbe55869b697aba9bcf2a-64bit'..
Downloading: E:/apps/emsdk/zips/e4ed6c79f4db8b175d9bbe55869b697aba9bcf2a-wasm-binaries.zip from https://storage.googleapis.com/webassembly/emscripten-releases-builds/win/e4ed6c79f4db8b175d9bbe55869b697aba9bcf2a/wasm-binaries.zip, 456385144 Bytes
Unpacking 'E:/apps/emsdk/zips/e4ed6c79f4db8b175d9bbe55869b697aba9bcf2a-wasm-binaries.zip' to 'E:/apps/emsdk/upstream'
Done installing tool 'releases-upstream-e4ed6c79f4db8b175d9bbe55869b697aba9bcf2a-64bit'.
Running post-install step: npm ci ...
Running post-install step: npm install google-closure-compiler-windows
Done running: npm ci
Done installing SDK 'sdk-releases-upstream-e4ed6c79f4db8b175d9bbe55869b697aba9bcf2a-64bit'.

E:\apps\emsdk (master -> origin)
λ emsdk activate 2.0.8
Setting the following tools as active:
   node-12.18.1-64bit
   python-3.7.4-pywin32-64bit
   java-8.152-64bit
   releases-upstream-e4ed6c79f4db8b175d9bbe55869b697aba9bcf2a-64bit

Setting environment variables:
PATH = E:\apps\emsdk;E:\apps\emsdk\node\12.18.1_64bit\bin;E:\apps\emsdk\python\3.7.4-pywin32_64bit;E:\apps\emsdk\java\8.152_64bit\bin;E:\apps\emsdk\upstream\emscripten;etc
The changes made to environment variables only apply to the currently running shell instance. Use the 'emsdk_env.bat' to re-enter this environment later, or if you'd like to permanently register this environment permanently, rerun this command with the option --permanent.

E:\apps\emsdk (master -> origin)
λ emsdk_env.bat
Setting environment variables:
PATH = E:\apps\emsdk;E:\apps\emsdk\upstream\emscripten;E:\apps\emsdk\node\12.18.1_64bit\bin;E:\apps\emsdk\python\3.7.4-pywin32_64bit;E:\apps\emsdk\java\8.152_64bit\bin;etc

E:\apps\emsdk (master -> origin)
λ emcc tests/hello_world.c --verbose
clang version 12.0.0 (Cswircachegitchromium.googlesource.com-external-github.aaakk.us.kg-llvm-llvm--project 1a7a9efec3cf872dcf3e1a6e6fe39e797c4d9fc6)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: E:/apps/emsdk/upstream/bin
 (in-process)
 "E:\\apps\\emsdk\\upstream\\bin\\clang.exe" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all --mrelax-relocations -disable-free -main-file-name hello_world.c -mrelocation-model static -mframe-pointer=none -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility hidden -debugger-tuning=gdb -v -resource-dir "E:\\apps\\emsdk\\upstream\\lib\\clang\\12.0.0" -D __EMSCRIPTEN_major__=2 -D __EMSCRIPTEN_minor__=0 -D __EMSCRIPTEN_tiny__=8 -D _LIBCPP_ABI_VERSION=2 -D unix -D __unix -D __unix__ -D EMSCRIPTEN -c-isystem "C:\\MinGW-3.4.2\\include" -c-isystem "C:\\MinGW-3.4.2\\lib\\gcc\\mingw32\\3.4.2\\include" -cxx-isystem "C:\\MinGW\\include" -cxx-isystem "C:\\MinGW\\lib\\gcc\\mingw32\\3.4.2\\include" -cxx-isystem "C:\\MinGW\\lib\\gcc\\mingw32\\4.8.1\\include\\c++" -internal-isystem "E:\\apps\\emsdk\\upstream\\lib\\clang\\12.0.0\\include" -internal-isystem /include/wasm32-emscripten -internal-isystem /include -Werror=implicit-function-declaration -fdebug-compilation-dir "E:\\apps\\emsdk" -ferror-limit 19 -fmessage-length=126 -fgnuc-version=4.2.1 -fignore-exceptions -fcolor-diagnostics -nostdsysteminc "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\system\\include\\compat" "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\system\\include" "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\system\\include\\libc" "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\system\\lib\\libc\\musl\\arch\\emscripten" "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\system\\local\\include" "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\system\\include\\SSE" "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\system\\include\\neon" "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\system\\lib\\compiler-rt\\include" "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\system\\lib\\libunwind\\include" "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\cache\\wasm\\include" "-isystemE:\\apps\\emsdk\\upstream\\emscripten\\system\\include\\SDL" -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o "C:\\Users\\etc\\AppData\\Local\\Temp\\emscripten_temp_j4yv32w2\\hello_world_0.o" -x c tests/hello_world.c
clang -cc1 version 12.0.0 based upon LLVM 12.0.0git default target x86_64-pc-windows-msvc
ignoring nonexistent directory "E:\apps\emsdk\upstream\emscripten\cache\wasm\include"
ignoring nonexistent directory "C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++"
ignoring nonexistent directory "/include/wasm32-emscripten"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 E:\apps\emsdk\upstream\emscripten\system\include\compat
 E:\apps\emsdk\upstream\emscripten\system\include
 E:\apps\emsdk\upstream\emscripten\system\include\libc
 E:\apps\emsdk\upstream\emscripten\system\lib\libc\musl\arch\emscripten
 E:\apps\emsdk\upstream\emscripten\system\local\include
 E:\apps\emsdk\upstream\emscripten\system\include\SSE
 E:\apps\emsdk\upstream\emscripten\system\include\neon
 E:\apps\emsdk\upstream\emscripten\system\lib\compiler-rt\include
 E:\apps\emsdk\upstream\emscripten\system\lib\libunwind\include
 E:\apps\emsdk\upstream\emscripten\system\include\SDL
 C:\MinGW-3.4.2\include
 C:\MinGW-3.4.2\lib\gcc\mingw32\3.4.2\include
 E:\apps\emsdk\upstream\lib\clang\12.0.0\include
End of search list.

E:\apps\emsdk (master -> origin)
λ ls
a.exe*           emscripten-releases-tags.txt  emsdk_env.csh        java/                       python/    zips/
a.out.js         emsdk*                        emsdk_env.fish       legacy-binaryen-tags.txt    README.md
a.out.wasm       emsdk.bat                     emsdk_env.ps1        legacy-emscripten-tags.txt  scripts/
bazel/           emsdk.ps1                     emsdk_env.sh         LICENSE                     tests/
docker/          emsdk.py*                     emsdk_manifest.json  llvm-tags-64bit.txt         tmp/
emcmdprompt.bat  emsdk_env.bat                 hello_world.o        node/                       upstream/

E:\apps\emsdk (master -> origin)
λ node a.out.js
hello, world!

@sbc100
Copy link
Collaborator

sbc100 commented Feb 12, 2021

The difference with 2.0.8 I believe is that we used to link to temp directory and then copy the resulting wasm file into place. With newer versions of emscripten we have wasm-ld link directly to the final location which I believe is what is causing this issue.

Reverting to linking a temp directory and copying doesn't seem a like a very satisfying solution. I think it would be good to find out what is really going on here.

@pineapplemachine
Copy link

pineapplemachine commented Feb 12, 2021

@sbc100 I really don't know enough about emscripten or LLVM generally to debug this myself, but please feel free to give me a @mention if you have tests or troubleshooting steps you'd like me to try on my Win7 machine.

@LinArcX
Copy link

LinArcX commented Feb 14, 2021

Same issue with 2.0.13 and 2.0.10.

@sbc100
Copy link
Collaborator

sbc100 commented Feb 14, 2021

What is the common theme here? Is this limited to windows 7?

@sbc100
Copy link
Collaborator

sbc100 commented Mar 3, 2021

Will be interesting to see if this is fixed by https://reviews.llvm.org/D81803

@pineapplemachine
Copy link

On the contrary @sbc100 that seems to be the change that broke it.

From the most recent comment on the thread:

Just FTR, this change had to be reverted in Rust's LLVM fork because it breaks compilation on Windows 7, see rust-lang/rust#81051.

@sbc100
Copy link
Collaborator

sbc100 commented Mar 5, 2021

Oh interesting! Anyway it looks like we found culprit and indeed it seems not to be emscripten-specific but a general llvm issue.

@aganea
Copy link

aganea commented Mar 24, 2021

Hello! I've fixed the issue in llvm/llvm-project@64ab2b6 - please let me know if the issue is still there in the next code drop.

@amboowang
Copy link

I install the latest version (2.0.30) and it also such error. I try to install the 2.0.0 version then it worked.

amboo@ubuntu:/mnt/hgfs/workdir/wasm$ emcc hello_world.c
wasm-ld: error: cannot open output file a.out.wasm: Input/output error
emcc: error: '/home/amboo/emsdk/upstream/bin/wasm-ld -o a.out.wasm /tmp/emscripten_temp_hokx0eoj/hello_world_0.o -L/home/amboo/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -ldlmalloc -lc_rt_wasm -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --strip-debug --export-if-defined=main --export-if-defined=emscripten_stack_get_end --export-if-defined=emscripten_stack_get_free --export-if-defined=emscripten_stack_init --export-if-defined=stackSave --export-if-defined=stackRestore --export-if-defined=stackAlloc --export-if-defined=__wasm_call_ctors --export-if-defined=fflush --export-if-defined=__errno_location --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=16777216 --global-base=1024' failed (returned 1)

@sbc100
Copy link
Collaborator

sbc100 commented Sep 29, 2021

Yes, there seems to be a bug with the way that llvm (wasm-ld) creates it output files. It seem to trigger and i/o error in certain circumstances that seem to be where the output file lives on a mounted of a windows filesystem in a virtual environment?

@amboowang can you confirm some things about your environment? Are you using a linux VM inside of windows? What virtualization system are you using? If /mnt/hgfs/workdir/wasm inside a windows filesystem? Does the issue go away when you run this command from a non-windows filesystem (e.g. /tmp?) What version of windows are you using?

@sbc100
Copy link
Collaborator

sbc100 commented Sep 29, 2021

The reason this started happening between 2.0.0 and 2.0.30 is explained #13067 (comment)

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

No branches or pull requests