Skip to content

Commit 639e817

Browse files
authored
Default-enable -sGL_ENABLE_GET_PROC_ADDRESS (#20948)
Add paranoia check: if developer is using GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS, then force an allow-list upon them so they don't get new GL extensions until they update their Emscripten compiler.
1 parent 3777e12 commit 639e817

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

embuilder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@
9191
'libc++-mt-noexcept',
9292
'libdlmalloc-mt',
9393
'libGL-emu',
94-
'libGL-emu-webgl2',
95-
'libGL-mt',
94+
'libGL-emu-webgl2-getprocaddr',
95+
'libGL-mt-getprocaddr',
9696
'libGL-mt-emu',
97-
'libGL-mt-emu-webgl2',
98-
'libGL-mt-emu-webgl2-ofb',
97+
'libGL-mt-emu-webgl2-getprocaddr',
98+
'libGL-mt-emu-webgl2-ofb-getprocaddr',
9999
'libsockets_proxy',
100100
'libsockets-mt',
101101
'crtbegin',

src/library_sigs.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ sigs = {
7676
SDL_GL_DeleteContext__sig: 'vp',
7777
SDL_GL_ExtensionSupported__sig: 'ip',
7878
SDL_GL_GetAttribute__sig: 'iip',
79-
SDL_GL_GetProcAddress__sig: 'pp',
8079
SDL_GL_GetSwapInterval__sig: 'i',
8180
SDL_GL_MakeCurrent__sig: 'ipp',
8281
SDL_GL_SetAttribute__sig: 'iii',
@@ -548,7 +547,6 @@ sigs = {
548547
eglGetCurrentSurface__sig: 'pi',
549548
eglGetDisplay__sig: 'pp',
550549
eglGetError__sig: 'i',
551-
eglGetProcAddress__sig: 'pp',
552550
eglInitialize__sig: 'ippp',
553551
eglMakeCurrent__sig: 'ipppp',
554552
eglQueryAPI__sig: 'i',
@@ -851,8 +849,6 @@ sigs = {
851849
emscripten_wasm_worker_post_function_vii__sig: 'vipii',
852850
emscripten_wasm_worker_post_function_viii__sig: 'vipiii',
853851
emscripten_wasm_worker_self_id__sig: 'i',
854-
emscripten_webgl1_get_proc_address__sig: 'pp',
855-
emscripten_webgl2_get_proc_address__sig: 'pp',
856852
emscripten_webgl_commit_frame__sig: 'i',
857853
emscripten_webgl_create_context__sig: 'ppp',
858854
emscripten_webgl_destroy_context__sig: 'ip',
@@ -874,7 +870,6 @@ sigs = {
874870
emscripten_webgl_get_parameter_o__sig: 'ii',
875871
emscripten_webgl_get_parameter_utf8__sig: 'pi',
876872
emscripten_webgl_get_parameter_v__sig: 'iipii',
877-
emscripten_webgl_get_proc_address__sig: 'pp',
878873
emscripten_webgl_get_program_info_log_utf8__sig: 'pi',
879874
emscripten_webgl_get_program_parameter_d__sig: 'dii',
880875
emscripten_webgl_get_shader_info_log_utf8__sig: 'pi',
@@ -1392,7 +1387,6 @@ sigs = {
13921387
glfwGetMouseWheel__sig: 'i',
13931388
glfwGetNumberOfProcessors__sig: 'i',
13941389
glfwGetPrimaryMonitor__sig: 'p',
1395-
glfwGetProcAddress__sig: 'pp',
13961390
glfwGetRequiredInstanceExtensions__sig: 'pp',
13971391
glfwGetThreadID__sig: 'i',
13981392
glfwGetTime__sig: 'd',

src/library_webgl.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,10 +739,11 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
739739
disableHalfFloatExtensionIfBroken(ctx);
740740
#endif
741741

742-
// If end user enables *glGetProcAddress() functionality, then we must filter out
742+
// If end user enables *glGetProcAddress() functionality or
743+
// GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS, then we must filter out
743744
// all future WebGL extensions from being passed to the user, and only restrict to advertising
744745
// extensions that the *glGetProcAddress() function knows to handle.
745-
#if GL_ENABLE_GET_PROC_ADDRESS
746+
#if GL_ENABLE_GET_PROC_ADDRESS || GL_SUPPORT_AUTOMATIC_ENABLE_EXTENSIONS
746747
var _allSupportedExtensions = ctx.getSupportedExtensions;
747748
var supportedExtensionsForGetProcAddress = [
748749
#if MIN_WEBGL_VERSION == 1

src/settings.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,16 @@ var GL_DISABLE_HALF_FLOAT_EXTENSION_IF_BROKEN = false;
587587
// context version was passed. See https://bugs.webkit.org/show_bug.cgi?id=222758 and
588588
// https://github.com/emscripten-core/emscripten/issues/13295.
589589
// Set this to 0 to force-disable the workaround if you know the issue will not affect you.
590+
// [link]
590591
var GL_WORKAROUND_SAFARI_GETCONTEXT_BUG = true;
591592

592593
// If 1, link with support to glGetProcAddress() functionality.
593594
// In WebGL, glGetProcAddress() causes a substantial code size and performance impact, since WebGL
594595
// does not natively provide such functionality, and it must be emulated. Using glGetProcAddress()
595596
// is not recommended. If you still need to use this, e.g. when porting an existing renderer,
596597
// you can link with -sGL_ENABLE_GET_PROC_ADDRESS=1 to get support for this functionality.
597-
var GL_ENABLE_GET_PROC_ADDRESS = false;
598+
// [link]
599+
var GL_ENABLE_GET_PROC_ADDRESS = true;
598600

599601
// Use JavaScript math functions like Math.tan. This saves code size as we can avoid shipping
600602
// compiled musl code. However, it can be significantly slower as it calls out to JS. It

test/test_other.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ def test_GetProcAddress_LEGACY_GL_EMULATION(self):
24642464
# at link time they should get a helpful error message guiding them to enable
24652465
# the option.
24662466
def test_get_proc_address_error_message(self):
2467-
err = self.expect_fail([EMCC, test_file('other/test_GetProcAddress_LEGACY_GL_EMULATION.cpp')])
2467+
err = self.expect_fail([EMCC, '-sGL_ENABLE_GET_PROC_ADDRESS=0', test_file('other/test_GetProcAddress_LEGACY_GL_EMULATION.cpp')])
24682468
self.assertContained('error: linker: Undefined symbol: SDL_GL_GetProcAddress(). Please pass -sGL_ENABLE_GET_PROC_ADDRESS at link time to link in SDL_GL_GetProcAddress().', err)
24692469

24702470
def test_prepost(self):
@@ -10520,6 +10520,7 @@ def test_minimal_runtime_code_size(self, test_name, js, compare_js_output=False)
1052010520
'-sGL_TRACK_ERRORS=0',
1052110521
'-sGL_POOL_TEMP_BUFFERS=0',
1052210522
'-sGL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0',
10523+
'-sGL_ENABLE_GET_PROC_ADDRESS=0',
1052310524
'-sNO_FILESYSTEM',
1052410525
'-sSTRICT',
1052510526
'--output_eol', 'linux',

0 commit comments

Comments
 (0)