From b5a619e9758e53f774b022f779649df84d561c89 Mon Sep 17 00:00:00 2001 From: F0x1fy Date: Thu, 5 Nov 2020 22:14:56 -0700 Subject: [PATCH 01/11] Moved internal_windows to internal_any to allow for manual linking related to issue odin-lang/Odin#527. --- core/runtime/{internal_windows.odin => internal_any.odin} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core/runtime/{internal_windows.odin => internal_any.odin} (100%) diff --git a/core/runtime/internal_windows.odin b/core/runtime/internal_any.odin similarity index 100% rename from core/runtime/internal_windows.odin rename to core/runtime/internal_any.odin From 94277fe41c60e32b8aa9ed5931dbfbbb8e6a4d82 Mon Sep 17 00:00:00 2001 From: F0x1fy Date: Fri, 6 Nov 2020 11:11:26 -0700 Subject: [PATCH 02/11] As per GingerBill's request, copied the files over to a linux-specific file instead of renaming to . --- ...{internal_any.odin => internal_linux.odin} | 0 core/runtime/internal_windows.odin | 135 ++++++++++++++++++ 2 files changed, 135 insertions(+) rename core/runtime/{internal_any.odin => internal_linux.odin} (100%) create mode 100644 core/runtime/internal_windows.odin diff --git a/core/runtime/internal_any.odin b/core/runtime/internal_linux.odin similarity index 100% rename from core/runtime/internal_any.odin rename to core/runtime/internal_linux.odin diff --git a/core/runtime/internal_windows.odin b/core/runtime/internal_windows.odin new file mode 100644 index 000000000..10d2e2249 --- /dev/null +++ b/core/runtime/internal_windows.odin @@ -0,0 +1,135 @@ +package runtime + +@(link_name="__umodti3") +umodti3 :: proc "c" (a, b: u128) -> u128 { + r: u128 = ---; + _ = udivmod128(a, b, &r); + return r; +} + + +@(link_name="__udivmodti4") +udivmodti4 :: proc "c" (a, b: u128, rem: ^u128) -> u128 { + return udivmod128(a, b, rem); +} + +@(link_name="__udivti3") +udivti3 :: proc "c" (a, b: u128) -> u128 { + return udivmodti4(a, b, nil); +} + + +@(link_name="__modti3") +modti3 :: proc "c" (a, b: i128) -> i128 { + s_a := a >> (128 - 1); + s_b := b >> (128 - 1); + an := (a ~ s_a) - s_a; + bn := (b ~ s_b) - s_b; + + r: u128 = ---; + _ = udivmod128(transmute(u128)an, transmute(u128)bn, &r); + return (transmute(i128)r ~ s_a) - s_a; +} + + +@(link_name="__divmodti4") +divmodti4 :: proc "c" (a, b: i128, rem: ^i128) -> i128 { + u := udivmod128(transmute(u128)a, transmute(u128)b, cast(^u128)rem); + return transmute(i128)u; +} + +@(link_name="__divti3") +divti3 :: proc "c" (a, b: i128) -> i128 { + u := udivmodti4(transmute(u128)a, transmute(u128)b, nil); + return transmute(i128)u; +} + + +@(link_name="__fixdfti") +fixdfti :: proc(a: u64) -> i128 { + significandBits :: 52; + typeWidth :: (size_of(u64)*8); + exponentBits :: (typeWidth - significandBits - 1); + maxExponent :: ((1 << exponentBits) - 1); + exponentBias :: (maxExponent >> 1); + + implicitBit :: (u64(1) << significandBits); + significandMask :: (implicitBit - 1); + signBit :: (u64(1) << (significandBits + exponentBits)); + absMask :: (signBit - 1); + exponentMask :: (absMask ~ significandMask); + + // Break a into sign, exponent, significand + aRep := a; + aAbs := aRep & absMask; + sign := i128(-1 if aRep & signBit != 0 else 1); + exponent := u64((aAbs >> significandBits) - exponentBias); + significand := u64((aAbs & significandMask) | implicitBit); + + // If exponent is negative, the result is zero. + if exponent < 0 { + return 0; + } + + // If the value is too large for the integer type, saturate. + if exponent >= size_of(i128) * 8 { + return max(i128) if sign == 1 else min(i128); + } + + // If 0 <= exponent < significandBits, right shift to get the result. + // Otherwise, shift left. + if exponent < significandBits { + return sign * i128(significand >> (significandBits - exponent)); + } else { + return sign * (i128(significand) << (exponent - significandBits)); + } + +} + +@(default_calling_convention = "none") +foreign { + @(link_name="llvm.ctlz.i128") _clz_i128 :: proc(x: i128, is_zero_undef := false) -> i128 --- +} + + +@(link_name="__floattidf") +floattidf :: proc(a: i128) -> f64 { + DBL_MANT_DIG :: 53; + if a == 0 { + return 0.0; + } + a := a; + N :: size_of(i128) * 8; + s := a >> (N-1); + a = (a ~ s) - s; + sd: = N - _clz_i128(a); // number of significant digits + e := u32(sd - 1); // exponent + if sd > DBL_MANT_DIG { + switch sd { + case DBL_MANT_DIG + 1: + a <<= 1; + case DBL_MANT_DIG + 2: + // okay + case: + a = i128(u128(a) >> u128(sd - (DBL_MANT_DIG+2))) | + i128(u128(a) & (~u128(0) >> u128(N + DBL_MANT_DIG+2 - sd)) != 0); + }; + + a |= i128((a & 4) != 0); + a += 1; + a >>= 2; + + if a & (1 << DBL_MANT_DIG) != 0 { + a >>= 1; + e += 1; + } + } else { + a <<= u128(DBL_MANT_DIG - sd); + } + fb: [2]u32; + fb[1] = (u32(s) & 0x80000000) | // sign + ((e + 1023) << 20) | // exponent + ((u32(a) >> 32) & 0x000FFFFF); // mantissa-high + fb[1] = u32(a); // mantissa-low + return transmute(f64)fb; +} From 39044b5bb52025b1cff4b21f922e6ef3e744ea1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20M=2E=20Monacci?= Date: Fri, 6 Nov 2020 15:46:32 -0300 Subject: [PATCH 03/11] Fix small typo Fix small typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ab92d6e46..23a969271 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ main :: proc() { #### [Getting Started](https://odin-lang.org/docs/install) -Instructions for downloading and install the Odin compiler and libraries. +Instructions for downloading and installing the Odin compiler and libraries. ### Learning Odin From 140bb3ebfcfa7579e53e836c3fb75792efbed078 Mon Sep 17 00:00:00 2001 From: Tetralux Date: Fri, 6 Nov 2020 05:43:13 +0000 Subject: [PATCH 04/11] Fix -build-mode:shared type table on Unix Fixes #527. Previously on Linux, '__$startup_runtime', the procedure that initializes the type table for runtime typeids, was NOT called when a shared library was loaded by the dynamic loader. This caused the library to not have its type table populated, which caused an assert to fail if you tried to use runtime typeids - like core:fmt, for example. This commit fixes this by calling ld instead of clang, when building a shared library, so that we can pass "-init '__$startup_runtime'" to it, when building a shared library. Try as I might, I could not get clang to correctly pass through the linker flags that I wanted. --- src/main.cpp | 82 ++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a7b951b67..1ae0e7d97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -342,9 +342,9 @@ i32 linker_stage(lbGenerator *gen) { lib_name = remove_extension_from_path(lib_name); lib_str = gb_string_append_fmt(lib_str, " -framework %.*s ", LIT(lib_name)); } else if (string_ends_with(lib, str_lit(".a")) || string_ends_with(lib, str_lit(".o")) || string_ends_with(lib, str_lit(".dylib"))) { - // For: - // object - // dynamic lib + // For: + // object + // dynamic lib // static libs, absolute full path relative to the file in which the lib was imported from lib_str = gb_string_append_fmt(lib_str, " %.*s ", LIT(lib)); } else { @@ -382,20 +382,33 @@ i32 linker_stage(lbGenerator *gen) { // Unlike the Win32 linker code, the output_ext includes the dot, because // typically executable files on *NIX systems don't have extensions. String output_ext = {}; - char const *link_settings = ""; + gbString link_settings = gb_string_make_reserve(heap_allocator(), 32); char const *linker; if (build_context.build_mode == BuildMode_DynamicLibrary) { + // NOTE(tetra, 2020-11-06): __$startup_runtime must be called at DLL load time. + // Clang, for some reason, won't let us pass the '-init' flag that lets us do this, + // so use ld instead. + // :UseLDForShared + linker = "ld"; + link_settings = gb_string_appendc(link_settings, "-init '__$startup_runtime' "); // Shared libraries are .dylib on MacOS and .so on Linux. #if defined(GB_SYSTEM_OSX) output_ext = STR_LIT(".dylib"); - link_settings = "-dylib -dynamic"; + link_settings = gb_string_appendc(link_settings, "-dylib -dynamic "); #else output_ext = STR_LIT(".so"); - link_settings = "-shared"; + link_settings = gb_string_appendc(link_settings, "-shared "); #endif } else { - // TODO: Do I need anything here? - link_settings = ""; + #if defined(GB_SYSTEM_OSX) + linker = "ld"; + #else + // TODO(zangent): Figure out how to make ld work on Linux. + // It probably has to do with including the entire CRT, but + // that's quite a complicated issue to solve while remaining distro-agnostic. + // Clang can figure out linker flags for us, and that's good enough _for now_. + linker = "clang -Wno-unused-command-line-argument"; + #endif } if (build_context.out_filepath.len > 0) { @@ -406,16 +419,6 @@ i32 linker_stage(lbGenerator *gen) { } } - #if defined(GB_SYSTEM_OSX) - linker = "ld"; - #else - // TODO(zangent): Figure out how to make ld work on Linux. - // It probably has to do with including the entire CRT, but - // that's quite a complicated issue to solve while remaining distro-agnostic. - // Clang can figure out linker flags for us, and that's good enough _for now_. - linker = "clang -Wno-unused-command-line-argument"; - #endif - exit_code = system_exec_command_line_app("ld-link", "%s %s -o \"%.*s%.*s\" %s " " %s " @@ -443,7 +446,7 @@ i32 linker_stage(lbGenerator *gen) { if (exit_code != 0) { return exit_code; } - + #if defined(GB_SYSTEM_OSX) if (build_context.ODIN_DEBUG) { // NOTE: macOS links DWARF symbols dynamically. Dsymutil will map the stubs in the exe @@ -2136,11 +2139,11 @@ int main(int arg_count, char const **arg_ptr) { String lib_name = lib; lib_name = remove_extension_from_path(lib_name); lib_str = gb_string_append_fmt(lib_str, " -framework %.*s ", LIT(lib_name)); - + } else if (string_ends_with(lib, str_lit(".a")) || string_ends_with(lib, str_lit(".o")) || string_ends_with(lib, str_lit(".dylib"))) { - // For: - // object - // dynamic lib + // For: + // object + // dynamic lib // static libs, absolute full path relative to the file in which the lib was imported from lib_str = gb_string_append_fmt(lib_str, " %.*s ", LIT(lib)); } else { @@ -2171,22 +2174,36 @@ int main(int arg_count, char const **arg_ptr) { // Unlike the Win32 linker code, the output_ext includes the dot, because // typically executable files on *NIX systems don't have extensions. String output_ext = {}; - char const *link_settings = ""; + gbString link_settings = gb_string_make_reserve(heap_allocator(), 32); char const *linker; if (build_context.build_mode == BuildMode_DynamicLibrary) { + // NOTE(tetra, 2020-11-06): __$startup_runtime must be called at DLL load time. + // Clang, for some reason, won't let us pass the '-init' flag that lets us do this, + // so use ld instead. + // :UseLDForShared + linker = "ld"; + link_settings = gb_string_appendc(link_settings, "-init '__$startup_runtime' "); // Shared libraries are .dylib on MacOS and .so on Linux. #if defined(GB_SYSTEM_OSX) output_ext = STR_LIT(".dylib"); - link_settings = "-dylib -dynamic"; + link_settings = gb_string_appendc(link_settings, "-dylib -dynamic "); #else output_ext = STR_LIT(".so"); - link_settings = "-shared"; + link_settings = gb_string_appendc(link_settings, "-shared "); #endif } else { - // TODO: Do I need anything here? - link_settings = ""; + #if defined(GB_SYSTEM_OSX) + linker = "ld"; + #else + // TODO(zangent): Figure out how to make ld work on Linux. + // It probably has to do with including the entire CRT, but + // that's quite a complicated issue to solve while remaining distro-agnostic. + // Clang can figure out linker flags for us, and that's good enough _for now_. + linker = "clang -Wno-unused-command-line-argument"; + #endif } + if (build_context.out_filepath.len > 0) { //NOTE(thebirk): We have a custom -out arguments, so we should use the extension from that isize pos = string_extension_position(build_context.out_filepath); @@ -2195,15 +2212,6 @@ int main(int arg_count, char const **arg_ptr) { } } - #if defined(GB_SYSTEM_OSX) - linker = "ld"; - #else - // TODO(zangent): Figure out how to make ld work on Linux. - // It probably has to do with including the entire CRT, but - // that's quite a complicated issue to solve while remaining distro-agnostic. - // Clang can figure out linker flags for us, and that's good enough _for now_. - linker = "clang -Wno-unused-command-line-argument"; - #endif exit_code = system_exec_command_line_app("ld-link", "%s \"%.*s.o\" -o \"%.*s%.*s\" %s " From 06b2a9a3e7de285ddb7a4add020c8d08c7afa873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20Hjortsh=C3=B8j?= Date: Sun, 8 Nov 2020 00:01:31 +0100 Subject: [PATCH 05/11] [CI] Try setting python 3.x in nightly upload step --- .github/workflows/nightly.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index d43e96b12..d4365d5af 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -96,6 +96,9 @@ jobs: needs: [build_windows, build_macos, build_ubuntu] steps: - uses: actions/checkout@v1 + - uses: actions/setup-python@v2 + with: + python-version: '3.x' - name: Install B2 CLI shell: bash From a77976533cd60f773030d898907b56896959bf72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20Hjortsh=C3=B8j?= Date: Sun, 8 Nov 2020 00:08:11 +0100 Subject: [PATCH 06/11] [CI] Add manual trigger to nightly --- .github/workflows/nightly.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index d4365d5af..4af568604 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,6 +1,7 @@ name: Nightly on: + workflow_dispatch: schedule: - cron: 0 20 * * * From a239fcfa3afbf6faf45a2a23b7f02e4ebd487b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20Hjortsh=C3=B8j?= Date: Sun, 8 Nov 2020 00:21:28 +0100 Subject: [PATCH 07/11] Update nightly.yml --- .github/workflows/nightly.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 4af568604..9d7b3b49b 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -103,7 +103,12 @@ jobs: - name: Install B2 CLI shell: bash - run: sudo pip install --upgrade b2 + run: | + python -m pip install --upgrade pip + sudo pip install --upgrade b2 + + - name: Display Python version + run: python -c "import sys; print(sys.version)" - name: Download Windows artifacts uses: actions/download-artifact@v1 From ef27528ace7e3a23d7a45be761fa1cb0d2af1a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20Hjortsh=C3=B8j?= Date: Sun, 8 Nov 2020 00:31:25 +0100 Subject: [PATCH 08/11] [CI] Non-sudo install of b2? --- .github/workflows/nightly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 9d7b3b49b..1648169e1 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -105,7 +105,7 @@ jobs: shell: bash run: | python -m pip install --upgrade pip - sudo pip install --upgrade b2 + pip install --upgrade b2 - name: Display Python version run: python -c "import sys; print(sys.version)" From 817db70bde5ff355d7f02ca5cc6ae1bfd14d9cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20Hjortsh=C3=B8j?= Date: Sun, 8 Nov 2020 01:23:19 +0100 Subject: [PATCH 09/11] [CI] Remove -march for makefile nightly --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 34e56c950..0be242aeb 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ release: $(CC) src/main.cpp $(DISABLED_WARNINGS) $(CFLAGS) -O3 -march=native $(LDFLAGS) -o odin nightly: - $(CC) src/main.cpp $(DISABLED_WARNINGS) $(CFLAGS) -DNIGHTLY -O3 -march=native $(LDFLAGS) -o odin + $(CC) src/main.cpp $(DISABLED_WARNINGS) $(CFLAGS) -DNIGHTLY -O3 $(LDFLAGS) -o odin From 19e2f7b7bfd7532fb35456c13361f406d99a4275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20Hjortsh=C3=B8j?= Date: Sun, 8 Nov 2020 01:46:28 +0100 Subject: [PATCH 10/11] [CI] testing webhook --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 219dcebfd..0513f6659 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,8 @@ jobs: build_linux: runs-on: ubuntu-latest steps: + - name: TESTING + run: exit 1 - uses: actions/checkout@v1 - name: Download LLVM run: sudo apt-get install llvm From 11a4dc8ee3a3f88ae37f444e98442882f8e4e2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikkel=20Hjortsh=C3=B8j?= Date: Sun, 8 Nov 2020 01:47:09 +0100 Subject: [PATCH 11/11] [CI] Done testing webhook --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0513f6659..219dcebfd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,8 +5,6 @@ jobs: build_linux: runs-on: ubuntu-latest steps: - - name: TESTING - run: exit 1 - uses: actions/checkout@v1 - name: Download LLVM run: sudo apt-get install llvm