From a805d9a7216464522c6ac6bcc91c7b1292e2a241 Mon Sep 17 00:00:00 2001 From: William Roe Date: Fri, 5 Nov 2021 13:37:52 +0000 Subject: [PATCH 1/9] Fix path to static GLFW lib on Windows --- vendor/glfw/bindings/bindings.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/glfw/bindings/bindings.odin b/vendor/glfw/bindings/bindings.odin index 90d5a0f9e..06b5f5b32 100644 --- a/vendor/glfw/bindings/bindings.odin +++ b/vendor/glfw/bindings/bindings.odin @@ -6,7 +6,7 @@ import vk "vendor:vulkan" when ODIN_OS == "linux" { foreign import glfw "system:glfw" } // TODO: Add the billion-or-so static libs to link to in linux when ODIN_OS == "windows" { foreign import glfw { - "lib/glfw3.lib", + "../lib/glfw3_mt.lib", "system:user32.lib", "system:gdi32.lib", "system:shell32.lib", From dd88104a81a7ec9adaf14dc7f21839bbee30cd2d Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Wed, 10 Nov 2021 14:59:54 +0100 Subject: [PATCH 2/9] Fix os.walk for UNC paths. --- core/os/stat_windows.odin | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/os/stat_windows.odin b/core/os/stat_windows.odin index 132cad155..2d9f98fd4 100644 --- a/core/os/stat_windows.odin +++ b/core/os/stat_windows.odin @@ -115,12 +115,16 @@ cleanpath_strip_prefix :: proc(buf: []u16) -> []u16 { } buf = buf[:N] - if len(buf) >= 4 { - if buf[0] == '\\' && - buf[1] == '\\' && - buf[2] == '?' && - buf[3] == '\\' { - buf = buf[4:] + if len(buf) >= 4 && buf[0] == '\\' && buf[1] == '\\' && buf[2] == '?' && buf[3] == '\\' { + buf = buf[4:] + + /* + NOTE(Jeroen): Properly handle UNC paths. + We need to turn `\\?\UNC\synology.local` into `\\synology.local`. + */ + if len(buf) >= 3 && buf[0] == 'U' && buf[1] == 'N' && buf[2] == 'C' { + buf = buf[2:] + buf[0] = '\\' } } return buf From 8aadcacc0b71acb356b03372b35d772829727af5 Mon Sep 17 00:00:00 2001 From: zhibog Date: Wed, 10 Nov 2021 15:22:12 +0100 Subject: [PATCH 3/9] Add tests to Linux and Mac and add vendor tests --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++---- tests/core/Makefile | 7 +++++-- tests/vendor/Makefile | 6 ++++++ 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 tests/vendor/Makefile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c9603db5..bf4b8eff8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Download LLVM - run: sudo apt-get install llvm-11 clang-11 llvm + - name: Download LLVM, botan + run: sudo apt-get install llvm-11 clang-11 llvm libbotan-2-13 libbotan-2-dev botan - name: build odin run: make release - name: Odin version @@ -30,13 +30,18 @@ jobs: cd tests/core make timeout-minutes: 10 + - name: Vendor library tests + run: | + cd tests/vendor + make + timeout-minutes: 10 build_macOS: runs-on: macos-latest steps: - uses: actions/checkout@v1 - - name: Download LLVM and setup PATH + - name: Download LLVM, botan and setup PATH run: | - brew install llvm@11 + brew install llvm@11 botan echo "/usr/local/opt/llvm@11/bin" >> $GITHUB_PATH TMP_PATH=$(xcrun --show-sdk-path)/user/include echo "CPATH=$TMP_PATH" >> $GITHUB_ENV @@ -57,6 +62,16 @@ jobs: - name: Odin run -debug run: ./odin run examples/demo/demo.odin -debug timeout-minutes: 10 + - name: Core library tests + run: | + cd tests/core + make + timeout-minutes: 10 + - name: Vendor library tests + run: | + cd tests/vendor + make + timeout-minutes: 10 build_windows: runs-on: windows-latest steps: @@ -97,6 +112,13 @@ jobs: cd tests\core call build.bat timeout-minutes: 10 + - name: Vendor library tests + shell: cmd + run: | + call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat + cd tests\vendor + call build.bat + timeout-minutes: 10 - name: core:math/big tests shell: cmd run: | diff --git a/tests/core/Makefile b/tests/core/Makefile index 99b1efe87..0f0ffe4d6 100644 --- a/tests/core/Makefile +++ b/tests/core/Makefile @@ -1,7 +1,7 @@ ODIN=../../odin PYTHON=$(shell which python3) -all: download_test_assets image_test compress_test strings_test hash_test +all: download_test_assets image_test compress_test strings_test hash_test crypto_test download_test_assets: $(PYTHON) download_assets.py @@ -16,4 +16,7 @@ strings_test: $(ODIN) run strings/test_core_strings.odin hash_test: - $(ODIN) run hash -out=test_hash -o:speed -no-bounds-check \ No newline at end of file + $(ODIN) run hash -out=test_hash -o:speed -no-bounds-check + +crypto_test: + $(ODIN) run crypto -out=crypto_hash -o:speed -no-bounds-check \ No newline at end of file diff --git a/tests/vendor/Makefile b/tests/vendor/Makefile new file mode 100644 index 000000000..f0a456bae --- /dev/null +++ b/tests/vendor/Makefile @@ -0,0 +1,6 @@ +ODIN=../../odin + +all: botan_test + +botan_test: + $(ODIN) run botan -out=botan_hash -o:speed -no-bounds-check \ No newline at end of file From 359e02bad7ed477deea8228c3a6fc1d7f411d405 Mon Sep 17 00:00:00 2001 From: zhibog Date: Wed, 10 Nov 2021 15:26:26 +0100 Subject: [PATCH 4/9] Fix botan lib name for apt --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf4b8eff8..33d92953c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Download LLVM, botan - run: sudo apt-get install llvm-11 clang-11 llvm libbotan-2-13 libbotan-2-dev botan + run: sudo apt-get install llvm-11 clang-11 llvm libbotan botan - name: build odin run: make release - name: Odin version From 96b670af49a9571991a242530dfd1bcce64b5d4f Mon Sep 17 00:00:00 2001 From: zhibog Date: Wed, 10 Nov 2021 15:31:29 +0100 Subject: [PATCH 5/9] Fix package name again --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33d92953c..6742b56f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: Download LLVM, botan - run: sudo apt-get install llvm-11 clang-11 llvm libbotan botan + run: sudo apt-get install llvm-11 clang-11 llvm libbotan-2-dev botan - name: build odin run: make release - name: Odin version From d8b15231616cd6aa475b3d899999ad267f213ac7 Mon Sep 17 00:00:00 2001 From: Carwyn Nelson Date: Wed, 10 Nov 2021 15:15:40 +0000 Subject: [PATCH 6/9] Fix the windows binding for getaddrinfo getaddrinfo should take a double pointer to ADDRINFOA instead of a single pointer. If you call the binding in its current state you will not get back a valid ADDRINFOA struct. I have also changed the `node` and `service` params to be cstring to avoid having to do `transmute(u8) value`. --- core/sys/windows/ws2_32.odin | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/sys/windows/ws2_32.odin b/core/sys/windows/ws2_32.odin index 6be55216e..cd467e142 100644 --- a/core/sys/windows/ws2_32.odin +++ b/core/sys/windows/ws2_32.odin @@ -76,10 +76,10 @@ foreign ws2_32 { listen :: proc(socket: SOCKET, backlog: c_int) -> c_int --- connect :: proc(socket: SOCKET, address: ^SOCKADDR, len: c_int) -> c_int --- getaddrinfo :: proc( - node: ^c_char, - service: ^c_char, + node: cstring, + service: cstring, hints: ^ADDRINFOA, - res: ^ADDRINFOA, + res: ^^ADDRINFOA, ) -> c_int --- freeaddrinfo :: proc(res: ^ADDRINFOA) --- select :: proc( From c67c0789ebd02d40ff5728a1d9d70cef04c6ad43 Mon Sep 17 00:00:00 2001 From: Carwyn Nelson Date: Wed, 10 Nov 2021 15:55:50 +0000 Subject: [PATCH 7/9] Add socket() function to windows ws32 bindings It looks like this was missing from the winsock bindings. Odin contains WSASocketW which I assume would also work for obtaining a socket, but socket() is distinct and is what I was using, so I assume others will want it too. --- core/sys/windows/ws2_32.odin | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/sys/windows/ws2_32.odin b/core/sys/windows/ws2_32.odin index cd467e142..0cff5c2da 100644 --- a/core/sys/windows/ws2_32.odin +++ b/core/sys/windows/ws2_32.odin @@ -39,6 +39,11 @@ foreign ws2_32 { g: GROUP, dwFlags: DWORD, ) -> SOCKET --- + socket :: proc( + af: c_int, + type: c_int, + protocol: c_int, + ) -> SOCKET --- ioctlsocket :: proc(s: SOCKET, cmd: c_long, argp: ^c_ulong) -> c_int --- closesocket :: proc(socket: SOCKET) -> c_int --- From c213274607bca0b2d2d069d551470610ec136a50 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Wed, 10 Nov 2021 19:15:10 +0100 Subject: [PATCH 8/9] [vendor:glfw] Add test. --- tests/vendor/build.bat | 7 +++- tests/vendor/glfw/test_vendor_glfw.odin | 45 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/vendor/glfw/test_vendor_glfw.odin diff --git a/tests/vendor/build.bat b/tests/vendor/build.bat index 655883a5e..e70d9f1d5 100644 --- a/tests/vendor/build.bat +++ b/tests/vendor/build.bat @@ -5,4 +5,9 @@ set PATH_TO_ODIN==..\..\odin echo --- echo Running vendor:botan tests echo --- -%PATH_TO_ODIN% run botan %COMMON% \ No newline at end of file +%PATH_TO_ODIN% run botan %COMMON% + +echo --- +echo Running vendor:glfw tests +echo --- +%PATH_TO_ODIN% run glfw %COMMON% \ No newline at end of file diff --git a/tests/vendor/glfw/test_vendor_glfw.odin b/tests/vendor/glfw/test_vendor_glfw.odin new file mode 100644 index 000000000..252df2033 --- /dev/null +++ b/tests/vendor/glfw/test_vendor_glfw.odin @@ -0,0 +1,45 @@ +package test_vendor_glfw + +import "core:testing" +import "core:fmt" +import "vendor:glfw" + +GLFW_MAJOR :: 3 +GLFW_MINOR :: 3 +GLFW_PATCH :: 4 + +TEST_count := 0 +TEST_fail := 0 + +when ODIN_TEST { + expect :: testing.expect + log :: testing.log +} else { + expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) { + fmt.printf("[%v] ", loc) + TEST_count += 1 + if !condition { + TEST_fail += 1 + fmt.println(message) + return + } + fmt.println(" PASS") + } + log :: proc(t: ^testing.T, v: any, loc := #caller_location) { + fmt.printf("[%v] ", loc) + fmt.printf("log: %v\n", v) + } +} + +main :: proc() { + t := testing.T{} + test_glfw(&t) + + fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count) +} + +@(test) +test_glfw :: proc(t: ^testing.T) { + major, minor, patch := glfw.GetVersion() + expect(t, major == GLFW_MAJOR && minor == GLFW_MINOR, fmt.tprintf("Expected GLFW.GetVersion: %v.%v.%v, got %v.%v.%v instead", GLFW_MAJOR, GLFW_MINOR, GLFW_PATCH, major, minor, patch)) +} \ No newline at end of file From c430a827216b7c79e5df70ed20a1acd98abc92f2 Mon Sep 17 00:00:00 2001 From: Yawning Angel Date: Sat, 13 Nov 2021 09:41:59 +0000 Subject: [PATCH 9/9] src: Fix the syscall intrinsic code generation for Linux and Windows The old assembly generated for the syscall intrinsic did not specify clobber constraints. This adds RCX and R11 (that are clobbered by the instruction itself), and memory (that is clobbered by some system calls) to the assembly constraints. Note: This is still incorrect on FreeBSD, which clobbers more registers and uses the carry flag instead of -errno in rax to indicate an error. --- src/llvm_backend_proc.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index 2b094cfae..8b8559cae 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -2002,7 +2002,22 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, constraints = gb_string_appendc(constraints, regs[i]); constraints = gb_string_appendc(constraints, "}"); } - + + // The SYSCALL instruction stores the address of the + // following instruction into RCX, and RFLAGS in R11. + // + // RSP is not saved, but at least on Linux it appears + // that the kernel system-call handler does the right + // thing. + // + // Some but not all system calls will additionally + // clobber memory. + // + // TODO: FreeBSD is different and will also clobber + // R8, R9, and R10. Additionally CF is used to + // indicate an error instead of -errno. + constraints = gb_string_appendc(constraints, ",~{rcx},~{r11},~{memory}"); + inline_asm = llvm_get_inline_asm(func_type, make_string_c(asm_string), make_string_c(constraints)); } break;