lol

Merge #263847: nodejs_18: fix build with clang 16

...into staging-next

+13 -129
-126
pkgs/development/web/nodejs/enum-width-fix-backport.patch
··· 1 - See https://github.com/v8/v8/commit/d15d49b09dc7aef9edcc4cf6a0cb2b77a0db203f. 2 - 3 - v8 doesn’t compile with clang 16 due to an error regarding integer values being outside the enum 4 - range. This is fixed in v8 upstream. This patch is a backport of the fix. 5 - 6 - Note that this patch is only needed for node.js v18. It is not needed for node v20. 7 - 8 - 9 - diff --git a/include/v8-internal.h b/include/v8-internal.h 10 - index a27f3a34480..5fb0f2ac16d 100644 11 - --- a/deps/v8/include/v8-internal.h 12 - +++ b/deps/v8/include/v8-internal.h 13 - @@ -574,7 +574,7 @@ class Internals { 14 - 15 - static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize; 16 - static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3; 17 - - static const int kNodeStateMask = 0x7; 18 - + static const int kNodeStateMask = 0x3; 19 - static const int kNodeStateIsWeakValue = 2; 20 - 21 - static const int kFirstNonstringType = 0x80; 22 - diff --git a/src/ast/ast.h b/src/ast/ast.h 23 - index 32438f9b249..8473f7fb67e 100644 24 - --- a/deps/v8/src/ast/ast.h 25 - +++ b/deps/v8/src/ast/ast.h 26 - @@ -1006,7 +1006,7 @@ class Literal final : public Expression { 27 - friend class AstNodeFactory; 28 - friend Zone; 29 - 30 - - using TypeField = Expression::NextBitField<Type, 4>; 31 - + using TypeField = Expression::NextBitField<Type, 3>; 32 - 33 - Literal(int smi, int position) : Expression(position, kLiteral), smi_(smi) { 34 - bit_field_ = TypeField::update(bit_field_, kSmi); 35 - diff --git a/src/base/bit-field.h b/src/base/bit-field.h 36 - index 9a66468d4e0..ccfc23a065d 100644 37 - --- a/deps/v8/src/base/bit-field.h 38 - +++ b/deps/v8/src/base/bit-field.h 39 - @@ -40,6 +40,11 @@ class BitField final { 40 - static constexpr U kNumValues = U{1} << kSize; 41 - 42 - // Value for the field with all bits set. 43 - + // If clang complains 44 - + // "constexpr variable 'kMax' must be initialized by a constant expression" 45 - + // on this line, then you're creating a BitField for an enum with more bits 46 - + // than needed for the enum values. Either reduce the BitField size, 47 - + // or give the enum an explicit underlying type. 48 - static constexpr T kMax = static_cast<T>(kNumValues - 1); 49 - 50 - template <class T2, int size2> 51 - diff --git a/src/compiler/backend/instruction-codes.h b/src/compiler/backend/instruction-codes.h 52 - index 1add351b422..2fe2cd1a74f 100644 53 - --- a/deps/v8/src/compiler/backend/instruction-codes.h 54 - +++ b/deps/v8/src/compiler/backend/instruction-codes.h 55 - @@ -198,7 +198,7 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, 56 - V(None) \ 57 - TARGET_ADDRESSING_MODE_LIST(V) 58 - 59 - -enum AddressingMode { 60 - +enum AddressingMode : uint8_t { 61 - #define DECLARE_ADDRESSING_MODE(Name) kMode_##Name, 62 - ADDRESSING_MODE_LIST(DECLARE_ADDRESSING_MODE) 63 - #undef DECLARE_ADDRESSING_MODE 64 - @@ -309,7 +309,7 @@ using MiscField = base::BitField<int, 22, 10>; 65 - // LaneSizeField and AccessModeField are helper types to encode/decode a lane 66 - // size, an access mode, or both inside the overlapping MiscField. 67 - using LaneSizeField = base::BitField<int, 22, 8>; 68 - -using AccessModeField = base::BitField<MemoryAccessMode, 30, 2>; 69 - +using AccessModeField = base::BitField<MemoryAccessMode, 30, 1>; 70 - // TODO(turbofan): {HasMemoryAccessMode} is currently only used to guard 71 - // decoding (in CodeGenerator and InstructionScheduler). Encoding (in 72 - // InstructionSelector) is not yet guarded. There are in fact instructions for 73 - diff --git a/src/compiler/backend/instruction.h b/src/compiler/backend/instruction.h 74 - index bed43dc6363..64b9063bcf8 100644 75 - --- a/deps/v8/src/compiler/backend/instruction.h 76 - +++ b/deps/v8/src/compiler/backend/instruction.h 77 - @@ -591,8 +591,8 @@ class LocationOperand : public InstructionOperand { 78 - } 79 - 80 - STATIC_ASSERT(KindField::kSize == 3); 81 - - using LocationKindField = base::BitField64<LocationKind, 3, 2>; 82 - - using RepresentationField = base::BitField64<MachineRepresentation, 5, 8>; 83 - + using LocationKindField = base::BitField64<LocationKind, 3, 1>; 84 - + using RepresentationField = LocationKindField::Next<MachineRepresentation, 8>; 85 - using IndexField = base::BitField64<int32_t, 35, 29>; 86 - }; 87 - 88 - diff --git a/src/handles/global-handles.cc b/src/handles/global-handles.cc 89 - index 536059f3115..ae9e70b3a85 100644 90 - --- a/deps/v8/src/handles/global-handles.cc 91 - +++ b/deps/v8/src/handles/global-handles.cc 92 - @@ -652,7 +652,7 @@ class GlobalHandles::Node final : public NodeBase<GlobalHandles::Node> { 93 - 94 - // This stores three flags (independent, partially_dependent and 95 - // in_young_list) and a State. 96 - - using NodeState = base::BitField8<State, 0, 3>; 97 - + using NodeState = base::BitField8<State, 0, 2>; 98 - using IsInYoungList = NodeState::Next<bool, 1>; 99 - using NodeWeaknessType = IsInYoungList::Next<WeaknessType, 2>; 100 - 101 - diff --git a/src/maglev/maglev-ir.h b/src/maglev/maglev-ir.h 102 - index 95aadfb5e14..f07f9fecf8c 100644 103 - --- a/deps/v8/src/maglev/maglev-ir.h 104 - +++ b/deps/v8/src/maglev/maglev-ir.h 105 - @@ -315,7 +315,7 @@ class OpProperties { 106 - return kNeedsRegisterSnapshotBit::decode(bitfield_); 107 - } 108 - constexpr bool is_pure() const { 109 - - return (bitfield_ | kPureMask) == kPureValue; 110 - + return (bitfield_ & kPureMask) == kPureValue; 111 - } 112 - constexpr bool is_required_when_unused() const { 113 - return can_write() || non_memory_side_effects(); 114 - diff --git a/src/wasm/wasm-code-manager.h b/src/wasm/wasm-code-manager.h 115 - index f8329424777..81c7cce62e8 100644 116 - --- a/deps/v8/src/wasm/wasm-code-manager.h 117 - +++ b/deps/v8/src/wasm/wasm-code-manager.h 118 - @@ -487,7 +487,7 @@ class V8_EXPORT_PRIVATE WasmCode final { 119 - int trap_handler_index_ = -1; 120 - 121 - // Bits encoded in {flags_}: 122 - - using KindField = base::BitField8<Kind, 0, 3>; 123 - + using KindField = base::BitField8<Kind, 0, 2>; 124 - using ExecutionTierField = KindField::Next<ExecutionTier, 2>; 125 - using ForDebuggingField = ExecutionTierField::Next<ForDebugging, 2>; 126 -
+13 -3
pkgs/development/web/nodejs/v18.nix
··· 1 - { callPackage, fetchpatch, openssl, python3, enableNpm ? true }: 1 + { callPackage, lib, overrideCC, pkgs, buildPackages, fetchpatch, openssl, python3, enableNpm ? true }: 2 2 3 3 let 4 + # Clang 16+ cannot build Node v18 due to -Wenum-constexpr-conversion errors. 5 + # Use an older version of clang with the current libc++ for compatibility (e.g., with icu). 6 + ensureCompatibleCC = packages: 7 + if packages.stdenv.cc.isClang && lib.versionAtLeast (lib.getVersion packages.stdenv.cc.cc) "16" 8 + then overrideCC packages.llvmPackages_15.stdenv (packages.llvmPackages_15.stdenv.cc.override { 9 + inherit (packages.llvmPackages) libcxx; 10 + extraPackages = [ packages.llvmPackages.libcxxabi ]; 11 + }) 12 + else packages.stdenv; 13 + 4 14 buildNodejs = callPackage ./nodejs.nix { 5 15 inherit openssl; 16 + stdenv = ensureCompatibleCC pkgs; 17 + buildPackages = buildPackages // { stdenv = ensureCompatibleCC buildPackages; }; 6 18 python = python3; 7 19 }; 8 20 in ··· 16 28 ./revert-arm64-pointer-auth.patch 17 29 ./node-npm-build-npm-package-logic.patch 18 30 ./trap-handler-backport.patch 19 - # Fix for enum width error when compiling with clang 16. 20 - ./enum-width-fix-backport.patch 21 31 ]; 22 32 }