Skip to content

Commit

Permalink
Apply patch. rdar://126195542
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohsin Qureshi committed Apr 17, 2024
1 parent 66b2665 commit 92b8d40
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 62 deletions.
22 changes: 1 addition & 21 deletions Source/JavaScriptCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,30 +152,9 @@ set(JavaScriptCore_OBJECT_LUT_SOURCES
)

list(APPEND JavaScriptCore_SOURCES
runtime/CachedTypes.cpp
${JavaScriptCore_DERIVED_SOURCES_DIR}/JSCBytecodeCacheVersion.cpp
${JavaScriptCore_DERIVED_SOURCES_DIR}/JSCBuiltins.cpp
)

find_program(TOUCH_EXECUTABLE touch)
if (TOUCH_EXECUTABLE)
add_custom_command(
OUTPUT ${JavaScriptCore_DERIVED_SOURCES_DIR}/JSCBytecodeCacheVersion.cpp
MAIN_DEPENDENCY ${JAVASCRIPTCORE_DIR}/runtime/JSCBytecodeCacheVersion.cpp.in
COMMAND ${PERL_EXECUTABLE} -pe s/CACHED_TYPES_CKSUM/__TIMESTAMP__/ ${JAVASCRIPTCORE_DIR}/runtime/JSCBytecodeCacheVersion.cpp.in > ${JavaScriptCore_DERIVED_SOURCES_DIR}/JSCBytecodeCacheVersion.cpp
COMMAND ${TOUCH_EXECUTABLE} -r ${JAVASCRIPTCORE_DIR}/runtime/JSCBytecodeCacheVersion.cpp.in ${JavaScriptCore_DERIVED_SOURCES_DIR}/JSCBytecodeCacheVersion.cpp
VERBATIM
)
else ()
message(WARNING "Unable to find touch executable; ${JavaScriptCore_DERIVED_SOURCES_DIR}/JSCBytecodeCacheVersion.cpp is built non-reproducibly from ${JAVASCRIPTCORE_DIR}/runtime/JSCBytecodeCacheVersion.cpp.in")
add_custom_command(
OUTPUT ${JavaScriptCore_DERIVED_SOURCES_DIR}/JSCBytecodeCacheVersion.cpp
MAIN_DEPENDENCY ${JAVASCRIPTCORE_DIR}/runtime/JSCBytecodeCacheVersion.cpp.in
COMMAND ${PERL_EXECUTABLE} -pe s/CACHED_TYPES_CKSUM/__TIMESTAMP__/ ${JAVASCRIPTCORE_DIR}/runtime/JSCBytecodeCacheVersion.cpp.in > ${JavaScriptCore_DERIVED_SOURCES_DIR}/JSCBytecodeCacheVersion.cpp
VERBATIM
)
endif ()

set(JavaScriptCore_FRAMEWORKS
WTF
)
Expand Down Expand Up @@ -1107,6 +1086,7 @@ set(JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
runtime/JSArrayIterator.h
runtime/JSBigInt.h
runtime/JSBoundFunction.h
runtime/JSCBytecodeCacheVersion.h
runtime/JSCConfig.h
runtime/JSCInlines.h
runtime/JSCJSValue.h
Expand Down
32 changes: 6 additions & 26 deletions Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1863,9 +1863,6 @@
DCF3D56D1CD29476003D5C65 /* LazyPropertyInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = DCF3D5681CD29468003D5C65 /* LazyPropertyInlines.h */; };
DCFDFBD91D1F5D9B00FE3D72 /* B3BottomProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = DCFDFBD71D1F5D9800FE3D72 /* B3BottomProvider.h */; };
DCFDFBDA1D1F5D9E00FE3D72 /* B3TypeMap.h in Headers */ = {isa = PBXBuildFile; fileRef = DCFDFBD81D1F5D9800FE3D72 /* B3TypeMap.h */; };
DD284672291A217E0009A61D /* CachedTypes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DAFA4521E3B871004B68F7 /* CachedTypes.cpp */; };
DD284679291A29900009A61D /* JSCBytecodeCacheVersion.cpp.in in Sources */ = {isa = PBXBuildFile; fileRef = DD284677291A280D0009A61D /* JSCBytecodeCacheVersion.cpp.in */; };
DD28467B291A35120009A61D /* JSCBytecodeCacheVersion.h in Headers */ = {isa = PBXBuildFile; fileRef = DD28467A291A35120009A61D /* JSCBytecodeCacheVersion.h */; };
DD28467C291AF1B20009A61D /* JSCBuiltins.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D801A61880D6A80026C39B /* JSCBuiltins.cpp */; };
DD41FA8627CDAD3200394D95 /* LowLevelInterpreter.asm in Sources */ = {isa = PBXBuildFile; fileRef = 86A054461556451B00445157 /* LowLevelInterpreter.asm */; };
DD41FA8727CDAD4300394D95 /* LowLevelInterpreter.asm in Sources */ = {isa = PBXBuildFile; fileRef = 86A054461556451B00445157 /* LowLevelInterpreter.asm */; };
Expand Down Expand Up @@ -2187,6 +2184,7 @@
FEF934472B4DC61500DFA7F5 /* ExpressionInfoInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = FEF934462B4DC61500DFA7F5 /* ExpressionInfoInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
FEFD6FC61D5E7992008F2F0B /* JSStringInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = FEFD6FC51D5E7970008F2F0B /* JSStringInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
FF41590C28FF3C6B00F80B96 /* WaiterListManager.h in Headers */ = {isa = PBXBuildFile; fileRef = FF41590B28FF3C6B00F80B96 /* WaiterListManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
FFF3373F2BCDF1240070D04B /* JSCBytecodeCacheVersion.h in Headers */ = {isa = PBXBuildFile; fileRef = FFF3373E2BCDF1240070D04B /* JSCBytecodeCacheVersion.h */; settings = {ATTRIBUTES = (Private, ); }; };
/* End PBXBuildFile section */

/* Begin PBXBuildRule section */
Expand All @@ -2203,21 +2201,6 @@
);
script = "exec \"${SRCROOT}/Scripts/postprocess-header-rule\"\n";
};
DD284676291A27C90009A61D /* PBXBuildRule */ = {
isa = PBXBuildRule;
compilerSpec = com.apple.compilers.proxy.script;
filePatterns = "*/JSCBytecodeCacheVersion.cpp.in";
fileType = pattern.proxy;
inputFiles = (
"$(OBJECT_FILE_DIR_normal)/$(arch)/JSCBuiltins.o",
"$(OBJECT_FILE_DIR_normal)/$(arch)/CachedTypes.o",
);
isEditable = 1;
outputFiles = (
"$(DERIVED_FILE_DIR)/$(arch)/JSCBytecodeCacheVersion.cpp",
);
script = "set -eo pipefail\nCKSUM=(`( cat \"${SCRIPT_INPUT_FILE_0}\" \"${SCRIPT_INPUT_FILE_1}\"; echo ${RC_ProjectSourceVersion} ) | shasum`)\nsed -e s/CACHED_TYPES_CKSUM/\\\"${CKSUM[0]}\\\"/ \"${INPUT_FILE_PATH}\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
};
DD41FA7D27CDA6FE00394D95 /* PBXBuildRule */ = {
isa = PBXBuildRule;
compilerSpec = com.apple.compilers.proxy.script;
Expand Down Expand Up @@ -5442,8 +5425,6 @@
DCF3D5681CD29468003D5C65 /* LazyPropertyInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LazyPropertyInlines.h; sourceTree = "<group>"; };
DCFDFBD71D1F5D9800FE3D72 /* B3BottomProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3BottomProvider.h; path = b3/B3BottomProvider.h; sourceTree = "<group>"; };
DCFDFBD81D1F5D9800FE3D72 /* B3TypeMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3TypeMap.h; path = b3/B3TypeMap.h; sourceTree = "<group>"; };
DD284677291A280D0009A61D /* JSCBytecodeCacheVersion.cpp.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; path = JSCBytecodeCacheVersion.cpp.in; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
DD28467A291A35120009A61D /* JSCBytecodeCacheVersion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSCBytecodeCacheVersion.h; sourceTree = "<group>"; };
DD4BEC0E29CB85AF00398E35 /* B3CanonicalizePrePostIncrements.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3CanonicalizePrePostIncrements.cpp; path = b3/B3CanonicalizePrePostIncrements.cpp; sourceTree = "<group>"; };
DD4BEC0F29CB85AF00398E35 /* B3CanonicalizePrePostIncrements.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3CanonicalizePrePostIncrements.h; path = b3/B3CanonicalizePrePostIncrements.h; sourceTree = "<group>"; };
DD5F74F8283EF4380027A8C6 /* copy-profiling-data.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "copy-profiling-data.sh"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6058,6 +6039,8 @@
FEFD6FC51D5E7970008F2F0B /* JSStringInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSStringInlines.h; sourceTree = "<group>"; };
FF41590B28FF3C6B00F80B96 /* WaiterListManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WaiterListManager.h; sourceTree = "<group>"; };
FFB77C2828FF561B00F3C55B /* WaiterListManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WaiterListManager.cpp; sourceTree = "<group>"; };
FFF3373D2BCDF1240070D04B /* JSCBytecodeCacheVersion.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSCBytecodeCacheVersion.cpp; sourceTree = "<group>"; };
FFF3373E2BCDF1240070D04B /* JSCBytecodeCacheVersion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSCBytecodeCacheVersion.h; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -8291,8 +8274,8 @@
657CF45719BF6662004ACBF2 /* JSCallee.h */,
276B38B52A71D25A00252F4E /* JSCalleeInlines.h */,
53B601EB2034B8C5006BE667 /* JSCast.h */,
DD284677291A280D0009A61D /* JSCBytecodeCacheVersion.cpp.in */,
DD28467A291A35120009A61D /* JSCBytecodeCacheVersion.h */,
FFF3373D2BCDF1240070D04B /* JSCBytecodeCacheVersion.cpp */,
FFF3373E2BCDF1240070D04B /* JSCBytecodeCacheVersion.h */,
FE48BD4323245E8700F136D0 /* JSCConfig.cpp */,
FE48BD4223245E8700F136D0 /* JSCConfig.h */,
BC7F8FBA0E19D1EF008632C0 /* JSCell.cpp */,
Expand Down Expand Up @@ -11170,7 +11153,7 @@
276B38DA2A71D26400252F4E /* JSCalleeInlines.h in Headers */,
53B601EC2034B8C5006BE667 /* JSCast.h in Headers */,
A7D801A91880D6A80026C39B /* JSCBuiltins.h in Headers */,
DD28467B291A35120009A61D /* JSCBytecodeCacheVersion.h in Headers */,
FFF3373F2BCDF1240070D04B /* JSCBytecodeCacheVersion.h in Headers */,
FE48BD4423245E9300F136D0 /* JSCConfig.h in Headers */,
BC1167DA0E19BCC9008066DD /* JSCell.h in Headers */,
0F9749711687ADE400A4FF6A /* JSCellInlines.h in Headers */,
Expand Down Expand Up @@ -12123,7 +12106,6 @@
44F93DFF2AE71F5300FFA37C /* Frameworks */,
);
buildRules = (
DD284676291A27C90009A61D /* PBXBuildRule */,
DD41FA7D27CDA6FE00394D95 /* PBXBuildRule */,
535E08C222545AC800DF00CA /* PBXBuildRule */,
);
Expand Down Expand Up @@ -12950,7 +12932,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DD284672291A217E0009A61D /* CachedTypes.cpp in Sources */,
5333BBDC2110F7D9007618EC /* DFGSpeculativeJIT.cpp in Sources */,
5333BBDB2110F7D2007618EC /* DFGSpeculativeJIT32_64.cpp in Sources */,
5333BBDD2110F7E1007618EC /* DFGSpeculativeJIT64.cpp in Sources */,
Expand All @@ -12962,7 +12943,6 @@
E30873E7272559410053B601 /* IntlPluralRules.cpp in Sources */,
A3EE8543262514B000FC9B8D /* IntlWorkaround.cpp in Sources */,
DD28467C291AF1B20009A61D /* JSCBuiltins.cpp in Sources */,
DD284679291A29900009A61D /* JSCBytecodeCacheVersion.cpp.in in Sources */,
E38E8790254B978400F6F9E4 /* JSDateMath.cpp in Sources */,
539900052A218CC4007F4335 /* JSWebAssemblyArray.cpp in Sources */,
4BE92D442898522400FA48E1 /* LowLevelInterpreter.asm in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Source/JavaScriptCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ runtime/CacheUpdate.cpp
runtime/CacheableIdentifier.cpp
runtime/CachedBytecode.cpp
runtime/CachedSpecialPropertyAdaptiveStructureWatchpoint.cpp
runtime/CachedTypes.cpp
runtime/CatchScope.cpp
runtime/ClassInfo.cpp
runtime/ClonedArguments.cpp
Expand Down Expand Up @@ -900,6 +901,7 @@ runtime/JSAsyncGeneratorFunction.cpp
runtime/JSArrayIterator.cpp
runtime/JSBigInt.cpp
runtime/JSBoundFunction.cpp
runtime/JSCBytecodeCacheVersion.cpp
runtime/JSCConfig.cpp
runtime/JSCJSValue.cpp
runtime/JSCPtrTag.cpp
Expand Down
2 changes: 2 additions & 0 deletions Source/JavaScriptCore/bytecode/ExpressionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#pragma once

#include "LineColumn.h"
#include <wtf/HashMap.h>
#include <wtf/HashTable.h>
#include <wtf/IterationStatus.h>
#include <wtf/PrintStream.h>
#include <wtf/StdLibExtras.h>
Expand Down
7 changes: 4 additions & 3 deletions Source/JavaScriptCore/runtime/CachedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,8 @@ class GenericCacheEntry {

protected:
GenericCacheEntry(Encoder& encoder, CachedCodeBlockTag tag)
: m_tag(tag)
: m_cacheVersion(computeJSCBytecodeCacheVersion())
, m_tag(tag)
{
m_bootSessionUUID.encode(encoder, bootSessionUUIDString());
}
Expand All @@ -2423,15 +2424,15 @@ class GenericCacheEntry {

bool isUpToDate(Decoder& decoder) const
{
if (m_cacheVersion != JSCBytecodeCacheVersion)
if (m_cacheVersion != computeJSCBytecodeCacheVersion())
return false;
if (m_bootSessionUUID.decode(decoder) != bootSessionUUIDString())
return false;
return true;
}

private:
uint32_t m_cacheVersion { JSCBytecodeCacheVersion };
uint32_t m_cacheVersion;
CachedString m_bootSessionUUID;
CachedCodeBlockTag m_tag;
};
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/runtime/FileBasedFuzzerAgentBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#pragma once

#include "ExpressionInfo.h"
#include "FuzzerAgent.h"
#include "LineColumn.h"
#include "Opcode.h"
Expand Down
73 changes: 73 additions & 0 deletions Source/JavaScriptCore/runtime/JSCBytecodeCacheVersion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2022-2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "JSCBytecodeCacheVersion.h"

#include <wtf/text/SuperFastHash.h>

#if OS(DARWIN)
#include <dlfcn.h>
#include <mach-o/dyld.h>
#include <uuid/uuid.h>
#include <wtf/DataLog.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/spi/darwin/dyldSPI.h>
#endif

namespace JSC {

namespace JSCBytecodeCacheVersionInternal {
static constexpr bool verbose = false;
}

uint32_t computeJSCBytecodeCacheVersion()
{
#if OS(DARWIN)
static LazyNeverDestroyed<uint32_t> cacheVersion;
static std::once_flag onceFlag;
std::call_once(onceFlag, [] {
void* jsFunctionAddr = bitwise_cast<void*>(&computeJSCBytecodeCacheVersion);

uuid_t uuid;
if (const mach_header* header = dyld_image_header_containing_address(jsFunctionAddr); header && _dyld_get_image_uuid(header, uuid)) {
uuid_string_t uuidString = { };
uuid_unparse(uuid, uuidString);
cacheVersion.construct(SuperFastHash::computeHash(uuidString));
dataLogLnIf(JSCBytecodeCacheVersionInternal::verbose, "UUID of JavaScriptCore.framework:", uuidString);
return;
}

cacheVersion.construct(0);
dataLogLnIf(JSCBytecodeCacheVersionInternal::verbose, "Failed to get UUID for JavaScriptCore framework");
});
return cacheVersion.get();
#else
static constexpr uint32_t precomputedCacheVersion = SuperFastHash::computeHash(__TIMESTAMP__);
return precomputedCacheVersion;
#endif
}

} // namespace JSC
7 changes: 0 additions & 7 deletions Source/JavaScriptCore/runtime/JSCBytecodeCacheVersion.cpp.in

This file was deleted.

10 changes: 6 additions & 4 deletions Source/JavaScriptCore/runtime/JSCBytecodeCacheVersion.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
* Copyright (C) 2022-2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -27,6 +27,8 @@

#include <stdint.h>

// Generated during the build based on a hash of JSCBuiltins.o, CachedTypes.o, and any production
// build source version number.
extern const uint32_t JSCBytecodeCacheVersion;
namespace JSC {

JS_EXPORT_PRIVATE NEVER_INLINE uint32_t computeJSCBytecodeCacheVersion();

}
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "JSSet.h"
#include "Lexer.h"
#include "LiteralParser.h"
#include "ObjectConstructor.h"
#include "ObjectConstructorInlines.h"
#include "ParseInt.h"
#include <stdio.h>
#include <wtf/ASCIICType.h>
Expand Down
1 change: 1 addition & 0 deletions Source/WTF/wtf/spi/darwin/dyldSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ WTF_EXTERN_C_BEGIN
uint32_t dyld_get_program_sdk_version();
bool dyld_program_sdk_at_least(dyld_build_version_t);
extern const char* dyld_shared_cache_file_path(void);
extern const struct mach_header* dyld_image_header_containing_address(const void* addr);
extern const struct mach_header* _dyld_get_dlopen_image_header(void* handle);
extern bool _dyld_get_image_uuid(const struct mach_header* mh, uuid_t);
extern bool _dyld_get_shared_cache_uuid(uuid_t);
Expand Down

0 comments on commit 92b8d40

Please sign in to comment.