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

cosmoc? #1

Open
coderofsalvation opened this issue Nov 4, 2021 · 11 comments
Open

cosmoc? #1

coderofsalvation opened this issue Nov 4, 2021 · 11 comments

Comments

@coderofsalvation
Copy link

Im trying to get the ./mk script to work..but can't find cosmoc in this / the cosmopolitan repo..where to get it?

@jacereda
Copy link
Owner

jacereda commented Nov 4, 2021

Cosmoc is just a wrapper to normal gcc with cosmopolitan options. In my case it looks like:

exec /nix/store/s5hkav7whndbfz0szshpb46h4idqdq9a-gcc-wrapper-10.3.0/bin/gcc -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone -fno-omit-frame-pointer -pg -mnop-mcount -fno-stack-protector -include /nix/store/vd0p0ni2ciisy8136niqpwc4c31m0mrh-cosmopolitan-git/lib/include/cosmopolitan.h "$@" -Wl,--gc-sections -Wl,-z,max-page-size=0x1000 -fuse-ld=bfd -Wl,-T,/nix/store/vd0p0ni2ciisy8136niqpwc4c31m0mrh-cosmopolitan-git/lib/ape.lds /nix/store/vd0p0ni2ciisy8136niqpwc4c31m0mrh-cosmopolitan-git/lib/{crt.o,ape.o,cosmopolitan.a}

Are you using nixpgks? If so, I can probably upload a decent default.nix that setups everything automatically.

@coderofsalvation
Copy link
Author

coderofsalvation commented Nov 5, 2021 via email

@jacereda
Copy link
Owner

jacereda commented Nov 6, 2021

Can you try now? Unless I messed something, this should work:

cd cosmogfx
nix-shell
./mk

The executable should now work on Linux, Windows, NetBSD and FreeBSD.

@coderofsalvation
Copy link
Author

coderofsalvation commented Nov 6, 2021 via email

@coderofsalvation
Copy link
Author

Thx, this is my output:

$ nix-shell
....
    66,636⏰    66,636⏳  13,488k       0iop o//third_party/python/pythontester.com -m test.test_dictviews
    67,056⏰    67,069⏳  13,448k       0iop o//third_party/python/pythontester.com -m test.test_dictcomps
    78,812⏰    78,843⏳  13,452k       0iop o//third_party/python/pythontester.com -m test.test_subclassinit
   770,278⏰   768,053⏳  49,268k       0iop o//third_party/python/pythontester.com -m test.test_zlib
 2,973,721⏰  2,968,926⏳  67,988k     472iop o//third_party/python/pythontester.com -m test.test_bz2
installing
rm: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
/bin/sh: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
dircolors: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
uname: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
stty: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
whoami: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
$

@jacereda
Copy link
Owner

jacereda commented Nov 9, 2021

I see.. Looks like a mess with runtimes. I'll try to simplify it so it doesn't depend on my nixpkgs fork.

@jacereda
Copy link
Owner

jacereda commented Nov 9, 2021

Meanwhile, does nix-shell --pure work?

@jacereda
Copy link
Owner

jacereda commented Nov 9, 2021

Can you please try again with the latest changes?

@coderofsalvation
Copy link
Author

coderofsalvation commented Nov 16, 2021

interesting, it crashed somewhere during the cosmopolitan tests

$ nix-shell --pure
....
7000000df430 00000062f41d _PyFunction_FastCall+109                                                                                                                                                                         
7000000df460 00000063029a fast_function+442                                                                                                                                                                                
7000000df4a0 000000630835 call_function+245                                                                                                                                                                                
7000000df4f0 000000635384 _PyEval_EvalFrameDefault+16004                                                     
7000000df610 00000063000f _PyEval_EvalCodeWithName+2271                                                      
7000000df6c0 000000630c9c PyEval_EvalCode+44                                                                 
7000000df720 00000062da64 builtin_exec_impl+479                                                              
7000000df760 00000062db48 builtin_exec+102                                                                   
7000000df7a0 0000005c1e4c _PyCFunction_FastCallKeywords+510                                                  
7000000df800 0000006309b9 call_function+633                                                                                                                                                                                
7000000df850 000000635384 _PyEval_EvalFrameDefault+16004                                                     
7000000df970 00000063000f _PyEval_EvalCodeWithName+2271                                                      
7000000dfa20 00000063017c fast_function+156                                                                  
7000000dfab0 000000630835 call_function+245                                                                  
7000000dfb00 000000635384 _PyEval_EvalFrameDefault+16004                                                     
7000000dfc20 00000063000f _PyEval_EvalCodeWithName+2271                                                      
7000000dfcd0 000000630d22 PyEval_EvalCodeEx+66                                                               
<truncated backtrace>                                                                                        
                                                                                                                                                                                                                           
`make MODE= -j8 o//third_party/python/Lib/test/test_pickle.py.runs` exited with 23:                          
o//third_party/python/pythontester.com -m test.test_pickle                                                   
consumed 13,171,706µs wall time                                                                              
ballooned to 37,952kb in size                                                                                
needed 12,988,666us cpu (1% kernel)                                                                          
caused 84,452 page faults (100% memcpy)                                                                      
900 context switch (0% consensual)                                                                                                                                                                                         
                                                                                                             
make: *** [third_party/python/python.mk:2704: o//third_party/python/Lib/test/test_pickle.py.runs] Error 23   
make: *** Waiting for unfinished jobs....                                                                    
18,374,233⏰ 18,163,338⏳ 123,960k       0iop o//third_party/python/pythontester.com -m test.test_decimal                                                                                                                  
builder for '/nix/store/mc4yz22nb9ci1pqwk380l1fs1k20jdkr-cosmopolitan-git.drv' failed with exit code 2                                                                                                                     
error: build of '/nix/store/mc4yz22nb9ci1pqwk380l1fs1k20jdkr-cosmopolitan-git.drv' failed                

which is strange because cosmopolitan builds fine outside of nix (~6G free mem):

$ cat /proc/meminfo |grep ^Mem
MemTotal:         12006276 kB
MemFree:           3074232 kB
MemAvailable:    5867632 kB

Since I already had cosmopolitan on my drive, I symlinked it and adjusted mk:

$ git clone https://github.com/jacereda/cosmogfx --recurse-submodules
$ cd cosmogfx
cosmogfx $ ln -s ../cosmopolitan .
cosmogfx $ git diff mk
diff --git a/mk b/mk
index 1c886a0..3cc5bba 100755
--- a/mk
+++ b/mk
@@ -1,4 +1,8 @@
 #!/usr/bin/env bash
+cosmoc(){
+  cosmopolitan/o/tool/build/compile.com gcc "$@"
+}
+export PATH=$PATH:cosmopolitan/o/tool/build
 set -e
 install -d b
 gcc -s -ffunction-sections -fdata-sections -Wl,-gc-sections -fomit-frame-pointer -Os -pie -fPIC helper.c -o helper/linux -ldl
@@ -13,8 +17,9 @@ cosmoc -DDLOPEN=z_dlopen \
        -DELFCLASS=ELFCLASS64 \
        -DCV_NO_MAIN \
        -DCV_DYN \
-       -include cosmopolitan.h \
+       -include cosmopolitan/o/cosmopolitan.h \
        -I. \
+       -Icosmopolitan \
        -Imicroui/demo \
        -Imicroui/src \
        -Ifake \

Which got me this output:

$ ./mk
/usr/bin/ld: /tmp/ccyAFSBD.o:(.bss.z_dlopen+0x0): multiple definition of `z_dlopen'; /tmp/cczXXTJE.o:(.bss.z_dlopen+0x0): first defined here
/usr/bin/ld: /tmp/ccyAFSBD.o:(.bss.z_dlsym+0x0): multiple definition of `z_dlsym'; /tmp/cczXXTJE.o:(.bss.z_dlsym+0x0): first defined here
/usr/bin/ld: /tmp/ccyAFSBD.o:(.bss.z_dlclose+0x0): multiple definition of `z_dlclose'; /tmp/cczXXTJE.o:(.bss.z_dlclose+0x0): first defined here                                                                            /usr/bin/ld: /tmp/ccyAFSBD.o:(.bss.z_dlerror+0x0): multiple definition of `z_dlerror'; /tmp/cczXXTJE.o:(.bss.z_dlerror+0x0): first defined here                                                                            /usr/bin/ld: /tmp/cczXXTJE.o: relocation R_X86_64_32 against `.text.trampoline' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /tmp/ccFYqk8g.o: relocation R_X86_64_32S against undefined symbol `__sysv2nt' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: /tmp/ccFJKOhU.o: warning: relocation against `AT_PHNUM' in read-only section `.text.elf_exec'
/usr/bin/ld: /tmp/cczXXTJE.o: in function `myvsnprintf':
cosmogfx.c:(.text.myvsnprintf+0x68): undefined reference to `__assert_fail'
/usr/bin/ld: /tmp/cczXXTJE.o: in function `bitarrayFor':
cosmogfx.c:(.text.bitarrayFor+0x40): undefined reference to `__assert_fail'
/usr/bin/ld: /tmp/cczXXTJE.o: in function `cvrun_xlib':
cosmogfx.c:(.text.cvrun_xlib+0x90): undefined reference to `__assert_fail'
/usr/bin/ld: cosmogfx.c:(.text.cvrun_xlib+0xd5): undefined reference to `__assert_fail'                                                                                                                                    
/usr/bin/ld: cosmogfx.c:(.text.cvrun_xlib+0x11a): undefined reference to `__assert_fail'
/usr/bin/ld: /tmp/cczXXTJE.o:cosmogfx.c:(.text.cvrun_xlib+0x15f): more undefined references to `__assert_fail' follow
/usr/bin/ld: /tmp/cczXXTJE.o: in function `delcursor': 
cosmogfx.c:(.text.delcursor+0x1f): undefined reference to `DestroyIcon'
/usr/bin/ld: /tmp/cczXXTJE.o: in function `winsetcursor':
cosmogfx.c:(.text.winsetcursor+0x94): undefined reference to `GetDC'
/usr/bin/ld: cosmogfx.c:(.text.winsetcursor+0xcc): undefined reference to `CreateDIBSection'
/usr/bin/ld: cosmogfx.c:(.text.winsetcursor+0xec): undefined reference to `ReleaseDC'
/usr/bin/ld: cosmogfx.c:(.text.winsetcursor+0x25c): undefined reference to `CreateBitmap'
/usr/bin/ld: cosmogfx.c:(.text.winsetcursor+0x272): undefined reference to `CreateIconIndirect'
/usr/bin/ld: cosmogfx.c:(.text.winsetcursor+0x288): undefined reference to `SetCursor'
/usr/bin/ld: cosmogfx.c:(.text.winsetcursor+0x297): undefined reference to `DeleteObject'
/usr/bin/ld: cosmogfx.c:(.text.winsetcursor+0x2a6): undefined reference to `DeleteObject'
/usr/bin/ld: /tmp/cczXXTJE.o: in function `osEvent_win':
cosmogfx.c:(.text.osEvent_win+0xc5): undefined reference to `LoadCursor'
/usr/bin/ld: cosmogfx.c:(.text.osEvent_win+0xcd): undefined reference to `SetCursor'
/usr/bin/ld: cosmogfx.c:(.text.osEvent_win+0xeb): undefined reference to `SetWindowLong'
/usr/bin/ld: cosmogfx.c:(.text.osEvent_win+0xff): undefined reference to `ShowWindow'
/usr/bin/ld: cosmogfx.c:(.text.osEvent_win+0x131): undefined reference to `SetWindowPos'
/usr/bin/ld: cosmogfx.c:(.text.osEvent_win+0x14b): undefined reference to `ShowWindow'
/usr/bin/ld: cosmogfx.c:(.text.osEvent_win+0x164): undefined reference to `SetWindowLong'
/usr/bin/ld: cosmogfx.c:(.text.osEvent_win+0x196): undefined reference to `SetWindowPos'
/usr/bin/ld: /tmp/cczXXTJE.o: in function `mapkey':
cosmogfx.c:(.text.mapkey+0x3e5): undefined reference to `GetKeyboardLayout'
/usr/bin/ld: cosmogfx.c:(.text.mapkey+0x3f7): undefined reference to `MapVirtualKeyEx'
/usr/bin/ld: /tmp/cczXXTJE.o: in function `onSETCURSOR':
cosmogfx.c:(.text.onSETCURSOR+0x31): undefined reference to `SetCursor'
/usr/bin/ld: /tmp/cczXXTJE.o: in function `onPAINT':
cosmogfx.c:(.text.onPAINT+0x2c): undefined reference to `GetDC'
/usr/bin/ld: cosmogfx.c:(.text.onPAINT+0x4a): undefined reference to `SwapBuffers'
/usr/bin/ld: cosmogfx.c:(.text.onPAINT+0x5d): undefined reference to `ReleaseDC'
/usr/bin/ld: /tmp/cczXXTJE.o: in function `winhandle': 
cosmogfx.c:(.text.winhandle+0x45d): undefined reference to `DefWindowProc'
collect2: error: ld returned 1 exit status

`make MODE= -j8 b/demo.com.dbg` exited with 1:
gcc -DDLOPEN=z_dlopen -DDLSYM=z_dlsym -DZ_SMALL -DSTDLIB=1 -DELFCLASS=ELFCLASS64 -DCV_NO_MAIN -DCV_DYN -include cosmopolitan/o/cosmopolitan.h -I. -Icosmopolitan -Imicroui/demo -Imicroui/src -Ifake -Iglcv/src -ffunction-
sections -fdata-sections -Wl,-gc-sections cosmogfx.c dtrampoline.c gl.c demo.c microui/src/microui.c renderer.c elf_loader.c b/helper.linux.zip.o b/helper.obsd.zip.o b/helper.fbsd.zip.o b/helper.nbsd.zip.o -o b/demo.com
.dbg -no-canonical-prefixes -fdiagnostics-color=always                                                                                                                                                                     
consumed 587,451µs wall time                                                                                                                                                                                               
ballooned to 44,888kb in size                                                                                                                                                                                              
needed 586,314us cpu (10% kernel)                                                                                                                                                                                          
caused 43,222 page faults (100% memcpy)                                                                                                                                                                                    
104 context switch (47% consensual)                                                                                                                                                                                        
performed 0 read and 2,576 write i/o operations  

@jacereda
Copy link
Owner

The first error seems related to jart/cosmopolitan@7064d73

Using your local copy won't work, Nixpkgs is using a very old version and this project needs some recent changes.

I've synced with the latest changes, can you pull again and retry?

@coderofsalvation
Copy link
Author

   573,952⏰   569,196⏳  18,708k       0iop o//third_party/python/pythontester.com -m test.test_codecencodings_iso2022
 1,095,311⏰ 1,074,030⏳  21,192k       0iop o//third_party/python/pythontester.com -m test.test_codecmaps_jp
   946,283⏰   944,000⏳  18,932k       0iop o//third_party/python/pythontester.com -m test.test_codecencodings_jp
 4,477,602⏰  4,472,040⏳  67,956k     472iop o//third_party/python/pythontester.com -m test.test_bz2
installing
rm: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
/bin/sh: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
dircolors: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
uname: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
stty: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
whoami: symbol lookup error: /nix/store/mij848h2x5wiqkwhg027byvmf9x3gx7y-glibc-2.33-50/lib/libc.so.6: undefined symbol: _dl_catch_error_ptr, version GLIBC_PRIVATE
(exit)
$

nix-shell --pure almost seems to finish.

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